2006-12-16 00:11:55 +00:00
|
|
|
/* ui-commit.c: generate commit view
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Lars Hjemli
|
|
|
|
*
|
|
|
|
* Licensed under GNU General Public License v2
|
|
|
|
* (see COPYING for full license text)
|
|
|
|
*/
|
|
|
|
|
2006-12-15 23:19:56 +00:00
|
|
|
#include "cgit.h"
|
2008-02-23 21:45:33 +00:00
|
|
|
#include "html.h"
|
2008-03-24 15:50:57 +00:00
|
|
|
#include "ui-shared.h"
|
2008-04-12 13:53:53 +00:00
|
|
|
#include "ui-diff.h"
|
2009-01-12 15:23:28 +00:00
|
|
|
#include "ui-log.h"
|
2006-12-15 23:19:56 +00:00
|
|
|
|
2007-06-17 16:12:03 +00:00
|
|
|
void cgit_print_commit(char *hex)
|
2006-12-15 23:19:56 +00:00
|
|
|
{
|
2007-05-13 21:13:12 +00:00
|
|
|
struct commit *commit, *parent;
|
2010-02-15 08:57:50 +00:00
|
|
|
struct commitinfo *info, *parent_info;
|
2006-12-15 23:19:56 +00:00
|
|
|
struct commit_list *p;
|
|
|
|
unsigned char sha1[20];
|
2007-06-16 23:23:08 +00:00
|
|
|
char *tmp;
|
2008-05-18 19:09:26 +00:00
|
|
|
int parents = 0;
|
2006-12-15 23:19:56 +00:00
|
|
|
|
2007-06-17 12:53:02 +00:00
|
|
|
if (!hex)
|
2008-02-16 10:53:40 +00:00
|
|
|
hex = ctx.qry.head;
|
2007-06-17 12:53:02 +00:00
|
|
|
|
2006-12-15 23:19:56 +00:00
|
|
|
if (get_sha1(hex, sha1)) {
|
|
|
|
cgit_print_error(fmt("Bad object id: %s", hex));
|
|
|
|
return;
|
|
|
|
}
|
2006-12-16 13:46:05 +00:00
|
|
|
commit = lookup_commit_reference(sha1);
|
2006-12-15 23:19:56 +00:00
|
|
|
if (!commit) {
|
|
|
|
cgit_print_error(fmt("Bad commit reference: %s", hex));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
info = cgit_parse_commit(commit);
|
|
|
|
|
2009-09-13 19:56:45 +00:00
|
|
|
load_ref_decorations(DECORATE_FULL_REFS);
|
2009-01-12 15:23:28 +00:00
|
|
|
|
2007-11-11 12:04:28 +00:00
|
|
|
html("<table summary='commit info' class='commit-info'>\n");
|
2006-12-16 13:28:26 +00:00
|
|
|
html("<tr><th>author</th><td>");
|
2006-12-15 23:19:56 +00:00
|
|
|
html_txt(info->author);
|
2009-08-07 12:05:17 +00:00
|
|
|
if (!ctx.cfg.noplainemail) {
|
|
|
|
html(" ");
|
|
|
|
html_txt(info->author_email);
|
|
|
|
}
|
2006-12-16 13:28:26 +00:00
|
|
|
html("</td><td class='right'>");
|
2008-08-01 12:54:38 +00:00
|
|
|
cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</td></tr>\n");
|
|
|
|
html("<tr><th>committer</th><td>");
|
|
|
|
html_txt(info->committer);
|
2009-08-07 12:05:17 +00:00
|
|
|
if (!ctx.cfg.noplainemail) {
|
|
|
|
html(" ");
|
|
|
|
html_txt(info->committer_email);
|
|
|
|
}
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</td><td class='right'>");
|
2008-08-01 12:54:38 +00:00
|
|
|
cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</td></tr>\n");
|
2008-04-13 10:20:00 +00:00
|
|
|
html("<tr><th>commit</th><td colspan='2' class='sha1'>");
|
|
|
|
tmp = sha1_to_hex(commit->object.sha1);
|
2009-09-14 18:19:02 +00:00
|
|
|
cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, 0);
|
2008-04-13 10:20:00 +00:00
|
|
|
html(" (");
|
|
|
|
cgit_patch_link("patch", NULL, NULL, NULL, tmp);
|
2009-09-14 18:19:02 +00:00
|
|
|
html(") (");
|
|
|
|
if ((ctx.qry.ssdiff && !ctx.cfg.ssdiff) || (!ctx.qry.ssdiff && ctx.cfg.ssdiff))
|
|
|
|
cgit_commit_link("unidiff", NULL, NULL, ctx.qry.head, tmp, 1);
|
|
|
|
else
|
|
|
|
cgit_commit_link("side-by-side diff", NULL, NULL, ctx.qry.head, tmp, 1);
|
2008-04-13 10:20:00 +00:00
|
|
|
html(")</td></tr>\n");
|
2007-06-16 23:23:08 +00:00
|
|
|
html("<tr><th>tree</th><td colspan='2' class='sha1'>");
|
|
|
|
tmp = xstrdup(hex);
|
|
|
|
cgit_tree_link(sha1_to_hex(commit->tree->object.sha1), NULL, NULL,
|
2008-02-16 10:53:40 +00:00
|
|
|
ctx.qry.head, tmp, NULL);
|
2007-06-16 23:23:08 +00:00
|
|
|
html("</td></tr>\n");
|
2006-12-16 18:35:31 +00:00
|
|
|
for (p = commit->parents; p ; p = p->next) {
|
2007-05-13 21:13:12 +00:00
|
|
|
parent = lookup_commit_reference(p->item->object.sha1);
|
|
|
|
if (!parent) {
|
|
|
|
html("<tr><td colspan='3'>");
|
|
|
|
cgit_print_error("Error reading parent commit");
|
|
|
|
html("</td></tr>");
|
|
|
|
continue;
|
|
|
|
}
|
2006-12-16 18:35:31 +00:00
|
|
|
html("<tr><th>parent</th>"
|
2007-06-17 13:44:22 +00:00
|
|
|
"<td colspan='2' class='sha1'>");
|
2010-02-15 08:57:50 +00:00
|
|
|
parent_info = cgit_parse_commit(parent);
|
|
|
|
tmp = sha1_to_hex(p->item->object.sha1);
|
|
|
|
cgit_commit_link(parent_info->subject, NULL, NULL,
|
|
|
|
ctx.qry.head, tmp, 0);
|
2007-06-17 16:12:03 +00:00
|
|
|
html(" (");
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex,
|
2009-09-14 18:19:02 +00:00
|
|
|
sha1_to_hex(p->item->object.sha1), NULL, 0);
|
2007-06-17 16:12:03 +00:00
|
|
|
html(")</td></tr>");
|
2008-05-18 19:09:26 +00:00
|
|
|
parents++;
|
2006-12-15 23:19:56 +00:00
|
|
|
}
|
2008-02-16 12:56:09 +00:00
|
|
|
if (ctx.repo->snapshots) {
|
2007-07-18 12:40:03 +00:00
|
|
|
html("<tr><th>download</th><td colspan='2' class='sha1'>");
|
2008-02-16 10:53:40 +00:00
|
|
|
cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head,
|
2008-02-16 12:56:09 +00:00
|
|
|
hex, ctx.repo->snapshots);
|
2007-07-18 12:40:03 +00:00
|
|
|
html("</td></tr>");
|
2007-02-08 13:47:56 +00:00
|
|
|
}
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</table>\n");
|
|
|
|
html("<div class='commit-subject'>");
|
2009-08-09 11:22:00 +00:00
|
|
|
if (ctx.repo->commit_filter)
|
|
|
|
cgit_open_filter(ctx.repo->commit_filter);
|
2006-12-15 23:19:56 +00:00
|
|
|
html_txt(info->subject);
|
2009-08-09 11:22:00 +00:00
|
|
|
if (ctx.repo->commit_filter)
|
|
|
|
cgit_close_filter(ctx.repo->commit_filter);
|
2009-01-12 15:23:28 +00:00
|
|
|
show_commit_decorations(commit);
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</div>");
|
|
|
|
html("<div class='commit-msg'>");
|
2009-08-09 11:22:00 +00:00
|
|
|
if (ctx.repo->commit_filter)
|
|
|
|
cgit_open_filter(ctx.repo->commit_filter);
|
2006-12-15 23:19:56 +00:00
|
|
|
html_txt(info->msg);
|
2009-08-09 11:22:00 +00:00
|
|
|
if (ctx.repo->commit_filter)
|
|
|
|
cgit_close_filter(ctx.repo->commit_filter);
|
2006-12-15 23:19:56 +00:00
|
|
|
html("</div>");
|
2008-05-18 19:09:26 +00:00
|
|
|
if (parents < 3) {
|
|
|
|
if (parents)
|
|
|
|
tmp = sha1_to_hex(commit->parents->item->object.sha1);
|
|
|
|
else
|
|
|
|
tmp = NULL;
|
2008-04-24 21:32:02 +00:00
|
|
|
cgit_print_diff(ctx.qry.sha1, tmp, NULL);
|
2007-05-13 20:25:14 +00:00
|
|
|
}
|
2006-12-16 13:58:20 +00:00
|
|
|
cgit_free_commitinfo(info);
|
2006-12-15 23:19:56 +00:00
|
|
|
}
|