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