]>
git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-dump-cache-tree.c
1 #define USE_THE_INDEX_VARIABLE
5 #include "cache-tree.h"
8 static void dump_one(struct cache_tree
*it
, const char *pfx
, const char *x
)
10 if (it
->entry_count
< 0)
11 printf("%-40s %s%s (%d subtrees)\n",
12 "invalid", x
, pfx
, it
->subtree_nr
);
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
);
19 static int dump_cache_tree(struct cache_tree
*it
,
20 struct cache_tree
*ref
,
27 /* missing in either */
30 if (it
->entry_count
< 0) {
32 dump_one(it
, pfx
, "");
33 dump_one(ref
, pfx
, "#(ref) ");
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) ");
46 for (i
= 0; i
< it
->subtree_nr
; i
++) {
48 struct cache_tree_sub
*down
= it
->down
[i
];
49 struct cache_tree_sub
*rdwn
;
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
))
59 int cmd__dump_cache_tree(int ac
, const char **av
)
61 struct index_state istate
;
62 struct cache_tree
*another
= cache_tree();
65 setup_git_directory();
66 if (repo_read_index(the_repository
) < 0)
67 die("unable to read index file");
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
);