@matheusbsbs / matheus-bagliano / commits / b9d37a5420
Fork 0

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>

Junio C Hamano committed Apr 20, 2009 at 03:58 UTC b9d37a5420446d0db2dc0dc5458a5e50656a4852
4 files changed +40 -36
builtin-checkout.c
+1
@@ -5,6 +5,7 @@
5 #include "commit.h"
6 #include "tree.h"
7 #include "tree-walk.h"
8 +#include "cache-tree.h"
9 #include "unpack-trees.h"
10 #include "dir.h"
11 #include "run-command.h"
builtin-read-tree.c
+1 -36
@@ -29,41 +29,6 @@ static int list_tree(unsigned char *sha1)
29 return 0;
30 }
31
32 -static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
33 -{
34 - struct tree_desc desc;
35 - struct name_entry entry;
36 - int cnt;
37 -
38 - hashcpy(it->sha1, tree->object.sha1);
39 - init_tree_desc(&desc, tree->buffer, tree->size);
40 - cnt = 0;
41 - while (tree_entry(&desc, &entry)) {
42 - if (!S_ISDIR(entry.mode))
43 - cnt++;
44 - else {
45 - struct cache_tree_sub *sub;
46 - struct tree *subtree = lookup_tree(entry.sha1);
47 - if (!subtree->object.parsed)
48 - parse_tree(subtree);
49 - sub = cache_tree_sub(it, entry.path);
50 - sub->cache_tree = cache_tree();
51 - prime_cache_tree_rec(sub->cache_tree, subtree);
52 - cnt += sub->cache_tree->entry_count;
53 - }
54 - }
55 - it->entry_count = cnt;
56 -}
57 -
58 -static void prime_cache_tree(void)
59 -{
60 - if (!nr_trees)
61 - return;
62 - active_cache_tree = cache_tree();
63 - prime_cache_tree_rec(active_cache_tree, trees[0]);
64 -
65 -}
66 -
32 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>]])";
33
34 static struct lock_file lock_file;
@@ -236,7 +201,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
201 * what came from the tree.
202 */
203 if (nr_trees == 1 && !opts.prefix)
239 - prime_cache_tree();
204 + prime_cache_tree(&active_cache_tree, trees[0]);
205
206 if (write_cache(newfd, active_cache, active_nr) ||
207 commit_locked_index(&lock_file))
cache-tree.c
+34
@@ -1,5 +1,6 @@
1 #include "cache.h"
2 #include "tree.h"
3 +#include "tree-walk.h"
4 #include "cache-tree.h"
5
6 #ifndef DEBUG
@@ -591,3 +592,36 @@ int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix)
592
593 return 0;
594 }
595 +
596 +static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
597 +{
598 + struct tree_desc desc;
599 + struct name_entry entry;
600 + int cnt;
601 +
602 + hashcpy(it->sha1, tree->object.sha1);
603 + init_tree_desc(&desc, tree->buffer, tree->size);
604 + cnt = 0;
605 + while (tree_entry(&desc, &entry)) {
606 + if (!S_ISDIR(entry.mode))
607 + cnt++;
608 + else {
609 + struct cache_tree_sub *sub;
610 + struct tree *subtree = lookup_tree(entry.sha1);
611 + if (!subtree->object.parsed)
612 + parse_tree(subtree);
613 + sub = cache_tree_sub(it, entry.path);
614 + sub->cache_tree = cache_tree();
615 + prime_cache_tree_rec(sub->cache_tree, subtree);
616 + cnt += sub->cache_tree->entry_count;
617 + }
618 + }
619 + it->entry_count = cnt;
620 +}
621 +
622 +void prime_cache_tree(struct cache_tree **it, struct tree *tree)
623 +{
624 + cache_tree_free(it);
625 + *it = cache_tree();
626 + prime_cache_tree_rec(*it, tree);
627 +}
cache-tree.h
+4
@@ -1,6 +1,8 @@
1 #ifndef CACHE_TREE_H
2 #define CACHE_TREE_H
3
4 +#include "tree.h"
5 +
6 struct cache_tree;
7 struct cache_tree_sub {
8 struct cache_tree *cache_tree;
@@ -33,4 +35,6 @@ int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int)
35 #define WRITE_TREE_PREFIX_ERROR (-3)
36
37 int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix);
38 +void prime_cache_tree(struct cache_tree **, struct tree *);
39 +
40 #endif