author | Lars Hjemli <hjemli@gmail.com> | 2008-05-18 19:09:26 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-05-18 19:13:21 (UTC) |
commit | 502d57596e645ec91bb9b8ca62833cdb0de4a3b1 (patch) (side-by-side diff) | |
tree | cf825746aee92fc7b50d5b35173a4c38739ecbbf | |
parent | 17890d0058c1555133c8767ceb123e809e6971ab (diff) | |
download | cgit-502d57596e645ec91bb9b8ca62833cdb0de4a3b1.zip cgit-502d57596e645ec91bb9b8ca62833cdb0de4a3b1.tar.gz cgit-502d57596e645ec91bb9b8ca62833cdb0de4a3b1.tar.bz2 |
ui-commit: handle root commits
Both cgit_print_diff() and cgit_diff_tree() handles root commits nicely,
but cgit_print_commit() forgot to check the case of 0 parents.
This fixes it, and adds tests to avoid future regressions.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rwxr-xr-x | tests/t0105-commit.sh | 15 | ||||
-rw-r--r-- | ui-commit.c | 8 |
2 files changed, 21 insertions, 2 deletions
diff --git a/tests/t0105-commit.sh b/tests/t0105-commit.sh index aa2bf33..4e1236b 100755 --- a/tests/t0105-commit.sh +++ b/tests/t0105-commit.sh @@ -1,22 +1,37 @@ #!/bin/sh . ./setup.sh prepare_tests "Check content on commit page" run_test 'generate foo/commit' 'cgit_url "foo/commit" >trash/tmp' run_test 'find tree link' 'grep -e "<a href=./foo/tree/.>" trash/tmp' run_test 'find parent link' 'grep -E "<a href=./foo/commit/\?id=.+>" trash/tmp' run_test 'find commit subject' ' grep -e "<div class=.commit-subject.>commit 5</div>" trash/tmp ' run_test 'find commit msg' 'grep -e "<div class=.commit-msg.></div>" trash/tmp' run_test 'find diffstat' 'grep -e "<table summary=.diffstat. class=.diffstat.>" trash/tmp' run_test 'find diff summary' ' grep -e "1 files changed, 1 insertions, 0 deletions" trash/tmp ' +run_test 'get root commit' ' + root=$(cd trash/repos/foo && git rev-list --reverse HEAD | head -1) && + cgit_url "foo/commit&id=$root" >trash/tmp && + grep "</html>" trash/tmp +' + +run_test 'root commit contains diffstat' ' + grep "<a href=./foo/diff/file-1.>file-1</a>" trash/tmp +' + +run_test 'root commit contains diff' ' + grep ">diff --git a/file-1 b/file-1<" trash/tmp && + grep -e "<div class=.add.>+1</div>" trash/tmp +' + tests_done diff --git a/ui-commit.c b/ui-commit.c index 1aa5d34..4bbb391 100644 --- a/ui-commit.c +++ b/ui-commit.c @@ -1,44 +1,45 @@ /* ui-commit.c: generate commit view * * Copyright (C) 2006 Lars Hjemli * * Licensed under GNU General Public License v2 * (see COPYING for full license text) */ #include "cgit.h" #include "html.h" #include "ui-shared.h" #include "ui-diff.h" void cgit_print_commit(char *hex) { struct commit *commit, *parent; struct commitinfo *info; struct commit_list *p; unsigned char sha1[20]; char *tmp; + int parents = 0; if (!hex) hex = ctx.qry.head; if (get_sha1(hex, sha1)) { cgit_print_error(fmt("Bad object id: %s", hex)); return; } commit = lookup_commit_reference(sha1); if (!commit) { cgit_print_error(fmt("Bad commit reference: %s", hex)); return; } info = cgit_parse_commit(commit); html("<table summary='commit info' class='commit-info'>\n"); html("<tr><th>author</th><td>"); html_txt(info->author); html(" "); html_txt(info->author_email); html("</td><td class='right'>"); cgit_print_date(info->author_date, FMT_LONGDATE); html("</td></tr>\n"); html("<tr><th>committer</th><td>"); @@ -54,45 +55,48 @@ void cgit_print_commit(char *hex) html(" ("); cgit_patch_link("patch", NULL, NULL, NULL, tmp); html(")</td></tr>\n"); 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, ctx.qry.head, tmp, NULL); html("</td></tr>\n"); for (p = commit->parents; p ; p = p->next) { 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; } html("<tr><th>parent</th>" "<td colspan='2' class='sha1'>"); cgit_commit_link(sha1_to_hex(p->item->object.sha1), NULL, NULL, ctx.qry.head, sha1_to_hex(p->item->object.sha1)); html(" ("); cgit_diff_link("diff", NULL, NULL, ctx.qry.head, hex, sha1_to_hex(p->item->object.sha1), NULL); html(")</td></tr>"); + parents++; } if (ctx.repo->snapshots) { html("<tr><th>download</th><td colspan='2' class='sha1'>"); cgit_print_snapshot_links(ctx.qry.repo, ctx.qry.head, hex, ctx.repo->snapshots); html("</td></tr>"); } html("</table>\n"); html("<div class='commit-subject'>"); html_txt(info->subject); html("</div>"); html("<div class='commit-msg'>"); html_txt(info->msg); html("</div>"); - if (!(commit->parents && commit->parents->next && - commit->parents->next->next)) { + if (parents < 3) { + if (parents) tmp = sha1_to_hex(commit->parents->item->object.sha1); + else + tmp = NULL; cgit_print_diff(ctx.qry.sha1, tmp, NULL); } cgit_free_commitinfo(info); } |