]> granicus.if.org Git - git/commitdiff
dir.c: support tracing exclude
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 15 Feb 2016 09:03:37 +0000 (16:03 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 15 Feb 2016 23:32:32 +0000 (15:32 -0800)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-check-ignore.txt
Documentation/git.txt
dir.c

index e94367a5ed8e8b94bca7036ff7616bc3cfa9ca97..f60ee051f8c0e930e790add0bd1be39f49c82785 100644 (file)
@@ -114,6 +114,7 @@ SEE ALSO
 linkgit:gitignore[5]
 linkgit:gitconfig[5]
 linkgit:git-ls-files[1]
+GIT_TRACE_EXCLUDE in linkgit:git[1]
 
 GIT
 ---
index d987ad20c90a05932733c09812324c3d176ebbbe..2c4f0f247065966e26bd1971db66ed74aacfa54b 100644 (file)
@@ -1064,6 +1064,11 @@ of clones and fetches.
        cloning of shallow repositories.
        See 'GIT_TRACE' for available trace output options.
 
+'GIT_TRACE_EXCLUDE'::
+       Enables trace messages that can help debugging .gitignore
+       processing. See 'GIT_TRACE' for available trace output
+       options.
+
 'GIT_LITERAL_PATHSPECS'::
        Setting this variable to `1` will cause Git to treat all
        pathspecs literally, rather than as glob patterns. For example,
diff --git a/dir.c b/dir.c
index bcaafac40418ce90d650e56f7edeb8eed178d282..0be7cf19253d5a7648a45ae6d59d92b7957fef70 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -53,6 +53,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
        int check_only, const struct path_simplify *simplify);
 static int get_dtype(struct dirent *de, const char *path, int len);
 
+static struct trace_key trace_exclude = TRACE_KEY_INIT(EXCLUDE);
+
 /* helper string functions with support for the ignore_case flag */
 int strcmp_icase(const char *a, const char *b)
 {
@@ -905,6 +907,8 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
        if (!el->nr)
                return NULL;    /* undefined */
 
+       trace_printf_key(&trace_exclude, "exclude: from %s\n", el->src);
+
        for (i = el->nr - 1; 0 <= i; i--) {
                struct exclude *x = el->excludes[i];
                const char *exclude = x->pattern;
@@ -936,6 +940,16 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
                        break;
                }
        }
+
+       if (!exc) {
+               trace_printf_key(&trace_exclude, "exclude: %.*s => n/a\n",
+                                pathlen, pathname);
+               return NULL;
+       }
+
+       trace_printf_key(&trace_exclude, "exclude: %.*s vs %s at line %d => %s\n",
+                        pathlen, pathname, exc->pattern, exc->srcpos,
+                        exc->flags & EXC_FLAG_NEGATIVE ? "no" : "yes");
        return exc;
 }
 
@@ -1683,9 +1697,13 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
        struct cached_dir cdir;
        enum path_treatment state, subdir_state, dir_state = path_none;
        struct strbuf path = STRBUF_INIT;
+       static int level = 0;
 
        strbuf_add(&path, base, baselen);
 
+       trace_printf_key(&trace_exclude, "exclude: [%d] enter '%.*s'\n",
+                        level++, baselen, base);
+
        if (open_cached_dir(&cdir, dir, untracked, &path, check_only))
                goto out;
 
@@ -1749,6 +1767,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
        }
        close_cached_dir(&cdir);
  out:
+       trace_printf_key(&trace_exclude, "exclude: [%d] leave '%.*s'\n",
+                        --level, baselen, base);
        strbuf_release(&path);
 
        return dir_state;