1 #define USE_THE_INDEX_VARIABLE
6 #include "cache-tree.h"
7 #include "parse-options.h"
8 #include "read-cache-ll.h"
9 #include "repository.h"
12 static char const * const test_cache_tree_usage
[] = {
13 N_("test-tool cache-tree <options> (control|prime|update)"),
17 int cmd__cache_tree(int argc
, const char **argv
)
22 int invalidate_qty
= 0;
25 struct option options
[] = {
26 OPT_BOOL(0, "empty", &empty
,
27 N_("clear the cache tree before each iteration")),
28 OPT_INTEGER_F(0, "invalidate", &invalidate_qty
,
29 N_("number of entries in the cache tree to invalidate (default 0)"),
34 setup_git_directory();
36 argc
= parse_options(argc
, argv
, NULL
, options
, test_cache_tree_usage
, 0);
38 if (repo_read_index(the_repository
) < 0)
39 die(_("unable to read index file"));
41 oidcpy(&oid
, &the_index
.cache_tree
->oid
);
42 tree
= parse_tree_indirect(&oid
);
44 die(_("not a tree object: %s"), oid_to_hex(&oid
));
47 /* clear the cache tree & allocate a new one */
48 cache_tree_free(&the_index
.cache_tree
);
49 the_index
.cache_tree
= cache_tree();
50 } else if (invalidate_qty
) {
51 /* invalidate the specified number of unique paths */
52 float f_interval
= (float)the_index
.cache_nr
/ invalidate_qty
;
53 int interval
= f_interval
< 1.0 ? 1 : (int)f_interval
;
54 for (i
= 0; i
< invalidate_qty
&& i
* interval
< the_index
.cache_nr
; i
++)
55 cache_tree_invalidate_path(&the_index
, the_index
.cache
[i
* interval
]->name
);
59 usage_with_options(test_cache_tree_usage
, options
);
60 else if (!strcmp(argv
[0], "prime"))
61 prime_cache_tree(the_repository
, &the_index
, tree
);
62 else if (!strcmp(argv
[0], "update"))
63 cache_tree_update(&the_index
, WRITE_TREE_SILENT
| WRITE_TREE_REPAIR
);
64 /* use "control" subcommand to specify no-op */
65 else if (!!strcmp(argv
[0], "control"))
66 die(_("Unhandled subcommand '%s'"), argv
[0]);