From 080ab56a46ad65068201a768a04464341117fe81 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Mon, 23 May 2022 13:48:41 +0000 Subject: cache-tree: implement cache_tree_find_path() Given a 'struct cache_tree', it may be beneficial to navigate directly to a node within that corresponds to a given path name. Create cache_tree_find_path() for this function. It returns NULL when no such path exists. The implementation is adapted from do_invalidate_path() which does a similar search but also modifies the nodes it finds along the way. The method could be implemented simply using tail-recursion, but this while loop does the same thing. This new method is not currently used, but will be in an upcoming change. Helped-by: Junio C Hamano Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- cache-tree.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cache-tree.h') diff --git a/cache-tree.h b/cache-tree.h index 8efeccebfc..f75f8e74dc 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -29,6 +29,8 @@ 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); +struct cache_tree *cache_tree_find_path(struct cache_tree *it, const char *path); + void cache_tree_write(struct strbuf *, struct cache_tree *root); struct cache_tree *cache_tree_read(const char *buffer, unsigned long size); -- cgit v1.2.3