summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-06-03 21:30:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-06-03 21:30:35 (GMT)
commitc276c21da6d055060b1c216de1b1c04fb058425f (patch)
tree6db5f39ef5a4b55adbd3401db6fc63fe25b7694e /cache-tree.c
parent091680472db4ab4604e79259233040a8d5762c06 (diff)
parent598b1e7d0982fd71a25d861dccc1d580ef14ac90 (diff)
downloadgit-c276c21da6d055060b1c216de1b1c04fb058425f.zip
git-c276c21da6d055060b1c216de1b1c04fb058425f.tar.gz
git-c276c21da6d055060b1c216de1b1c04fb058425f.tar.bz2
Merge branch 'ds/sparse-sparse-checkout'
"sparse-checkout" learns to work well with the sparse-index feature. * ds/sparse-sparse-checkout: sparse-checkout: integrate with sparse index p2000: add test for 'git sparse-checkout [add|set]' sparse-index: complete partial expansion sparse-index: partially expand directories sparse-checkout: --no-sparse-index needs a full index cache-tree: implement cache_tree_find_path() sparse-index: introduce partially-sparse indexes sparse-index: create expand_index() t1092: stress test 'git sparse-checkout set' t1092: refactor 'sparse-index contents' test
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/cache-tree.c b/cache-tree.c
index 8c5e882..a92c23e 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -101,6 +101,33 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *it, const char *path)
return find_subtree(it, path, pathlen, 1);
}
+struct cache_tree *cache_tree_find_path(struct cache_tree *it, const char *path)
+{
+ const char *slash;
+ int namelen;
+ struct cache_tree_sub it_sub = {
+ .cache_tree = it,
+ };
+ struct cache_tree_sub *down = &it_sub;
+
+ while (down) {
+ slash = strchrnul(path, '/');
+ namelen = slash - path;
+ down->cache_tree->entry_count = -1;
+ if (!*slash) {
+ int pos;
+ pos = cache_tree_subtree_pos(down->cache_tree, path, namelen);
+ if (0 <= pos)
+ return down->cache_tree->down[pos]->cache_tree;
+ return NULL;
+ }
+ down = find_subtree(it, path, namelen, 0);
+ path = slash + 1;
+ }
+
+ return NULL;
+}
+
static int do_invalidate_path(struct cache_tree *it, const char *path)
{
/* a/b/c