diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/ui-commit.c49
1 file changed, 32 insertions, 17 deletions
diff --git a/source/ui-commit.c b/source/ui-commit.c
index 80c7faf..1fdc5fa 100644
--- a/source/ui-commit.c
+++ b/source/ui-commit.c
@@ -32,7 +32,7 @@ static void print_ident_row(const char *role, const char *name, const char *emai
timestamp_t date, int tz)
{
htmlf("<tr><th>%s</th><td>", role);
- cgit_open_filter(ctx.repo->email_filter, email, "commit");
+ cgit_open_filter(ctx.repo->email_filter, email ? email : "", "commit");
html_txt(name);
if (ctx.cfg.enable_plain_email) {
html(" ");
@@ -46,10 +46,16 @@ static void print_ident_row(const char *role, const char *name, const char *emai
html("</time></td></tr>\n");
}
-static int print_parent_rows(struct commit *commit, const char *rev, const char *prefix)
+/*
+ * Counts the parents that could be read and leaves the first of them in first,
+ * which the diff below the message is taken against.
+ */
+static int print_parent_rows(struct commit *commit, const char *rev, const char *prefix,
+ struct object_id *first)
{
struct commit_list *p;
struct commit *parent;
+ struct commitinfo *info;
const char *parent_hex, *label;
int parents = 0;
@@ -61,13 +67,19 @@ static int print_parent_rows(struct commit *commit, const char *rev, const char
html("</td></tr>\n");
continue;
}
+ if (!parents)
+ oidcpy(first, &p->item->object.oid);
html("<tr><th>parent</th><td colspan='2' class='oid'><div class='spanning'>");
parent_hex = label = oid_to_hex(&p->item->object.oid);
- if (ctx.repo->enable_subject_links)
- label = cgit_parse_commit(parent)->subject;
+ info = ctx.repo->enable_subject_links ? cgit_parse_commit(parent) : NULL;
+ if (info)
+ label = info->subject;
cgit_commit_link(label, NULL, NULL, ctx.qry.head, parent_hex, prefix);
+ if (info)
+ cgit_free_commitinfo(info);
html(" (");
- cgit_diff_link("diff", NULL, NULL, ctx.qry.head, rev, oid_to_hex(&p->item->object.oid), prefix);
+ cgit_diff_link("diff", NULL, NULL, ctx.qry.head, rev, oid_to_hex(&p->item->object.oid),
+ prefix);
html(")</div></td></tr>\n");
parents++;
}
@@ -127,8 +139,9 @@ static void print_trailer_value(const char *key, const char *value)
cgit_open_filter(ctx.repo->trailer_filter, key, "commit");
html_txt(value);
cgit_close_filter(ctx.repo->trailer_filter);
- } else
+ } else {
print_filtered_text(value);
+ }
}
/*
@@ -204,7 +217,10 @@ static void print_message(struct commitinfo *info)
end = trailer_block_end(block);
free_trailers(&items);
trailer_block_release(block);
- if (start >= prefix && start < end) {
+ // git leaves trailing comment lines and an old style Conflicts
+ // section after the block, which the split would lose, so such
+ // a message is shown whole.
+ if (start >= prefix && start < end && !full.buf[end + strspn(full.buf + end, "\n")]) {
size_t len = start - prefix;
while (len > 0 && info->msg[len - 1] == '\n')
@@ -228,8 +244,9 @@ void cgit_print_commit(char *hex, const char *prefix)
struct commit *commit;
struct commitinfo *info;
struct strbuf notes = STRBUF_INIT;
- struct object_id oid;
- const char *commit_hex, *first_parent;
+ struct object_id oid, first_oid;
+ const char *commit_hex;
+ char *first_parent;
char *tree_rev;
int parents;
@@ -237,17 +254,17 @@ void cgit_print_commit(char *hex, const char *prefix)
hex = ctx.qry.head;
if (repo_get_oid(the_repository, hex, &oid)) {
- cgit_print_error_page(400, "Bad Request", "Bad object id: %s", hex);
+ cgit_print_error_page(404, "Not Found", "Bad object id: %s", hex);
return;
}
commit = lookup_commit_reference(the_repository, &oid);
if (!commit) {
- cgit_print_error_page(404, "Not Found", "Bad commit reference: %s", hex);
+ cgit_print_error_page(404, "Not Found", "Not a commit: %s", hex);
return;
}
info = cgit_parse_commit(commit);
- format_display_notes(&oid, &notes, PAGE_ENCODING, 1);
+ format_display_notes(&commit->object.oid, &notes, PAGE_ENCODING, 1);
load_ref_decorations(NULL, DECORATE_FULL_REFS);
@@ -271,7 +288,7 @@ void cgit_print_commit(char *hex, const char *prefix)
// The parent rows follow the commit row so the commit hashes sit
// together, leaving the tree beside the download links.
- parents = print_parent_rows(commit, hex, prefix);
+ parents = print_parent_rows(commit, hex, prefix, &first_oid);
html("<tr><th>tree</th><td colspan='2' class='oid'><div class='spanning'>");
tree_rev = xstrdup(hex);
@@ -304,11 +321,9 @@ void cgit_print_commit(char *hex, const char *prefix)
}
if (parents < OCTOPUS_PARENTS) {
- if (parents)
- first_parent = oid_to_hex(&commit->parents->item->object.oid);
- else
- first_parent = NULL;
+ first_parent = parents ? xstrdup(oid_to_hex(&first_oid)) : NULL;
cgit_print_diff(ctx.qry.oid, first_parent, prefix, 0, 0);
+ free(first_parent);
}
strbuf_release(&notes);