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