Commit 46bb00673013a7dae1ee81c484ac05c533ed1c4d

Carlos Martín Nieto 2014-07-11T11:52:38

tree-cache: remove the parent pointer This wasn't used. We invalidate based on the full path, so we always go down the tree, never up.

diff --git a/src/tree-cache.c b/src/tree-cache.c
index 86521ce..1eb046d 100644
--- a/src/tree-cache.c
+++ b/src/tree-cache.c
@@ -72,7 +72,7 @@ const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char 
 
 static int read_tree_internal(git_tree_cache **out,
 			      const char **buffer_in, const char *buffer_end,
-			      git_tree_cache *parent, git_pool *pool)
+			      git_pool *pool)
 {
 	git_tree_cache *tree = NULL;
 	const char *name_start, *buffer;
@@ -86,7 +86,7 @@ static int read_tree_internal(git_tree_cache **out,
 	if (++buffer >= buffer_end)
 		goto corrupted;
 
-	if (git_tree_cache_new(&tree, name_start, parent, pool) < 0)
+	if (git_tree_cache_new(&tree, name_start, pool) < 0)
 		return -1;
 
 	/* Blank-terminated ASCII decimal number of entries in this tree */
@@ -127,7 +127,7 @@ static int read_tree_internal(git_tree_cache **out,
 		memset(tree->children, 0x0, tree->children_count * sizeof(git_tree_cache *));
 
 		for (i = 0; i < tree->children_count; ++i) {
-			if (read_tree_internal(&tree->children[i], &buffer, buffer_end, tree, pool) < 0)
+			if (read_tree_internal(&tree->children[i], &buffer, buffer_end, pool) < 0)
 				goto corrupted;
 		}
 	}
@@ -145,7 +145,7 @@ int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer
 {
 	const char *buffer_end = buffer + buffer_size;
 
-	if (read_tree_internal(tree, &buffer, buffer_end, NULL, pool) < 0)
+	if (read_tree_internal(tree, &buffer, buffer_end, pool) < 0)
 		return -1;
 
 	if (buffer < buffer_end) {
@@ -194,7 +194,7 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
 		if (git_tree_entry_filemode(entry) != GIT_FILEMODE_TREE)
 			continue;
 
-		if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), cache, pool)) < 0)
+		if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), pool)) < 0)
 			return error;
 
 		if ((error = git_tree_lookup(&subtree, repo, git_tree_entry_id(entry))) < 0)
@@ -216,7 +216,7 @@ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_poo
 	int error;
 	git_tree_cache *cache;
 
-	if ((error = git_tree_cache_new(&cache, "", NULL, pool)) < 0)
+	if ((error = git_tree_cache_new(&cache, "", pool)) < 0)
 		return error;
 
 	if ((error = read_tree_recursive(cache, tree, pool)) < 0)
@@ -226,7 +226,7 @@ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_poo
 	return 0;
 }
 
-int git_tree_cache_new(git_tree_cache **out, const char *name, git_tree_cache *parent, git_pool *pool)
+int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
 {
 	size_t name_len;
 	git_tree_cache *tree;
@@ -236,7 +236,6 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_tree_cache *p
 	GITERR_CHECK_ALLOC(tree);
 
 	memset(tree, 0x0, sizeof(git_tree_cache));
-	tree->parent = parent;
 	/* NUL-terminated tree name */
 	tree->namelen = name_len;
 	memcpy(tree->name, name, name_len);
diff --git a/src/tree-cache.h b/src/tree-cache.h
index d75049d..b92a401 100644
--- a/src/tree-cache.h
+++ b/src/tree-cache.h
@@ -12,8 +12,7 @@
 #include "pool.h"
 #include "git2/oid.h"
 
-typedef struct {
-	struct git_tree_cache *parent;
+typedef struct git_tree_cache {
 	struct git_tree_cache **children;
 	size_t children_count;
 
@@ -26,7 +25,7 @@ typedef struct {
 int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool);
 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);
-int git_tree_cache_new(git_tree_cache **out, const char *name, git_tree_cache *parent, git_pool *pool);
+int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool);
 /**
  * Read a tree as the root of the tree cache (like for `git read-tree`)
  */