]>
git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-dump-cache-tree.c
715aabfbae7a74ab56650dc358a2e9e4270d1512
1 #define USE_THE_INDEX_VARIABLE
6 #include "cache-tree.h"
9 static void dump_one(struct cache_tree
*it
, const char *pfx
, const char *x
)
11 if (it
->entry_count
< 0)
12 printf("%-40s %s%s (%d subtrees)\n",
13 "invalid", x
, pfx
, it
->subtree_nr
);
15 printf("%s %s%s (%d entries, %d subtrees)\n",
16 oid_to_hex(&it
->oid
), x
, pfx
,
17 it
->entry_count
, it
->subtree_nr
);
20 static int dump_cache_tree(struct cache_tree
*it
,
21 struct cache_tree
*ref
,
28 /* missing in either */
31 if (it
->entry_count
< 0) {
33 dump_one(it
, pfx
, "");
34 dump_one(ref
, pfx
, "#(ref) ");
37 dump_one(it
, pfx
, "");
38 if (!oideq(&it
->oid
, &ref
->oid
) ||
39 ref
->entry_count
!= it
->entry_count
||
40 ref
->subtree_nr
!= it
->subtree_nr
) {
41 /* claims to be valid but is lying */
42 dump_one(ref
, pfx
, "#(ref) ");
47 for (i
= 0; i
< it
->subtree_nr
; i
++) {
49 struct cache_tree_sub
*down
= it
->down
[i
];
50 struct cache_tree_sub
*rdwn
;
52 rdwn
= cache_tree_sub(ref
, down
->name
);
53 xsnprintf(path
, sizeof(path
), "%s%.*s/", pfx
, down
->namelen
, down
->name
);
54 if (dump_cache_tree(down
->cache_tree
, rdwn
->cache_tree
, path
))
60 int cmd__dump_cache_tree(int ac
, const char **av
)
62 struct index_state istate
;
63 struct cache_tree
*another
= cache_tree();
66 setup_git_directory();
67 if (repo_read_index(the_repository
) < 0)
68 die("unable to read index file");
70 istate
.cache_tree
= another
;
71 cache_tree_update(&istate
, WRITE_TREE_DRY_RUN
);
72 ret
= dump_cache_tree(the_index
.cache_tree
, another
, "");
73 cache_tree_free(&another
);