blob: 1f73f1ea7dfa6a14dedf384c99751e86c8121ff4 [file] [log] [blame]
Junio C Hamano17448202006-04-23 20:20:25 -07001#include "cache.h"
2#include "tree.h"
3#include "cache-tree.h"
4
Junio C Hamanod2cb7c62006-04-27 16:22:45 -07005
6static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
7{
8 if (it->entry_count < 0)
9 printf("%-40s %s%s (%d subtrees)\n",
10 "invalid", x, pfx, it->subtree_nr);
11 else
12 printf("%s %s%s (%d entries, %d subtrees)\n",
13 sha1_to_hex(it->sha1), x, pfx,
14 it->entry_count, it->subtree_nr);
15}
16
17static int dump_cache_tree(struct cache_tree *it,
18 struct cache_tree *ref,
19 const char *pfx)
Junio C Hamano17448202006-04-23 20:20:25 -070020{
21 int i;
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070022 int errs = 0;
23
Junio C Hamanoa84faf72006-05-03 15:32:54 -070024 if (!it || !ref)
25 /* missing in either */
26 return 0;
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070027
28 if (it->entry_count < 0) {
29 dump_one(it, pfx, "");
30 dump_one(ref, pfx, "#(ref) ");
31 if (it->subtree_nr != ref->subtree_nr)
32 errs = 1;
33 }
34 else {
35 dump_one(it, pfx, "");
David Rientjesa89fccd2006-08-17 11:54:57 -070036 if (hashcmp(it->sha1, ref->sha1) ||
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070037 ref->entry_count != it->entry_count ||
38 ref->subtree_nr != it->subtree_nr) {
39 dump_one(ref, pfx, "#(ref) ");
40 errs = 1;
41 }
42 }
43
Junio C Hamano17448202006-04-23 20:20:25 -070044 for (i = 0; i < it->subtree_nr; i++) {
45 char path[PATH_MAX];
46 struct cache_tree_sub *down = it->down[i];
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070047 struct cache_tree_sub *rdwn;
48
49 rdwn = cache_tree_sub(ref, down->name);
Junio C Hamano17448202006-04-23 20:20:25 -070050 sprintf(path, "%s%.*s/", pfx, down->namelen, down->name);
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070051 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
52 errs = 1;
Junio C Hamano17448202006-04-23 20:20:25 -070053 }
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070054 return errs;
Junio C Hamano17448202006-04-23 20:20:25 -070055}
56
57int main(int ac, char **av)
58{
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070059 struct cache_tree *another = cache_tree();
Junio C Hamanobad68ec2006-04-24 21:18:58 -070060 if (read_cache() < 0)
Junio C Hamano17448202006-04-23 20:20:25 -070061 die("unable to read index file");
Junio C Hamanod2cb7c62006-04-27 16:22:45 -070062 cache_tree_update(another, active_cache, active_nr, 0, 1);
63 return dump_cache_tree(active_cache_tree, another, "");
Junio C Hamano17448202006-04-23 20:20:25 -070064}