]> git.ipfire.org Git - thirdparty/git.git/blame - test-dump-cache-tree.c
l10n: zh_CN: Update Git Glossary: pickaxe
[thirdparty/git.git] / test-dump-cache-tree.c
CommitLineData
17448209
JH
1#include "cache.h"
2#include "tree.h"
3#include "cache-tree.h"
4
d2cb7c6e
JH
5
6static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
7{
8 if (it->entry_count < 0)
9 printf("%-40s %s%s (%d subtrees)\n",
10 "invalid", x, pfx, it->subtree_nr);
11 else
12 printf("%s %s%s (%d entries, %d subtrees)\n",
13 sha1_to_hex(it->sha1), x, pfx,
14 it->entry_count, it->subtree_nr);
15}
16
17static int dump_cache_tree(struct cache_tree *it,
18 struct cache_tree *ref,
19 const char *pfx)
17448209
JH
20{
21 int i;
d2cb7c6e
JH
22 int errs = 0;
23
a84faf77
JH
24 if (!it || !ref)
25 /* missing in either */
26 return 0;
d2cb7c6e
JH
27
28 if (it->entry_count < 0) {
969dd8c6 29 /* invalid */
d2cb7c6e
JH
30 dump_one(it, pfx, "");
31 dump_one(ref, pfx, "#(ref) ");
d2cb7c6e
JH
32 }
33 else {
34 dump_one(it, pfx, "");
a89fccd2 35 if (hashcmp(it->sha1, ref->sha1) ||
d2cb7c6e
JH
36 ref->entry_count != it->entry_count ||
37 ref->subtree_nr != it->subtree_nr) {
969dd8c6 38 /* claims to be valid but is lying */
d2cb7c6e
JH
39 dump_one(ref, pfx, "#(ref) ");
40 errs = 1;
41 }
42 }
43
17448209
JH
44 for (i = 0; i < it->subtree_nr; i++) {
45 char path[PATH_MAX];
46 struct cache_tree_sub *down = it->down[i];
d2cb7c6e
JH
47 struct cache_tree_sub *rdwn;
48
49 rdwn = cache_tree_sub(ref, down->name);
17448209 50 sprintf(path, "%s%.*s/", pfx, down->namelen, down->name);
d2cb7c6e
JH
51 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
52 errs = 1;
17448209 53 }
d2cb7c6e 54 return errs;
17448209
JH
55}
56
57int main(int ac, char **av)
58{
d0cfc3e8 59 struct index_state istate;
d2cb7c6e 60 struct cache_tree *another = cache_tree();
bad68ec9 61 if (read_cache() < 0)
17448209 62 die("unable to read index file");
d0cfc3e8
NTND
63 istate = the_index;
64 istate.cache_tree = another;
65 cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
d2cb7c6e 66 return dump_cache_tree(active_cache_tree, another, "");
17448209 67}