test-dump-cache-tree: validate the cached data as well.
While dumping the cached data, try recomputing everything from scratch to make sure things match. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 27, 2006 at 16:22 UTC
d2cb7c6e9303c082b406acc643018f51179e8b35
1 file changed
+45
-11
dump-cache-tree.c
+45
-11
@@ -2,30 +2,64 @@
2
#include "tree.h"
3
#include "cache-tree.h"
4
5
-static void dump_cache_tree(struct cache_tree *it, const char *pfx)
5
+
6
+static 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
+
17
+static int dump_cache_tree(struct cache_tree *it,
18
+ struct cache_tree *ref,
19
+ const char *pfx)
20
{
21
int i;
22
+ int errs = 0;
23
+
24
if (!it)
25
return;
10
- if (it->entry_count < 0)
11
- printf("%-40s %s (%d subtrees)\n", "invalid", pfx,
12
- it->subtree_nr);
13
- else
14
- printf("%s %s (%d entries, %d subtrees)\n",
15
- sha1_to_hex(it->sha1),
16
- pfx, it->entry_count, it->subtree_nr);
26
+ if (!ref)
27
+ die("internal error");
28
+
29
+ if (it->entry_count < 0) {
30
+ dump_one(it, pfx, "");
31
+ dump_one(ref, pfx, "#(ref) ");
32
+ if (it->subtree_nr != ref->subtree_nr)
33
+ errs = 1;
34
+ }
35
+ else {
36
+ dump_one(it, pfx, "");
37
+ if (memcmp(it->sha1, ref->sha1, 20) ||
38
+ ref->entry_count != it->entry_count ||
39
+ ref->subtree_nr != it->subtree_nr) {
40
+ dump_one(ref, pfx, "#(ref) ");
41
+ errs = 1;
42
+ }
43
+ }
44
+
45
for (i = 0; i < it->subtree_nr; i++) {
46
char path[PATH_MAX];
47
struct cache_tree_sub *down = it->down[i];
48
+ struct cache_tree_sub *rdwn;
49
+
50
+ rdwn = cache_tree_sub(ref, down->name);
51
sprintf(path, "%s%.*s/", pfx, down->namelen, down->name);
21
- dump_cache_tree(down->cache_tree, path);
52
+ if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
53
+ errs = 1;
54
}
55
+ return errs;
56
}
57
58
int main(int ac, char **av)
59
{
60
+ struct cache_tree *another = cache_tree();
61
if (read_cache() < 0)
62
die("unable to read index file");
29
- dump_cache_tree(active_cache_tree, "");
30
- return 0;
63
+ cache_tree_update(another, active_cache, active_nr, 0, 1);
64
+ return dump_cache_tree(active_cache_tree, another, "");
65
}