5 #include "cache-tree.h"
6 #include "read-cache-ll.h"
7 #include "repository.h"
10 static void dump_one(struct cache_tree
*it
, const char *pfx
, const char *x
)
12 if (it
->entry_count
< 0)
13 printf("%-40s %s%s (%d subtrees)\n",
14 "invalid", x
, pfx
, it
->subtree_nr
);
16 printf("%s %s%s (%d entries, %d subtrees)\n",
17 oid_to_hex(&it
->oid
), x
, pfx
,
18 it
->entry_count
, it
->subtree_nr
);
21 static int dump_cache_tree(struct cache_tree
*it
,
22 struct cache_tree
*ref
,
29 /* missing in either */
32 if (it
->entry_count
< 0) {
34 dump_one(it
, pfx
, "");
35 dump_one(ref
, pfx
, "#(ref) ");
38 dump_one(it
, pfx
, "");
39 if (!oideq(&it
->oid
, &ref
->oid
) ||
40 ref
->entry_count
!= it
->entry_count
||
41 ref
->subtree_nr
!= it
->subtree_nr
) {
42 /* claims to be valid but is lying */
43 dump_one(ref
, pfx
, "#(ref) ");
48 for (i
= 0; i
< it
->subtree_nr
; i
++) {
50 struct cache_tree_sub
*down
= it
->down
[i
];
51 struct cache_tree_sub
*rdwn
;
53 rdwn
= cache_tree_sub(ref
, down
->name
);
54 xsnprintf(path
, sizeof(path
), "%s%.*s/", pfx
, down
->namelen
, down
->name
);
55 if (dump_cache_tree(down
->cache_tree
, rdwn
->cache_tree
, path
))
61 int cmd__dump_cache_tree(int ac UNUSED
, const char **av UNUSED
)
63 struct index_state istate
;
64 struct cache_tree
*another
= cache_tree();
67 setup_git_directory();
68 if (repo_read_index(the_repository
) < 0)
69 die("unable to read index file");
70 istate
= *the_repository
->index
;
71 istate
.cache_tree
= another
;
72 cache_tree_update(&istate
, WRITE_TREE_DRY_RUN
);
73 ret
= dump_cache_tree(the_repository
->index
->cache_tree
, another
, "");
74 cache_tree_free(&another
);