summaryrefslogtreecommitdiff
path: root/test-dump-untracked-cache.c
blob: 710441ee054626908d69550bb2011daad0488331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "cache.h"
#include "dir.h"
 
static int compare_untracked(const void *a_, const void *b_)
{
	const char *const *a = a_;
	const char *const *b = b_;
	return strcmp(*a, *b);
}
 
static int compare_dir(const void *a_, const void *b_)
{
	const struct untracked_cache_dir *const *a = a_;
	const struct untracked_cache_dir *const *b = b_;
	return strcmp((*a)->name, (*b)->name);
}
 
static void dump(struct untracked_cache_dir *ucd, struct strbuf *base)
{
	int i, len;
	qsort(ucd->untracked, ucd->untracked_nr, sizeof(*ucd->untracked),
	      compare_untracked);
	qsort(ucd->dirs, ucd->dirs_nr, sizeof(*ucd->dirs),
	      compare_dir);
	len = base->len;
	strbuf_addf(base, "%s/", ucd->name);
	printf("%s %s", base->buf,
	       sha1_to_hex(ucd->exclude_sha1));
	if (ucd->recurse)
		fputs(" recurse", stdout);
	if (ucd->check_only)
		fputs(" check_only", stdout);
	if (ucd->valid)
		fputs(" valid", stdout);
	printf("\n");
	for (i = 0; i < ucd->untracked_nr; i++)
		printf("%s\n", ucd->untracked[i]);
	for (i = 0; i < ucd->dirs_nr; i++)
		dump(ucd->dirs[i], base);
	strbuf_setlen(base, len);
}
 
int main(int ac, char **av)
{
	struct untracked_cache *uc;
	struct strbuf base = STRBUF_INIT;
	if (read_cache() < 0)
		die("unable to read index file");
	uc = the_index.untracked;
	if (!uc) {
		printf("no untracked cache\n");
		return 0;
	}
	printf("info/exclude %s\n", sha1_to_hex(uc->ss_info_exclude.sha1));
	printf("core.excludesfile %s\n", sha1_to_hex(uc->ss_excludes_file.sha1));
	printf("exclude_per_dir %s\n", uc->exclude_per_dir);
	printf("flags %08x\n", uc->dir_flags);
	if (uc->root)
		dump(uc->root, &base);
	return 0;
}