From 702fd5d5d7a3c981856b711d785c44f65f8b9da6 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 30 Oct 2026 22:51:19 -0700 Subject: Look up a request's commit in one place The diff page now names a revision that is no commit the way the request wrote it, as the other pages already did, rather than as the full id it resolved to. The helpers sit beside the error page in ui-shared.c, since shared.c prints nothing. --- source/ui-diff.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'source/ui-diff.c') diff --git a/source/ui-diff.c b/source/ui-diff.c index 736cdaf..51df73d 100644 --- a/source/ui-diff.c +++ b/source/ui-diff.c @@ -604,31 +604,17 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, const char *prefi if (!new_rev) new_rev = ctx.qry.head; - if (repo_get_oid(the_repository, new_rev, new_rev_oid)) { - cgit_print_error_page(404, "Not Found", "Bad object id: %s", new_rev); + new_commit = cgit_get_commit(new_rev, new_rev_oid); + if (!new_commit || cgit_get_old_oid(old_rev, new_commit, old_rev_oid)) return; - } - new_commit = lookup_commit_reference(the_repository, new_rev_oid); - if (!new_commit || repo_parse_commit(the_repository, new_commit)) { - cgit_print_error_page(404, "Not Found", "Not a commit: %s", oid_to_hex(new_rev_oid)); - return; - } new_tree_oid = get_commit_tree_oid(new_commit); - if (old_rev) { - if (repo_get_oid(the_repository, old_rev, old_rev_oid)) { - cgit_print_error_page(404, "Not Found", "Bad object id: %s", old_rev); - return; - } - } else if (new_commit->parents && new_commit->parents->item) { - oidcpy(old_rev_oid, &new_commit->parents->item->object.oid); - } else { - oidclr(old_rev_oid, the_repository->hash_algo); - } - if (!is_null_oid(old_rev_oid)) { + // A named old side is a commit already, so only a first parent + // missing from the repository fails here, and it has no name + // but its id. old_commit = lookup_commit_reference(the_repository, old_rev_oid); - if (!old_commit || repo_parse_commit(the_repository, old_commit)) { + if (!old_commit) { cgit_print_error_page(404, "Not Found", "Not a commit: %s", oid_to_hex(old_rev_oid)); return; } -- cgit 2.12.1