dir.c: support tracing exclude
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 15, 2016 at 16:03 UTC
bac65a2be598811d944c846bdf61580f5c1af927
3 files changed
+26
Documentation/git-check-ignore.txt
+1
@@ -114,6 +114,7 @@ SEE ALSO
114
linkgit:gitignore[5]
115
linkgit:gitconfig[5]
116
linkgit:git-ls-files[1]
117
+GIT_TRACE_EXCLUDE in linkgit:git[1]
118
119
GIT
120
---
Documentation/git.txt
+5
@@ -1064,6 +1064,11 @@ of clones and fetches.
1064
cloning of shallow repositories.
1065
See 'GIT_TRACE' for available trace output options.
1066
1067
+'GIT_TRACE_EXCLUDE'::
1068
+ Enables trace messages that can help debugging .gitignore
1069
+ processing. See 'GIT_TRACE' for available trace output
1070
+ options.
1071
+
1072
'GIT_LITERAL_PATHSPECS'::
1073
Setting this variable to `1` will cause Git to treat all
1074
pathspecs literally, rather than as glob patterns. For example,
dir.c
+20
@@ -53,6 +53,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
53
int check_only, const struct path_simplify *simplify);
54
static int get_dtype(struct dirent *de, const char *path, int len);
55
56
+static struct trace_key trace_exclude = TRACE_KEY_INIT(EXCLUDE);
57
+
58
/* helper string functions with support for the ignore_case flag */
59
int strcmp_icase(const char *a, const char *b)
60
{
@@ -905,6 +907,8 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
907
if (!el->nr)
908
return NULL; /* undefined */
909
910
+ trace_printf_key(&trace_exclude, "exclude: from %s\n", el->src);
911
+
912
for (i = el->nr - 1; 0 <= i; i--) {
913
struct exclude *x = el->excludes[i];
914
const char *exclude = x->pattern;
@@ -936,6 +940,16 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
940
break;
941
}
942
}
943
+
944
+ if (!exc) {
945
+ trace_printf_key(&trace_exclude, "exclude: %.*s => n/a\n",
946
+ pathlen, pathname);
947
+ return NULL;
948
+ }
949
+
950
+ trace_printf_key(&trace_exclude, "exclude: %.*s vs %s at line %d => %s\n",
951
+ pathlen, pathname, exc->pattern, exc->srcpos,
952
+ exc->flags & EXC_FLAG_NEGATIVE ? "no" : "yes");
953
return exc;
954
}
955
@@ -1683,9 +1697,13 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
1697
struct cached_dir cdir;
1698
enum path_treatment state, subdir_state, dir_state = path_none;
1699
struct strbuf path = STRBUF_INIT;
1700
+ static int level = 0;
1701
1702
strbuf_add(&path, base, baselen);
1703
1704
+ trace_printf_key(&trace_exclude, "exclude: [%d] enter '%.*s'\n",
1705
+ level++, baselen, base);
1706
+
1707
if (open_cached_dir(&cdir, dir, untracked, &path, check_only))
1708
goto out;
1709
@@ -1749,6 +1767,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
1767
}
1768
close_cached_dir(&cdir);
1769
out:
1770
+ trace_printf_key(&trace_exclude, "exclude: [%d] leave '%.*s'\n",
1771
+ --level, baselen, base);
1772
strbuf_release(&path);
1773
1774
return dir_state;