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 '')
-rw-r--r--source/ui-blob.c17
1 file changed, 4 insertions, 13 deletions
diff --git a/source/ui-blob.c b/source/ui-blob.c
index bc66509..5118ac2 100644
--- a/source/ui-blob.c
+++ b/source/ui-blob.c
@@ -55,24 +55,14 @@ 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. The path has to be writable because a pathspec
- * item does not hold a const string.
+ * which every caller relies on.
*/
static int find_path_oid(struct object_id *oid, char *path, int file_only)
{
struct commit *commit = lookup_commit_reference(the_repository, oid);
struct tree *tree;
- // nowildcard_len matching len makes git treat the path as literal
- // rather than as a glob.
- struct pathspec_item item = {
- .match = path,
- .len = strlen(path),
- .nowildcard_len = strlen(path)
- };
- struct pathspec paths = {
- .nr = 1,
- .items = &item
- };
+ struct pathspec_item item;
+ struct pathspec paths = { 0 };
struct walk_tree_context walk = {
.match_path = path,
.matched_oid = oid,
@@ -87,6 +77,7 @@ static int find_path_oid(struct object_id *oid, char *path, int file_only)
tree = repo_get_commit_tree(the_repository, commit);
if (!tree)
return 0;
+ cgit_literal_pathspec(&paths, &item, path);
read_tree(the_repository, tree, &paths, walk_tree, &walk);
return walk.found_path;
}