revision: add mark_tree_uninteresting_sparse
[git.git] / t / helper / test-dump-cache-tree.c
blob6a3f88f5f5d4a8af09dca7c13da6132d66093ca2
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "tree.h"
4 #include "cache-tree.h"
7 static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
9 if (it->entry_count < 0)
10 printf("%-40s %s%s (%d subtrees)\n",
11 "invalid", x, pfx, it->subtree_nr);
12 else
13 printf("%s %s%s (%d entries, %d subtrees)\n",
14 oid_to_hex(&it->oid), x, pfx,
15 it->entry_count, it->subtree_nr);
18 static int dump_cache_tree(struct cache_tree *it,
19 struct cache_tree *ref,
20 const char *pfx)
22 int i;
23 int errs = 0;
25 if (!it || !ref)
26 /* missing in either */
27 return 0;
29 if (it->entry_count < 0) {
30 /* invalid */
31 dump_one(it, pfx, "");
32 dump_one(ref, pfx, "#(ref) ");
34 else {
35 dump_one(it, pfx, "");
36 if (!oideq(&it->oid, &ref->oid) ||
37 ref->entry_count != it->entry_count ||
38 ref->subtree_nr != it->subtree_nr) {
39 /* claims to be valid but is lying */
40 dump_one(ref, pfx, "#(ref) ");
41 errs = 1;
45 for (i = 0; i < it->subtree_nr; i++) {
46 char path[PATH_MAX];
47 struct cache_tree_sub *down = it->down[i];
48 struct cache_tree_sub *rdwn;
50 rdwn = cache_tree_sub(ref, down->name);
51 xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
52 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
53 errs = 1;
55 return errs;
58 int cmd__dump_cache_tree(int ac, const char **av)
60 struct index_state istate;
61 struct cache_tree *another = cache_tree();
62 setup_git_directory();
63 if (read_cache() < 0)
64 die("unable to read index file");
65 istate = the_index;
66 istate.cache_tree = another;
67 cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
68 return dump_cache_tree(active_cache_tree, another, "");