test-dump-untracked-cache.con commit Documentation/git-for-each-ref: don't list date formats (8f50d26)
   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;
  21        qsort(ucd->untracked, ucd->untracked_nr, sizeof(*ucd->untracked),
  22              compare_untracked);
  23        qsort(ucd->dirs, ucd->dirs_nr, sizeof(*ucd->dirs),
  24              compare_dir);
  25        len = base->len;
  26        strbuf_addf(base, "%s/", ucd->name);
  27        printf("%s %s", base->buf,
  28               sha1_to_hex(ucd->exclude_sha1));
  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
  43int main(int ac, char **av)
  44{
  45        struct untracked_cache *uc;
  46        struct strbuf base = STRBUF_INIT;
  47        setup_git_directory();
  48        if (read_cache() < 0)
  49                die("unable to read index file");
  50        uc = the_index.untracked;
  51        if (!uc) {
  52                printf("no untracked cache\n");
  53                return 0;
  54        }
  55        printf("info/exclude %s\n", sha1_to_hex(uc->ss_info_exclude.sha1));
  56        printf("core.excludesfile %s\n", sha1_to_hex(uc->ss_excludes_file.sha1));
  57        printf("exclude_per_dir %s\n", uc->exclude_per_dir);
  58        printf("flags %08x\n", uc->dir_flags);
  59        if (uc->root)
  60                dump(uc->root, &base);
  61        return 0;
  62}