]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-read-cache.c
rebase: allow overriding the maximal length of the generated labels
[thirdparty/git.git] / t / helper / test-read-cache.c
1 #define USE_THE_INDEX_VARIABLE
2 #include "test-tool.h"
3 #include "cache.h"
4 #include "config.h"
5 #include "repository.h"
6 #include "setup.h"
7 #include "wrapper.h"
8
9 int cmd__read_cache(int argc, const char **argv)
10 {
11 int i, cnt = 1;
12 const char *name = NULL;
13
14 initialize_the_repository();
15
16 if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
17 argc--;
18 argv++;
19 }
20
21 if (argc == 2)
22 cnt = strtol(argv[1], NULL, 0);
23 setup_git_directory();
24 git_config(git_default_config, NULL);
25
26 for (i = 0; i < cnt; i++) {
27 repo_read_index(the_repository);
28 if (name) {
29 int pos;
30
31 refresh_index(&the_index, REFRESH_QUIET,
32 NULL, NULL, NULL);
33 pos = index_name_pos(&the_index, name, strlen(name));
34 if (pos < 0)
35 die("%s not in index", name);
36 printf("%s is%s up to date\n", name,
37 ce_uptodate(the_index.cache[pos]) ? "" : " not");
38 write_file(name, "%d\n", i);
39 }
40 discard_index(&the_index);
41 }
42 return 0;
43 }