]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-read-cache.c
Merge branch 'jc/git-gui-maintainer-update'
[thirdparty/git.git] / t / helper / test-read-cache.c
1 #include "test-tool.h"
2 #include "config.h"
3 #include "read-cache-ll.h"
4 #include "repository.h"
5 #include "setup.h"
6
7 int cmd__read_cache(int argc, const char **argv)
8 {
9 int i, cnt = 1;
10 const char *name = NULL;
11
12 initialize_repository(the_repository);
13
14 if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
15 argc--;
16 argv++;
17 }
18
19 if (argc == 2)
20 cnt = strtol(argv[1], NULL, 0);
21 setup_git_directory();
22 git_config(git_default_config, NULL);
23
24 for (i = 0; i < cnt; i++) {
25 repo_read_index(the_repository);
26 if (name) {
27 int pos;
28
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);
37 }
38 discard_index(the_repository->index);
39 }
40 return 0;
41 }