Skip to content

Commit bac65a2

Browse files
pcloudsgitster
authored andcommitted
dir.c: support tracing exclude
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a60ea8f commit bac65a2

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Documentation/git-check-ignore.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ SEE ALSO
114114
linkgit:gitignore[5]
115115
linkgit:gitconfig[5]
116116
linkgit:git-ls-files[1]
117+
GIT_TRACE_EXCLUDE in linkgit:git[1]
117118

118119
GIT
119120
---

Documentation/git.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,11 @@ of clones and fetches.
10641064
cloning of shallow repositories.
10651065
See 'GIT_TRACE' for available trace output options.
10661066

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+
10671072
'GIT_LITERAL_PATHSPECS'::
10681073
Setting this variable to `1` will cause Git to treat all
10691074
pathspecs literally, rather than as glob patterns. For example,

dir.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
5353
int check_only, const struct path_simplify *simplify);
5454
static int get_dtype(struct dirent *de, const char *path, int len);
5555

56+
static struct trace_key trace_exclude = TRACE_KEY_INIT(EXCLUDE);
57+
5658
/* helper string functions with support for the ignore_case flag */
5759
int strcmp_icase(const char *a, const char *b)
5860
{
@@ -905,6 +907,8 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
905907
if (!el->nr)
906908
return NULL; /* undefined */
907909

910+
trace_printf_key(&trace_exclude, "exclude: from %s\n", el->src);
911+
908912
for (i = el->nr - 1; 0 <= i; i--) {
909913
struct exclude *x = el->excludes[i];
910914
const char *exclude = x->pattern;
@@ -936,6 +940,16 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
936940
break;
937941
}
938942
}
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");
939953
return exc;
940954
}
941955

@@ -1683,9 +1697,13 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
16831697
struct cached_dir cdir;
16841698
enum path_treatment state, subdir_state, dir_state = path_none;
16851699
struct strbuf path = STRBUF_INIT;
1700+
static int level = 0;
16861701

16871702
strbuf_add(&path, base, baselen);
16881703

1704+
trace_printf_key(&trace_exclude, "exclude: [%d] enter '%.*s'\n",
1705+
level++, baselen, base);
1706+
16891707
if (open_cached_dir(&cdir, dir, untracked, &path, check_only))
16901708
goto out;
16911709

@@ -1749,6 +1767,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
17491767
}
17501768
close_cached_dir(&cdir);
17511769
out:
1770+
trace_printf_key(&trace_exclude, "exclude: [%d] leave '%.*s'\n",
1771+
--level, baselen, base);
17521772
strbuf_release(&path);
17531773

17541774
return dir_state;

0 commit comments

Comments
 (0)