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-patch.c | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) (limited to 'source/ui-patch.c') diff --git a/source/ui-patch.c b/source/ui-patch.c index 9cf61c0..763776a 100644 --- a/source/ui-patch.c +++ b/source/ui-patch.c @@ -16,42 +16,6 @@ // Room for two hex object ids, the two dots between them, and the null byte. #define REV_RANGE_LEN (2 * GIT_MAX_HEXSZ + 3) -/* - * A root commit has no parent, so the old end is left null and the caller asks - * for that one commit instead. - */ -static int resolve_range(const char *new_rev, const char *old_rev, - struct object_id *new_oid, struct object_id *old_oid) -{ - struct commit *commit; - - if (repo_get_oid(the_repository, new_rev, new_oid)) { - cgit_print_error_page(404, "Not Found", "Bad object id: %s", new_rev); - return -1; - } - commit = lookup_commit_reference(the_repository, new_oid); - if (!commit) { - cgit_print_error_page(404, "Not Found", "Not a commit: %s", new_rev); - return -1; - } - - if (old_rev) { - if (repo_get_oid(the_repository, old_rev, old_oid)) { - cgit_print_error_page(404, "Not Found", "Bad object id: %s", old_rev); - return -1; - } - if (!lookup_commit_reference(the_repository, old_oid)) { - cgit_print_error_page(404, "Not Found", "Not a commit: %s", old_rev); - return -1; - } - } else if (commit->parents && commit->parents->item) { - oidcpy(old_oid, &commit->parents->item->object.oid); - } else { - oidclr(old_oid, the_repository->hash_algo); - } - return 0; -} - void cgit_print_patch(const char *new_rev, const char *old_rev, const char *prefix) { struct rev_info rev; @@ -71,7 +35,8 @@ void cgit_print_patch(const char *new_rev, const char *old_rev, const char *pref return; } - if (resolve_range(new_rev, old_rev, &new_oid, &old_oid)) + commit = cgit_get_commit(new_rev, &new_oid); + if (!commit || cgit_get_old_oid(old_rev, commit, &old_oid)) return; if (is_null_oid(&old_oid)) { -- cgit 2.12.1