From 09a5334f28c853530ab6a70e11929e9a0f2aca45 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Thu, 1 Oct 2026 17:27:43 -1000 Subject: Walk a path on the blob page from any commit the id names With both an id and a path the blob page handed back the raw object the id named, so a commit id gave the commit text itself, while the plain page looked the path up in that commit's tree. A tag is peeled to its commit on the way, and the README example of a pinned commit now uses a form the request checks accept. --- source/ui-blob.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/ui-blob.c b/source/ui-blob.c index 8407342..4105e48 100644 --- a/source/ui-blob.c +++ b/source/ui-blob.c @@ -181,17 +181,23 @@ void cgit_print_blob(const char *hex, char *path, const char *head, int file_onl cgit_print_error_page(404, "Not Found", "Bad object id: %s", hex); return; } - } else { - if (repo_get_oid(the_repository, head, &oid)) { - cgit_print_error_page(404, "Not Found", "Bad object id: %s", head); - return; - } - peel_to_commit(&oid); + } else if (repo_get_oid(the_repository, head, &oid)) { + cgit_print_error_page(404, "Not Found", "Bad object id: %s", head); + return; } type = odb_read_object_info(the_repository->objects, &oid, &size); - if (!hex && type == OBJ_COMMIT && path) { + // A tag is peeled to its commit, so a path can be looked up in the + // tree whether the id or the head named the tag. The type is read + // first because peeling a blob would read it whole just to learn that + // it is one. + if (type == OBJ_TAG) { + peel_to_commit(&oid); + type = odb_read_object_info(the_repository->objects, &oid, &size); + } + + if (type == OBJ_COMMIT && path) { if (!find_path_oid(&oid, path, file_only)) { cgit_print_error_page(404, "Not Found", "Path not found: %s", path); return; -- cgit v2.8.0