Fourth batch
[git/raj.git] / t / helper / test-read-cache.c
blob244977a29bdfda7839c62b97e7f1ba591b02abff
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "config.h"
5 int cmd__read_cache(int argc, const char **argv)
7 int i, cnt = 1;
8 const char *name = NULL;
10 if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
11 argc--;
12 argv++;
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;
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);
33 discard_cache();
35 return 0;