]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-dump-cache-tree.c
t9001: fix indentation in test_no_confirm()
[thirdparty/git.git] / t / helper / test-dump-cache-tree.c
1 #define USE_THE_INDEX_VARIABLE
2 #include "test-tool.h"
3 #include "cache.h"
4 #include "tree.h"
5 #include "cache-tree.h"
6
7
8 static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
9 {
10 if (it->entry_count < 0)
11 printf("%-40s %s%s (%d subtrees)\n",
12 "invalid", x, pfx, it->subtree_nr);
13 else
14 printf("%s %s%s (%d entries, %d subtrees)\n",
15 oid_to_hex(&it->oid), x, pfx,
16 it->entry_count, it->subtree_nr);
17 }
18
19 static int dump_cache_tree(struct cache_tree *it,
20 struct cache_tree *ref,
21 const char *pfx)
22 {
23 int i;
24 int errs = 0;
25
26 if (!it || !ref)
27 /* missing in either */
28 return 0;
29
30 if (it->entry_count < 0) {
31 /* invalid */
32 dump_one(it, pfx, "");
33 dump_one(ref, pfx, "#(ref) ");
34 }
35 else {
36 dump_one(it, pfx, "");
37 if (!oideq(&it->oid, &ref->oid) ||
38 ref->entry_count != it->entry_count ||
39 ref->subtree_nr != it->subtree_nr) {
40 /* claims to be valid but is lying */
41 dump_one(ref, pfx, "#(ref) ");
42 errs = 1;
43 }
44 }
45
46 for (i = 0; i < it->subtree_nr; i++) {
47 char path[PATH_MAX];
48 struct cache_tree_sub *down = it->down[i];
49 struct cache_tree_sub *rdwn;
50
51 rdwn = cache_tree_sub(ref, down->name);
52 xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
53 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
54 errs = 1;
55 }
56 return errs;
57 }
58
59 int cmd__dump_cache_tree(int ac, const char **av)
60 {
61 struct index_state istate;
62 struct cache_tree *another = cache_tree();
63 int ret;
64
65 setup_git_directory();
66 if (repo_read_index(the_repository) < 0)
67 die("unable to read index file");
68 istate = the_index;
69 istate.cache_tree = another;
70 cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
71 ret = dump_cache_tree(the_index.cache_tree, another, "");
72 cache_tree_free(&another);
73
74 return ret;
75 }