Sync with 'maint'
[git.git] / t / helper / test-read-cache.c
blobe803c43ece92def7bc69c253a49bc5602129d22c
1 #include "test-tool.h"
2 #include "config.h"
3 #include "read-cache-ll.h"
4 #include "repository.h"
5 #include "setup.h"
7 int cmd__read_cache(int argc, const char **argv)
9 int i, cnt = 1;
10 const char *name = NULL;
12 initialize_repository(the_repository);
14 if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
15 argc--;
16 argv++;
19 if (argc == 2)
20 cnt = strtol(argv[1], NULL, 0);
21 setup_git_directory();
22 git_config(git_default_config, NULL);
24 for (i = 0; i < cnt; i++) {
25 repo_read_index(the_repository);
26 if (name) {
27 int pos;
29 refresh_index(the_repository->index, REFRESH_QUIET,
30 NULL, NULL, NULL);
31 pos = index_name_pos(the_repository->index, name, strlen(name));
32 if (pos < 0)
33 die("%s not in index", name);
34 printf("%s is%s up to date\n", name,
35 ce_uptodate(the_repository->index->cache[pos]) ? "" : " not");
36 write_file(name, "%d\n", i);
38 discard_index(the_repository->index);
40 return 0;