Merge branch 'ab/config-based-hooks-base' into seen
[git] / t / helper / test-read-cache-perf.c
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "parse-options.h"
4
5 static const char *read_cache_perf_usage[] = {
6         "test-tool read-cache-perf [<options>...]",
7         NULL
8 };
9
10 int cmd__read_cache_perf(int argc, const char **argv)
11 {
12         struct repository *r = the_repository;
13         int cnt = -1;
14         int refresh = 0;
15         struct option options[] = {
16                 OPT_INTEGER(0, "count", &cnt, "number of passes"),
17                 OPT_BOOL(0, "refresh", &refresh,
18                          "call refresh_index() in a loop, not read()/discard()"),
19                 OPT_END()
20         };
21
22         argc = parse_options(argc, argv, "test-tools", options,
23                              read_cache_perf_usage, 0);
24         if (argc > 0)
25                 usage_msg_opt("Too many arguments.", read_cache_perf_usage,
26                               options);
27         if (cnt < 1)
28                 usage_msg_opt("Need at least one pass.", read_cache_perf_usage,
29                               options);
30
31         setup_git_directory();
32         if (refresh)
33                 repo_read_index(r);
34         while (cnt--) {
35                 if (refresh) {
36                         unsigned int flags = REFRESH_QUIET|REFRESH_PROGRESS;
37                         refresh_index(r->index, flags, NULL, NULL, NULL);
38                         continue;
39                 }
40                 repo_read_index(r);
41                 discard_index(r->index);
42         }
43         if (refresh)
44                 discard_index(r->index);
45
46         return 0;
47 }