]> git.ipfire.org Git - thirdparty/git.git/blame - dump-cache-tree.c
cache-tree: protect against "git prune".
[thirdparty/git.git] / dump-cache-tree.c
CommitLineData
17448209
JH
1#include "cache.h"
2#include "tree.h"
3#include "cache-tree.h"
4
5static unsigned char active_cache_sha1[20];
6static struct cache_tree *active_cache_tree;
7
8static 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
25int 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}