Skip to content

Commit c80dd39

Browse files
derrickstoleegitster
authored andcommitted
cache-tree: extract subtree_pos()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d87e33 commit c80dd39

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

cache-tree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int subtree_name_cmp(const char *one, int onelen,
4545
return memcmp(one, two, onelen);
4646
}
4747

48-
static int subtree_pos(struct cache_tree *it, const char *path, int pathlen)
48+
int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen)
4949
{
5050
struct cache_tree_sub **down = it->down;
5151
int lo, hi;
@@ -72,7 +72,7 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
7272
int create)
7373
{
7474
struct cache_tree_sub *down;
75-
int pos = subtree_pos(it, path, pathlen);
75+
int pos = cache_tree_subtree_pos(it, path, pathlen);
7676
if (0 <= pos)
7777
return it->down[pos];
7878
if (!create)
@@ -123,7 +123,7 @@ static int do_invalidate_path(struct cache_tree *it, const char *path)
123123
it->entry_count = -1;
124124
if (!*slash) {
125125
int pos;
126-
pos = subtree_pos(it, path, namelen);
126+
pos = cache_tree_subtree_pos(it, path, namelen);
127127
if (0 <= pos) {
128128
cache_tree_free(&it->down[pos]->cache_tree);
129129
free(it->down[pos]);

cache-tree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void cache_tree_free(struct cache_tree **);
2727
void cache_tree_invalidate_path(struct index_state *, const char *);
2828
struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *);
2929

30+
int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen);
31+
3032
void cache_tree_write(struct strbuf *, struct cache_tree *root);
3133
struct cache_tree *cache_tree_read(const char *buffer, unsigned long size);
3234

0 commit comments

Comments
 (0)