read-cache*.h: move declarations for read-cache.c functions from cache.h
[alt-git.git] / t / helper / test-dump-untracked-cache.c
bloba1cbafd64f33004dcf37c18c9f4d583d1a7268e6
1 #define USE_THE_INDEX_VARIABLE
2 #include "test-tool.h"
3 #include "cache.h"
4 #include "dir.h"
5 #include "hex.h"
6 #include "read-cache-ll.h"
7 #include "repository.h"
8 #include "setup.h"
10 static int compare_untracked(const void *a_, const void *b_)
12 const char *const *a = a_;
13 const char *const *b = b_;
14 return strcmp(*a, *b);
17 static int compare_dir(const void *a_, const void *b_)
19 const struct untracked_cache_dir *const *a = a_;
20 const struct untracked_cache_dir *const *b = b_;
21 return strcmp((*a)->name, (*b)->name);
24 static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
26 int i, len;
27 QSORT(ucd->untracked, ucd->untracked_nr, compare_untracked);
28 QSORT(ucd->dirs, ucd->dirs_nr, compare_dir);
29 len = base->len;
30 strbuf_addf(base, "%s/", ucd->name);
31 printf("%s %s", base->buf,
32 oid_to_hex(&ucd->exclude_oid));
33 if (ucd->recurse)
34 fputs(" recurse", stdout);
35 if (ucd->check_only)
36 fputs(" check_only", stdout);
37 if (ucd->valid)
38 fputs(" valid", stdout);
39 printf("\n");
40 for (i = 0; i < ucd->untracked_nr; i++)
41 printf("%s\n", ucd->untracked[i]);
42 for (i = 0; i < ucd->dirs_nr; i++)
43 dump(ucd->dirs[i], base);
44 strbuf_setlen(base, len);
47 int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
49 struct untracked_cache *uc;
50 struct strbuf base = STRBUF_INIT;
52 /* Set core.untrackedCache=keep before setup_git_directory() */
53 xsetenv("GIT_CONFIG_COUNT", "1", 1);
54 xsetenv("GIT_CONFIG_KEY_0", "core.untrackedCache", 1);
55 xsetenv("GIT_CONFIG_VALUE_0", "keep", 1);
57 setup_git_directory();
58 if (repo_read_index(the_repository) < 0)
59 die("unable to read index file");
60 uc = the_index.untracked;
61 if (!uc) {
62 printf("no untracked cache\n");
63 return 0;
65 printf("info/exclude %s\n", oid_to_hex(&uc->ss_info_exclude.oid));
66 printf("core.excludesfile %s\n", oid_to_hex(&uc->ss_excludes_file.oid));
67 printf("exclude_per_dir %s\n", uc->exclude_per_dir);
68 printf("flags %08x\n", uc->dir_flags);
69 if (uc->root)
70 dump(uc->root, &base);
71 return 0;