From cbadaccdf6b8a87f962a9230b977cd6b28d7bada Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 14:14:32 -0700 Subject: Build a literal pathspec in one place Git's pathspec item holds a const string now, so a path needs no writable copy to be matched. --- source/ui-plain.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'source/ui-plain.c') diff --git a/source/ui-plain.c b/source/ui-plain.c index f97b80c..0d12896 100644 --- a/source/ui-plain.c +++ b/source/ui-plain.c @@ -202,19 +202,8 @@ void cgit_print_plain(void) const char *rev = ctx.qry.oid; struct object_id oid; struct commit *commit; - int path_len = ctx.qry.path ? strlen(ctx.qry.path) : 0; - // nowildcard_len matches len so git treats the path as literal. As a - // glob, every entry a pattern like * matches would be answered with - // its own HTTP headers inside the body of the first. - struct pathspec_item path_items = { - .match = ctx.qry.path, - .len = path_len, - .nowildcard_len = path_len - }; - struct pathspec paths = { - .nr = 1, - .items = &path_items - }; + struct pathspec_item path_item; + struct pathspec paths = { 0 }; struct walk_tree_context walk = { .response = RESPONSE_NONE }; @@ -231,15 +220,18 @@ void cgit_print_plain(void) cgit_print_error_page(404, "Not Found", "Not found"); return; } - if (!path_items.match) { + // The path is taken literally, since as a glob every entry a pattern + // like * matches would be answered with its own HTTP headers inside + // the body of the first. + cgit_literal_pathspec(&paths, &path_item, ctx.qry.path); + if (!ctx.qry.path) { // The walk is never handed an entry for the top of the tree // itself, so the listing it would have opened is opened here. - paths.nr = 0; walk.dir_len = -1; print_dir("", 0, ""); walk.response = RESPONSE_LISTING; } else { - walk.dir_len = dir_prefix_len(path_items.match); + walk.dir_len = dir_prefix_len(ctx.qry.path); } read_tree(the_repository, repo_get_commit_tree(the_repository, commit), &paths, walk_tree, &walk); if (walk.response == RESPONSE_NONE) -- cgit