]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-dump-untracked-cache.c
dir: convert struct untracked_cache_dir to object_id
[thirdparty/git.git] / t / helper / test-dump-untracked-cache.c
CommitLineData
a3ddcefd
NTND
1#include "cache.h"
2#include "dir.h"
3
4static int compare_untracked(const void *a_, const void *b_)
5{
6 const char *const *a = a_;
7 const char *const *b = b_;
8 return strcmp(*a, *b);
9}
10
11static int compare_dir(const void *a_, const void *b_)
12{
13 const struct untracked_cache_dir *const *a = a_;
14 const struct untracked_cache_dir *const *b = b_;
15 return strcmp((*a)->name, (*b)->name);
16}
17
18static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
19{
20 int i, len;
9ed0d8d6
RS
21 QSORT(ucd->untracked, ucd->untracked_nr, compare_untracked);
22 QSORT(ucd->dirs, ucd->dirs_nr, compare_dir);
a3ddcefd
NTND
23 len = base->len;
24 strbuf_addf(base, "%s/", ucd->name);
25 printf("%s %s", base->buf,
70c369cd 26 oid_to_hex(&ucd->exclude_oid));
a3ddcefd
NTND
27 if (ucd->recurse)
28 fputs(" recurse", stdout);
29 if (ucd->check_only)
30 fputs(" check_only", stdout);
31 if (ucd->valid)
32 fputs(" valid", stdout);
33 printf("\n");
34 for (i = 0; i < ucd->untracked_nr; i++)
35 printf("%s\n", ucd->untracked[i]);
36 for (i = 0; i < ucd->dirs_nr; i++)
37 dump(ucd->dirs[i], base);
38 strbuf_setlen(base, len);
39}
40
3f2e2297 41int cmd_main(int ac, const char **av)
a3ddcefd
NTND
42{
43 struct untracked_cache *uc;
44 struct strbuf base = STRBUF_INIT;
dae6c322
CC
45
46 /* Hack to avoid modifying the untracked cache when we read it */
47 ignore_untracked_cache_config = 1;
48
1e8fef60 49 setup_git_directory();
a3ddcefd
NTND
50 if (read_cache() < 0)
51 die("unable to read index file");
52 uc = the_index.untracked;
53 if (!uc) {
54 printf("no untracked cache\n");
55 return 0;
56 }
4b33e602
PO
57 printf("info/exclude %s\n", oid_to_hex(&uc->ss_info_exclude.oid));
58 printf("core.excludesfile %s\n", oid_to_hex(&uc->ss_excludes_file.oid));
a3ddcefd
NTND
59 printf("exclude_per_dir %s\n", uc->exclude_per_dir);
60 printf("flags %08x\n", uc->dir_flags);
61 if (uc->root)
62 dump(uc->root, &base);
63 return 0;
64}