summaryrefslogtreecommitdiff
path: root/src/tree-cache.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-07-26 14:58:32 +0200
committerVicent Marti <tanoku@gmail.com>2011-09-27 14:33:18 +0200
commit69bffab9693983378409d2bdd3266ba8540b3236 (patch)
tree7f798fa843dfd196399e9b35f3b7d84eb6e69be0 /src/tree-cache.c
parentacd31b4ad6b3bb3e3048fe3b4d7005b9a4a770e5 (diff)
downloadlibgit2-69bffab9693983378409d2bdd3266ba8540b3236.tar.gz
Add git_tree_cache_invalidate_path
Whenever a file is updated in the index, each tree leading towards it needs to be invalidated. Provide the supporting function. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'src/tree-cache.c')
-rw-r--r--src/tree-cache.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/tree-cache.c b/src/tree-cache.c
index 2e6e5f103..026ede0cc 100644
--- a/src/tree-cache.c
+++ b/src/tree-cache.c
@@ -7,10 +7,56 @@
#include "tree-cache.h"
+static git_tree_cache *find_child(git_tree_cache *tree, const char *path)
+{
+ size_t i, dirlen;
+ const char *end;
+
+ end = strchr(path, '/');
+ if (end == NULL) {
+ end = strrchr(path, '\0');
+ }
+
+ dirlen = end - path;
+
+ for (i = 0; i < tree->children_count; ++i) {
+ const char *childname = tree->children[i]->name;
+
+ if (strlen(childname) == dirlen && !memcmp(path, childname, dirlen))
+ return tree->children[i];
+ }
+
+ return NULL;
+}
+
+void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path)
+{
+ const char *ptr = path, *end;
+
+ if (tree == NULL)
+ return;
+
+ tree->entries = -1;
+
+ while (ptr != NULL) {
+ end = strchr(ptr, '/');
+
+ if (end == NULL) /* End of path */
+ break;
+
+ tree = find_child(tree, ptr);
+ if (tree == NULL) /* We don't have that tree */
+ return;
+
+ tree->entries = -1;
+ ptr = end + 1;
+ }
+}
+
static int read_tree_internal(git_tree_cache **out,
const char **buffer_in, const char *buffer_end, git_tree_cache *parent)
{
- git_tree_cache *tree;
+ git_tree_cache *tree = NULL;
const char *name_start, *buffer;
int count;
int error = GIT_SUCCESS;