Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
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.
Diffstat (limited to 'source/ui-plain.c')
-rw-r--r--source/ui-plain.c24
1 file changed, 8 insertions, 16 deletions
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)