diff mbox series

[v3,3/9] cache-tree: extract subtree_pos()

Message ID 314b6b34f759c3a0e0d361bc08b254960a4d28e4.1611431900.git.gitgitgadget@gmail.com (mailing list archive)
State New
Headers show
Series More index cleanups | expand

Commit Message

Derrick Stolee Jan. 23, 2021, 7:58 p.m. UTC
From: Derrick Stolee <dstolee@microsoft.com>

This method will be helpful to use outside of cache-tree.c in a later
feature. The implementation is subtle due to subtree_name_cmp() sorting
by length and then lexicographically.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 cache-tree.c | 6 +++---
 cache-tree.h | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/cache-tree.c b/cache-tree.c
index acac6d58c37..2fb483d3c08 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -45,7 +45,7 @@  static int subtree_name_cmp(const char *one, int onelen,
 	return memcmp(one, two, onelen);
 }
 
-static int subtree_pos(struct cache_tree *it, const char *path, int pathlen)
+int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen)
 {
 	struct cache_tree_sub **down = it->down;
 	int lo, hi;
@@ -72,7 +72,7 @@  static struct cache_tree_sub *find_subtree(struct cache_tree *it,
 					   int create)
 {
 	struct cache_tree_sub *down;
-	int pos = subtree_pos(it, path, pathlen);
+	int pos = cache_tree_subtree_pos(it, path, pathlen);
 	if (0 <= pos)
 		return it->down[pos];
 	if (!create)
@@ -123,7 +123,7 @@  static int do_invalidate_path(struct cache_tree *it, const char *path)
 	it->entry_count = -1;
 	if (!*slash) {
 		int pos;
-		pos = subtree_pos(it, path, namelen);
+		pos = cache_tree_subtree_pos(it, path, namelen);
 		if (0 <= pos) {
 			cache_tree_free(&it->down[pos]->cache_tree);
 			free(it->down[pos]);
diff --git a/cache-tree.h b/cache-tree.h
index 639bfa5340e..8efeccebfc9 100644
--- a/cache-tree.h
+++ b/cache-tree.h
@@ -27,6 +27,8 @@  void cache_tree_free(struct cache_tree **);
 void cache_tree_invalidate_path(struct index_state *, const char *);
 struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
 
+int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen);
+
 void cache_tree_write(struct strbuf *, struct cache_tree *root);
 struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);