1 #define USE_THE_INDEX_VARIABLE
5 #include "cache-tree.h"
6 #include "parse-options.h"
8 static char const * const test_cache_tree_usage
[] = {
9 N_("test-tool cache-tree <options> (control|prime|update)"),
13 int cmd__cache_tree(int argc
, const char **argv
)
18 int invalidate_qty
= 0;
21 struct option options
[] = {
22 OPT_BOOL(0, "empty", &empty
,
23 N_("clear the cache tree before each iteration")),
24 OPT_INTEGER_F(0, "invalidate", &invalidate_qty
,
25 N_("number of entries in the cache tree to invalidate (default 0)"),
30 setup_git_directory();
32 argc
= parse_options(argc
, argv
, NULL
, options
, test_cache_tree_usage
, 0);
34 if (repo_read_index(the_repository
) < 0)
35 die(_("unable to read index file"));
37 oidcpy(&oid
, &the_index
.cache_tree
->oid
);
38 tree
= parse_tree_indirect(&oid
);
40 die(_("not a tree object: %s"), oid_to_hex(&oid
));
43 /* clear the cache tree & allocate a new one */
44 cache_tree_free(&the_index
.cache_tree
);
45 the_index
.cache_tree
= cache_tree();
46 } else if (invalidate_qty
) {
47 /* invalidate the specified number of unique paths */
48 float f_interval
= (float)the_index
.cache_nr
/ invalidate_qty
;
49 int interval
= f_interval
< 1.0 ? 1 : (int)f_interval
;
50 for (i
= 0; i
< invalidate_qty
&& i
* interval
< the_index
.cache_nr
; i
++)
51 cache_tree_invalidate_path(&the_index
, the_index
.cache
[i
* interval
]->name
);
55 usage_with_options(test_cache_tree_usage
, options
);
56 else if (!strcmp(argv
[0], "prime"))
57 prime_cache_tree(the_repository
, &the_index
, tree
);
58 else if (!strcmp(argv
[0], "update"))
59 cache_tree_update(&the_index
, WRITE_TREE_SILENT
| WRITE_TREE_REPAIR
);
60 /* use "control" subcommand to specify no-op */
61 else if (!!strcmp(argv
[0], "control"))
62 die(_("Unhandled subcommand '%s'"), argv
[0]);