summaryrefslogtreecommitdiff
path: root/cache-tree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-04-20 03:58:18 -0700
committerJunio C Hamano <gitster@pobox.com>2009-04-20 04:16:41 -0700
commitb9d37a5420446d0db2dc0dc5458a5e50656a4852 (patch)
tree1544417a886e6fd46ea5f786c8ac74744719ba56 /cache-tree.c
parent8cc21ce78c2f3781024117047c0650861f890213 (diff)
downloadgit-b9d37a5420446d0db2dc0dc5458a5e50656a4852.tar.gz
Move prime_cache_tree() to cache-tree.c
The interface to build cache-tree belongs there. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache-tree.c')
-rw-r--r--cache-tree.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/cache-tree.c b/cache-tree.c
index 3d8f218a5f..37bf35e636 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -1,5 +1,6 @@
#include "cache.h"
#include "tree.h"
+#include "tree-walk.h"
#include "cache-tree.h"
#ifndef DEBUG
@@ -591,3 +592,36 @@ int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix)
return 0;
}
+
+static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
+{
+ struct tree_desc desc;
+ struct name_entry entry;
+ int cnt;
+
+ hashcpy(it->sha1, tree->object.sha1);
+ init_tree_desc(&desc, tree->buffer, tree->size);
+ cnt = 0;
+ while (tree_entry(&desc, &entry)) {
+ if (!S_ISDIR(entry.mode))
+ cnt++;
+ else {
+ struct cache_tree_sub *sub;
+ struct tree *subtree = lookup_tree(entry.sha1);
+ if (!subtree->object.parsed)
+ parse_tree(subtree);
+ sub = cache_tree_sub(it, entry.path);
+ sub->cache_tree = cache_tree();
+ prime_cache_tree_rec(sub->cache_tree, subtree);
+ cnt += sub->cache_tree->entry_count;
+ }
+ }
+ it->entry_count = cnt;
+}
+
+void prime_cache_tree(struct cache_tree **it, struct tree *tree)
+{
+ cache_tree_free(it);
+ *it = cache_tree();
+ prime_cache_tree_rec(*it, tree);
+}