summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8cc21ce)
raw | patch | inline | side by side (parent: 8cc21ce)
author | Junio C Hamano <gitster@pobox.com> | |
Mon, 20 Apr 2009 10:58:18 +0000 (03:58 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 20 Apr 2009 11:16:41 +0000 (04:16 -0700) |
The interface to build cache-tree belongs there.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-checkout.c | patch | blob | history | |
builtin-read-tree.c | patch | blob | history | |
cache-tree.c | patch | blob | history | |
cache-tree.h | patch | blob | history |
diff --git a/builtin-checkout.c b/builtin-checkout.c
index b121fe56de884867b31aeeb5bd704bdaf0310310..ffdb33aef596740890362a0e237d33131a906f45 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
#include "commit.h"
#include "tree.h"
#include "tree-walk.h"
+#include "cache-tree.h"
#include "unpack-trees.h"
#include "dir.h"
#include "run-command.h"
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index e4e0e710c8e2b889189132a64515d063a8adb8b1..9cd7d0738ed7018737196f03aa01c7bc7f720e26 100644 (file)
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
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;
-}
-
-static void prime_cache_tree(void)
-{
- if (!nr_trees)
- return;
- active_cache_tree = cache_tree();
- prime_cache_tree_rec(active_cache_tree, trees[0]);
-
-}
-
static const char read_tree_usage[] = "git read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
static struct lock_file lock_file;
* what came from the tree.
*/
if (nr_trees == 1 && !opts.prefix)
- prime_cache_tree();
+ prime_cache_tree(&active_cache_tree, trees[0]);
if (write_cache(newfd, active_cache, active_nr) ||
commit_locked_index(&lock_file))
diff --git a/cache-tree.c b/cache-tree.c
index 3d8f218a5f9e838b15e1d56113a4dd56904ee544..37bf35e636f0966662416f0693dbea5c1cc73311 100644 (file)
--- a/cache-tree.c
+++ b/cache-tree.c
#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);
+}
diff --git a/cache-tree.h b/cache-tree.h
index cf8b790874c4a4f5890b360c237ccdd4a5a03de4..e95883523633a51f833683e96af1738da2868238 100644 (file)
--- a/cache-tree.h
+++ b/cache-tree.h
#ifndef CACHE_TREE_H
#define CACHE_TREE_H
+#include "tree.h"
+
struct cache_tree;
struct cache_tree_sub {
struct cache_tree *cache_tree;
#define WRITE_TREE_PREFIX_ERROR (-3)
int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix);
+void prime_cache_tree(struct cache_tree **, struct tree *);
+
#endif