Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (56 sloc) 1.54 kb
1744820 Add test-dump-cache-tree
Junio C Hamano authored
1 #include "cache.h"
2 #include "tree.h"
3 #include "cache-tree.h"
4
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
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)
1744820 Add test-dump-cache-tree
Junio C Hamano authored
20 {
21 int i;
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
22 int errs = 0;
23
a84faf7 Fix test-dump-cache-tree in one-tree disappeared case.
Junio C Hamano authored
24 if (!it || !ref)
25 /* missing in either */
26 return 0;
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
27
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, "");
a89fccd Do not use memcmp(sha1_1, sha1_2, 20) with hardcoded length.
David Rientjes authored
36 if (hashcmp(it->sha1, ref->sha1) ||
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
37 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
1744820 Add test-dump-cache-tree
Junio C Hamano authored
44 for (i = 0; i < it->subtree_nr; i++) {
45 char path[PATH_MAX];
46 struct cache_tree_sub *down = it->down[i];
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
47 struct cache_tree_sub *rdwn;
48
49 rdwn = cache_tree_sub(ref, down->name);
1744820 Add test-dump-cache-tree
Junio C Hamano authored
50 sprintf(path, "%s%.*s/", pfx, down->namelen, down->name);
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
51 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
52 errs = 1;
1744820 Add test-dump-cache-tree
Junio C Hamano authored
53 }
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
54 return errs;
1744820 Add test-dump-cache-tree
Junio C Hamano authored
55 }
56
57 int main(int ac, char **av)
58 {
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
59 struct cache_tree *another = cache_tree();
bad68ec index: make the index file format extensible.
Junio C Hamano authored
60 if (read_cache() < 0)
1744820 Add test-dump-cache-tree
Junio C Hamano authored
61 die("unable to read index file");
e859c69 @pclouds cache-tree: update API to take abitrary flags
pclouds authored
62 cache_tree_update(another, active_cache, active_nr, WRITE_TREE_DRY_RUN);
d2cb7c6 test-dump-cache-tree: validate the cached data as well.
Junio C Hamano authored
63 return dump_cache_tree(active_cache_tree, another, "");
1744820 Add test-dump-cache-tree
Junio C Hamano authored
64 }
Something went wrong with that request. Please try again.