Merge branch 'sb/userdiff-dts'
[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         if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
11                 argc--;
12                 argv++;
13         }
14
15         if (argc == 2)
16                 cnt = strtol(argv[1], NULL, 0);
17         setup_git_directory();
18         git_config(git_default_config, NULL);
19         for (i = 0; i < cnt; i++) {
20                 read_cache();
21                 if (name) {
22                         int pos;
23
24                         refresh_index(&the_index, REFRESH_QUIET,
25                                       NULL, NULL, NULL);
26                         pos = index_name_pos(&the_index, name, strlen(name));
27                         if (pos < 0)
28                                 die("%s not in index", name);
29                         printf("%s is%s up to date\n", name,
30                                ce_uptodate(the_index.cache[pos]) ? "" : " not");
31                         write_file(name, "%d\n", i);
32                 }
33                 discard_cache();
34         }
35         return 0;
36 }