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