From 86a999458adbe1b75ad365e7df9e48aa84e4043d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 14:49:09 -0700 Subject: Check a ref path without copying it --- source/ui-blob.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/ui-blob.c b/source/ui-blob.c index 5118ac2..4ed9b3b 100644 --- a/source/ui-blob.c +++ b/source/ui-blob.c @@ -57,7 +57,7 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base, * oid comes in naming a commit and goes out naming the blob found at path, * which every caller relies on. */ -static int find_path_oid(struct object_id *oid, char *path, int file_only) +static int find_path_oid(struct object_id *oid, const char *path, int file_only) { struct commit *commit = lookup_commit_reference(the_repository, oid); struct tree *tree; @@ -86,19 +86,13 @@ int cgit_ref_path_exists(const char *path, const char *ref) { struct object_id oid; size_t size; - char *path_copy = xstrdup(path); - int found = 0; if (repo_get_oid(the_repository, ref, &oid)) - goto done; + return 0; peel_to_commit(&oid); if (odb_read_object_info(the_repository->objects, &oid, &size) != OBJ_COMMIT) - goto done; - found = find_path_oid(&oid, path_copy, 1); - -done: - free(path_copy); - return found; + return 0; + return find_path_oid(&oid, path, 1); } int cgit_print_file(char *path, const char *head, int html_escape) -- cgit