@matheusbsbs / matheus-bagliano / commits / 17448209f5
Fork 0

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 <junkio@cox.net>

Junio C Hamano committed Apr 23, 2006 at 20:20 UTC 17448209f5441718c69642871c85a80f00d12b43
3 files changed +36
.gitignore
+1
@@ -123,6 +123,7 @@ git-write-tree
123 git-core-*/?*
124 test-date
125 test-delta
126 +test-dump-cache-tree
127 common-cmds.h
128 *.tar.gz
129 *.dsc
Makefile
+3
@@ -611,6 +611,9 @@ test-date$X: test-date.c date.o ctype.o
611 test-delta$X: test-delta.c diff-delta.o patch-delta.o
612 $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^ -lz
613
614 +test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
615 + $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
616 +
617 check:
618 for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done
619
dump-cache-tree.c new
+32
@@ -0,0 +1,32 @@
1 +#include "cache.h"
2 +#include "tree.h"
3 +#include "cache-tree.h"
4 +
5 +static unsigned char active_cache_sha1[20];
6 +static struct cache_tree *active_cache_tree;
7 +
8 +static void dump_cache_tree(struct cache_tree *it, const char *pfx)
9 +{
10 + int i;
11 + if (it->entry_count < 0)
12 + printf("%-40s %s\n", "invalid", pfx);
13 + else
14 + printf("%s %s (%d entries)\n",
15 + sha1_to_hex(it->sha1),
16 + pfx, it->entry_count);
17 + for (i = 0; i < it->subtree_nr; i++) {
18 + char path[PATH_MAX];
19 + struct cache_tree_sub *down = it->down[i];
20 + sprintf(path, "%s%.*s/", pfx, down->namelen, down->name);
21 + dump_cache_tree(down->cache_tree, path);
22 + }
23 +}
24 +
25 +int main(int ac, char **av)
26 +{
27 + if (read_cache_1(active_cache_sha1) < 0)
28 + die("unable to read index file");
29 + active_cache_tree = read_cache_tree(active_cache_sha1);
30 + dump_cache_tree(active_cache_tree, "");
31 + return 0;
32 +}