summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-04-24 03:20:25 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-04-24 07:26:31 (GMT)
commit17448209f5441718c69642871c85a80f00d12b43 (patch)
tree0e9e0d8a1718e3336c9a6d6b977b834b7cff355a
parenta6e5642f39db2113785c4f22add7e16d559b8d55 (diff)
downloadgit-17448209f5441718c69642871c85a80f00d12b43.zip
git-17448209f5441718c69642871c85a80f00d12b43.tar.gz
git-17448209f5441718c69642871c85a80f00d12b43.tar.bz2
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>
-rw-r--r--.gitignore1
-rw-r--r--Makefile3
-rw-r--r--dump-cache-tree.c32
3 files changed, 36 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index b5959d6..7906909 100644
--- a/.gitignore
+++ b/.gitignore
@@ -123,6 +123,7 @@ git-write-tree
git-core-*/?*
test-date
test-delta
+test-dump-cache-tree
common-cmds.h
*.tar.gz
*.dsc
diff --git a/Makefile b/Makefile
index 518c3c1..1aa96f4 100644
--- a/Makefile
+++ b/Makefile
@@ -611,6 +611,9 @@ test-date$X: test-date.c date.o ctype.o
test-delta$X: test-delta.c diff-delta.o patch-delta.o
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^ -lz
+test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
+ $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
+
check:
for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done
diff --git a/dump-cache-tree.c b/dump-cache-tree.c
new file mode 100644
index 0000000..80f8683
--- /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;
+}