Add test-scrap-cache-tree

A simple utility that invalidates all existing cache-tree data. We need this for tests. (We don't need a tool to rebuild the cache-tree data; git read-tree HEAD works for that.) Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Dec 6, 2011 at 18:43 UTC 1aed2fe394f45fed7b97e268cfa11d25c3d8da27
3 files changed +19
.gitignore
+1
@@ -171,6 +171,7 @@
171 /test-date
172 /test-delta
173 /test-dump-cache-tree
174 +/test-scrap-cache-tree
175 /test-genrandom
176 /test-index-version
177 /test-line-buffer
Makefile
+1
@@ -435,6 +435,7 @@ TEST_PROGRAMS_NEED_X += test-ctype
435 TEST_PROGRAMS_NEED_X += test-date
436 TEST_PROGRAMS_NEED_X += test-delta
437 TEST_PROGRAMS_NEED_X += test-dump-cache-tree
438 +TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
439 TEST_PROGRAMS_NEED_X += test-genrandom
440 TEST_PROGRAMS_NEED_X += test-index-version
441 TEST_PROGRAMS_NEED_X += test-line-buffer
test-scrap-cache-tree.c new
+17
@@ -0,0 +1,17 @@
1 +#include "cache.h"
2 +#include "tree.h"
3 +#include "cache-tree.h"
4 +
5 +static struct lock_file index_lock;
6 +
7 +int main(int ac, char **av)
8 +{
9 + int fd = hold_locked_index(&index_lock, 1);
10 + if (read_cache() < 0)
11 + die("unable to read index file");
12 + active_cache_tree = NULL;
13 + if (write_cache(fd, active_cache, active_nr)
14 + || commit_lock_file(&index_lock))
15 + die("unable to write index file");
16 + return 0;
17 +}