Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-08-02 17:27:42 +0400
committerVicent Marti <tanoku@gmail.com>2011-09-27 16:33:18 +0400
commit3ba69ba8a469deee81ab718ecc04551c17b9615d (patch)
tree9c9db0631581160bcb703d0a5643394c3a7b99b4 /src/tree-cache.c
parentb419fe2d8cd536e596a4e0ea2eac221fbc2f59a1 (diff)
Add git_tree_cache_get
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'src/tree-cache.c')
-rw-r--r--src/tree-cache.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/tree-cache.c b/src/tree-cache.c
index 026ede0cc..5a3257520 100644
--- a/src/tree-cache.c
+++ b/src/tree-cache.c
@@ -7,7 +7,7 @@
#include "tree-cache.h"
-static git_tree_cache *find_child(git_tree_cache *tree, const char *path)
+static git_tree_cache *find_child(const git_tree_cache *tree, const char *path)
{
size_t i, dirlen;
const char *end;
@@ -53,6 +53,29 @@ void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path)
}
}
+const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path)
+{
+ const char *ptr = path, *end;
+
+ if (tree == NULL) {
+ return NULL;
+ }
+
+ while (1) {
+ end = strchr(ptr, '/');
+
+ tree = find_child(tree, ptr);
+ if (tree == NULL) { /* Can't find it */
+ return NULL;
+ }
+
+ if (end == NULL || end + 1 == '\0')
+ return tree;
+
+ ptr = end + 1;
+ }
+}
+
static int read_tree_internal(git_tree_cache **out,
const char **buffer_in, const char *buffer_end, git_tree_cache *parent)
{