]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-read-cache.c
Merge branch 'da/rhel7-lacks-uncompress2-and-c99'
[thirdparty/git.git] / t / helper / test-read-cache.c
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "config.h"
4
5 int cmd__read_cache(int argc, const char **argv)
6 {
7 int i, cnt = 1;
8 const char *name = NULL;
9
10 initialize_the_repository();
11
12 if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
13 argc--;
14 argv++;
15 }
16
17 if (argc == 2)
18 cnt = strtol(argv[1], NULL, 0);
19 setup_git_directory();
20 git_config(git_default_config, NULL);
21
22 for (i = 0; i < cnt; i++) {
23 read_cache();
24 if (name) {
25 int pos;
26
27 refresh_index(&the_index, REFRESH_QUIET,
28 NULL, NULL, NULL);
29 pos = index_name_pos(&the_index, name, strlen(name));
30 if (pos < 0)
31 die("%s not in index", name);
32 printf("%s is%s up to date\n", name,
33 ce_uptodate(the_index.cache[pos]) ? "" : " not");
34 write_file(name, "%d\n", i);
35 }
36 discard_cache();
37 }
38 return 0;
39 }