]>
git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-dump-untracked-cache.c
1 #define USE_THE_INDEX_VARIABLE
5 #include "read-cache-ll.h"
6 #include "repository.h"
9 static int compare_untracked(const void *a_
, const void *b_
)
11 const char *const *a
= a_
;
12 const char *const *b
= b_
;
13 return strcmp(*a
, *b
);
16 static int compare_dir(const void *a_
, const void *b_
)
18 const struct untracked_cache_dir
*const *a
= a_
;
19 const struct untracked_cache_dir
*const *b
= b_
;
20 return strcmp((*a
)->name
, (*b
)->name
);
23 static void dump(struct untracked_cache_dir
*ucd
, struct strbuf
*base
)
26 QSORT(ucd
->untracked
, ucd
->untracked_nr
, compare_untracked
);
27 QSORT(ucd
->dirs
, ucd
->dirs_nr
, compare_dir
);
29 strbuf_addf(base
, "%s/", ucd
->name
);
30 printf("%s %s", base
->buf
,
31 oid_to_hex(&ucd
->exclude_oid
));
33 fputs(" recurse", stdout
);
35 fputs(" check_only", stdout
);
37 fputs(" valid", stdout
);
39 for (i
= 0; i
< ucd
->untracked_nr
; i
++)
40 printf("%s\n", ucd
->untracked
[i
]);
41 for (i
= 0; i
< ucd
->dirs_nr
; i
++)
42 dump(ucd
->dirs
[i
], base
);
43 strbuf_setlen(base
, len
);
46 int cmd__dump_untracked_cache(int ac UNUSED
, const char **av UNUSED
)
48 struct untracked_cache
*uc
;
49 struct strbuf base
= STRBUF_INIT
;
51 /* Set core.untrackedCache=keep before setup_git_directory() */
52 xsetenv("GIT_CONFIG_COUNT", "1", 1);
53 xsetenv("GIT_CONFIG_KEY_0", "core.untrackedCache", 1);
54 xsetenv("GIT_CONFIG_VALUE_0", "keep", 1);
56 setup_git_directory();
57 if (repo_read_index(the_repository
) < 0)
58 die("unable to read index file");
59 uc
= the_index
.untracked
;
61 printf("no untracked cache\n");
64 printf("info/exclude %s\n", oid_to_hex(&uc
->ss_info_exclude
.oid
));
65 printf("core.excludesfile %s\n", oid_to_hex(&uc
->ss_excludes_file
.oid
));
66 printf("exclude_per_dir %s\n", uc
->exclude_per_dir
);
67 printf("flags %08x\n", uc
->dir_flags
);
69 dump(uc
->root
, &base
);