| 1 | #define USE_THE_REPOSITORY_VARIABLE |
| 2 | |
| 3 | #include "test-tool.h" |
| 4 | #include "dir.h" |
| 5 | #include "hex.h" |
| 6 | #include "read-cache-ll.h" |
| 7 | #include "repository.h" |
| 8 | #include "setup.h" |
| 9 | |
| 10 | static int compare_untracked(const void *a_, const void *b_) |
| 11 | { |
| 12 | const char *const *a = a_; |
| 13 | const char *const *b = b_; |
| 14 | return strcmp(*a, *b); |
| 15 | } |
| 16 | |
| 17 | static int compare_dir(const void *a_, const void *b_) |
| 18 | { |
| 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); |
| 22 | } |
| 23 | |
| 24 | static void dump(struct untracked_cache_dir *ucd, struct strbuf *base) |
| 25 | { |
| 26 | int 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 (size_t i = 0; i < ucd->untracked_nr; i++) |
| 41 | printf("%s\n", ucd->untracked[i]); |
| 42 | for (size_t i = 0; i < ucd->dirs_nr; i++) |
| 43 | dump(ucd->dirs[i], base); |
| 44 | strbuf_setlen(base, len); |
| 45 | } |
| 46 | |
| 47 | int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED) |
| 48 | { |
| 49 | struct untracked_cache *uc; |
| 50 | struct strbuf base = STRBUF_INIT; |
| 51 | |
| 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); |
| 56 | |
| 57 | setup_git_directory(the_repository); |
| 58 | if (repo_read_index(the_repository) < 0) |
| 59 | die("unable to read index file"); |
| 60 | uc = the_repository->index->untracked; |
| 61 | if (!uc) { |
| 62 | printf("no untracked cache\n"); |
| 63 | return 0; |
| 64 | } |
| 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 | |
| 72 | strbuf_release(&base); |
| 73 | return 0; |
| 74 | } |