]>
git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-dump-cache-tree.c
1 #define USE_THE_INDEX_VARIABLE
6 #include "cache-tree.h"
7 #include "read-cache-ll.h"
8 #include "repository.h"
11 static void dump_one(struct cache_tree
*it
, const char *pfx
, const char *x
)
13 if (it
->entry_count
< 0)
14 printf("%-40s %s%s (%d subtrees)\n",
15 "invalid", x
, pfx
, it
->subtree_nr
);
17 printf("%s %s%s (%d entries, %d subtrees)\n",
18 oid_to_hex(&it
->oid
), x
, pfx
,
19 it
->entry_count
, it
->subtree_nr
);
22 static int dump_cache_tree(struct cache_tree
*it
,
23 struct cache_tree
*ref
,
30 /* missing in either */
33 if (it
->entry_count
< 0) {
35 dump_one(it
, pfx
, "");
36 dump_one(ref
, pfx
, "#(ref) ");
39 dump_one(it
, pfx
, "");
40 if (!oideq(&it
->oid
, &ref
->oid
) ||
41 ref
->entry_count
!= it
->entry_count
||
42 ref
->subtree_nr
!= it
->subtree_nr
) {
43 /* claims to be valid but is lying */
44 dump_one(ref
, pfx
, "#(ref) ");
49 for (i
= 0; i
< it
->subtree_nr
; i
++) {
51 struct cache_tree_sub
*down
= it
->down
[i
];
52 struct cache_tree_sub
*rdwn
;
54 rdwn
= cache_tree_sub(ref
, down
->name
);
55 xsnprintf(path
, sizeof(path
), "%s%.*s/", pfx
, down
->namelen
, down
->name
);
56 if (dump_cache_tree(down
->cache_tree
, rdwn
->cache_tree
, path
))
62 int cmd__dump_cache_tree(int ac UNUSED
, const char **av UNUSED
)
64 struct index_state istate
;
65 struct cache_tree
*another
= cache_tree();
68 setup_git_directory();
69 if (repo_read_index(the_repository
) < 0)
70 die("unable to read index file");
72 istate
.cache_tree
= another
;
73 cache_tree_update(&istate
, WRITE_TREE_DRY_RUN
);
74 ret
= dump_cache_tree(the_index
.cache_tree
, another
, "");
75 cache_tree_free(&another
);