The 20th batch
[git.git] / t / helper / test-read-cache.c
blobd285c656bd3a3276c7c3e1b7e5a88f2d276223ab
1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "test-tool.h"
4 #include "config.h"
5 #include "read-cache-ll.h"
6 #include "repository.h"
7 #include "setup.h"
9 int cmd__read_cache(int argc, const char **argv)
11 int i, cnt = 1;
12 const char *name = NULL;
14 initialize_repository(the_repository);
16 if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
17 argc--;
18 argv++;
21 if (argc == 2)
22 cnt = strtol(argv[1], NULL, 0);
23 setup_git_directory();
24 git_config(git_default_config, NULL);
26 for (i = 0; i < cnt; i++) {
27 repo_read_index(the_repository);
28 if (name) {
29 int pos;
31 refresh_index(the_repository->index, REFRESH_QUIET,
32 NULL, NULL, NULL);
33 pos = index_name_pos(the_repository->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_repository->index->cache[pos]) ? "" : " not");
38 write_file(name, "%d\n", i);
40 discard_index(the_repository->index);
42 return 0;