]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-dump-cache-tree.c
Merge branch 'sb/blame-color' into jk/banned-function
[thirdparty/git.git] / t / helper / test-dump-cache-tree.c
CommitLineData
06ccb29e 1#include "test-tool.h"
17448209
JH
2#include "cache.h"
3#include "tree.h"
4#include "cache-tree.h"
5
d2cb7c6e
JH
6
7static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
8{
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",
e0a92804 14 oid_to_hex(&it->oid), x, pfx,
d2cb7c6e
JH
15 it->entry_count, it->subtree_nr);
16}
17
18static int dump_cache_tree(struct cache_tree *it,
19 struct cache_tree *ref,
20 const char *pfx)
17448209
JH
21{
22 int i;
d2cb7c6e
JH
23 int errs = 0;
24
a84faf77
JH
25 if (!it || !ref)
26 /* missing in either */
27 return 0;
d2cb7c6e
JH
28
29 if (it->entry_count < 0) {
969dd8c6 30 /* invalid */
d2cb7c6e
JH
31 dump_one(it, pfx, "");
32 dump_one(ref, pfx, "#(ref) ");
d2cb7c6e
JH
33 }
34 else {
35 dump_one(it, pfx, "");
e0a92804 36 if (oidcmp(&it->oid, &ref->oid) ||
d2cb7c6e
JH
37 ref->entry_count != it->entry_count ||
38 ref->subtree_nr != it->subtree_nr) {
969dd8c6 39 /* claims to be valid but is lying */
d2cb7c6e
JH
40 dump_one(ref, pfx, "#(ref) ");
41 errs = 1;
42 }
43 }
44
17448209
JH
45 for (i = 0; i < it->subtree_nr; i++) {
46 char path[PATH_MAX];
47 struct cache_tree_sub *down = it->down[i];
d2cb7c6e
JH
48 struct cache_tree_sub *rdwn;
49
50 rdwn = cache_tree_sub(ref, down->name);
04724222 51 xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
d2cb7c6e
JH
52 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
53 errs = 1;
17448209 54 }
d2cb7c6e 55 return errs;
17448209
JH
56}
57
06ccb29e 58int cmd__dump_cache_tree(int ac, const char **av)
17448209 59{
d0cfc3e8 60 struct index_state istate;
d2cb7c6e 61 struct cache_tree *another = cache_tree();
4ce742fc 62 setup_git_directory();
bad68ec9 63 if (read_cache() < 0)
17448209 64 die("unable to read index file");
d0cfc3e8
NTND
65 istate = the_index;
66 istate.cache_tree = another;
67 cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
d2cb7c6e 68 return dump_cache_tree(active_cache_tree, another, "");
17448209 69}