]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-dump-cache-tree.c
Merge branch 'bb/unicode-width-table-15'
[thirdparty/git.git] / t / helper / test-dump-cache-tree.c
CommitLineData
bdafeae0 1#define USE_THE_INDEX_VARIABLE
06ccb29e 2#include "test-tool.h"
d1cbe1e6 3#include "hash.h"
41771fa4 4#include "hex.h"
17448209
JH
5#include "tree.h"
6#include "cache-tree.h"
08c46a49 7#include "read-cache-ll.h"
d1cbe1e6 8#include "repository.h"
e38da487 9#include "setup.h"
d2cb7c6e
JH
10
11static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
12{
13 if (it->entry_count < 0)
14 printf("%-40s %s%s (%d subtrees)\n",
15 "invalid", x, pfx, it->subtree_nr);
16 else
17 printf("%s %s%s (%d entries, %d subtrees)\n",
e0a92804 18 oid_to_hex(&it->oid), x, pfx,
d2cb7c6e
JH
19 it->entry_count, it->subtree_nr);
20}
21
22static int dump_cache_tree(struct cache_tree *it,
23 struct cache_tree *ref,
24 const char *pfx)
17448209
JH
25{
26 int i;
d2cb7c6e
JH
27 int errs = 0;
28
a84faf77
JH
29 if (!it || !ref)
30 /* missing in either */
31 return 0;
d2cb7c6e
JH
32
33 if (it->entry_count < 0) {
969dd8c6 34 /* invalid */
d2cb7c6e
JH
35 dump_one(it, pfx, "");
36 dump_one(ref, pfx, "#(ref) ");
d2cb7c6e
JH
37 }
38 else {
39 dump_one(it, pfx, "");
9001dc2a 40 if (!oideq(&it->oid, &ref->oid) ||
d2cb7c6e
JH
41 ref->entry_count != it->entry_count ||
42 ref->subtree_nr != it->subtree_nr) {
969dd8c6 43 /* claims to be valid but is lying */
d2cb7c6e
JH
44 dump_one(ref, pfx, "#(ref) ");
45 errs = 1;
46 }
47 }
48
17448209
JH
49 for (i = 0; i < it->subtree_nr; i++) {
50 char path[PATH_MAX];
51 struct cache_tree_sub *down = it->down[i];
d2cb7c6e
JH
52 struct cache_tree_sub *rdwn;
53
54 rdwn = cache_tree_sub(ref, down->name);
04724222 55 xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
d2cb7c6e
JH
56 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
57 errs = 1;
17448209 58 }
d2cb7c6e 59 return errs;
17448209
JH
60}
61
126e3b3d 62int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
17448209 63{
d0cfc3e8 64 struct index_state istate;
d2cb7c6e 65 struct cache_tree *another = cache_tree();
9afa46d4
ÆAB
66 int ret;
67
4ce742fc 68 setup_git_directory();
0ea414a1 69 if (repo_read_index(the_repository) < 0)
17448209 70 die("unable to read index file");
d0cfc3e8
NTND
71 istate = the_index;
72 istate.cache_tree = another;
73 cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
dc594180 74 ret = dump_cache_tree(the_index.cache_tree, another, "");
9afa46d4
ÆAB
75 cache_tree_free(&another);
76
77 return ret;
17448209 78}