]>
Commit | Line | Data |
---|---|---|
bdafeae0 | 1 | #define USE_THE_INDEX_VARIABLE |
94fcf0e8 | 2 | #include "test-tool.h" |
f394e093 | 3 | #include "gettext.h" |
41771fa4 | 4 | #include "hex.h" |
94fcf0e8 VD |
5 | #include "tree.h" |
6 | #include "cache-tree.h" | |
7 | #include "parse-options.h" | |
08c46a49 | 8 | #include "read-cache-ll.h" |
d1cbe1e6 | 9 | #include "repository.h" |
e38da487 | 10 | #include "setup.h" |
94fcf0e8 VD |
11 | |
12 | static char const * const test_cache_tree_usage[] = { | |
13 | N_("test-tool cache-tree <options> (control|prime|update)"), | |
14 | NULL | |
15 | }; | |
16 | ||
17 | int cmd__cache_tree(int argc, const char **argv) | |
18 | { | |
19 | struct object_id oid; | |
20 | struct tree *tree; | |
21 | int empty = 0; | |
22 | int invalidate_qty = 0; | |
23 | int i; | |
24 | ||
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)"), | |
30 | PARSE_OPT_NONEG), | |
31 | OPT_END() | |
32 | }; | |
33 | ||
34 | setup_git_directory(); | |
35 | ||
36 | argc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0); | |
37 | ||
0ea414a1 | 38 | if (repo_read_index(the_repository) < 0) |
94fcf0e8 VD |
39 | die(_("unable to read index file")); |
40 | ||
41 | oidcpy(&oid, &the_index.cache_tree->oid); | |
42 | tree = parse_tree_indirect(&oid); | |
43 | if (!tree) | |
44 | die(_("not a tree object: %s"), oid_to_hex(&oid)); | |
45 | ||
46 | if (empty) { | |
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); | |
56 | } | |
57 | ||
58 | if (argc != 1) | |
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]); | |
67 | ||
68 | return 0; | |
69 | } |