From 17448209f5441718c69642871c85a80f00d12b43 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 23 Apr 2006 20:20:25 -0700 Subject: Add test-dump-cache-tree This was useful in diagnosing the corrupt index.aux format problem. But do not bother building or installing it by default. Signed-off-by: Junio C Hamano --- dump-cache-tree.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 dump-cache-tree.c (limited to 'dump-cache-tree.c') diff --git a/dump-cache-tree.c b/dump-cache-tree.c new file mode 100644 index 0000000000..80f8683f39 --- /dev/null +++ b/dump-cache-tree.c @@ -0,0 +1,32 @@ +#include "cache.h" +#include "tree.h" +#include "cache-tree.h" + +static unsigned char active_cache_sha1[20]; +static struct cache_tree *active_cache_tree; + +static void dump_cache_tree(struct cache_tree *it, const char *pfx) +{ + int i; + if (it->entry_count < 0) + printf("%-40s %s\n", "invalid", pfx); + else + printf("%s %s (%d entries)\n", + sha1_to_hex(it->sha1), + pfx, it->entry_count); + for (i = 0; i < it->subtree_nr; i++) { + char path[PATH_MAX]; + struct cache_tree_sub *down = it->down[i]; + sprintf(path, "%s%.*s/", pfx, down->namelen, down->name); + dump_cache_tree(down->cache_tree, path); + } +} + +int main(int ac, char **av) +{ + if (read_cache_1(active_cache_sha1) < 0) + die("unable to read index file"); + active_cache_tree = read_cache_tree(active_cache_sha1); + dump_cache_tree(active_cache_tree, ""); + return 0; +} -- cgit v1.2.3