Git development
 help / color / mirror / Atom feed
* [PATCH] Revert "dir.c: don't exclude whole dir prematurely if neg pattern may match"
@ 2016-01-08 12:05 Nguyễn Thái Ngọc Duy
  2016-01-08 12:12 ` Duy Nguyen
  0 siblings, 1 reply; 3+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2016-01-08 12:05 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

This reverts commit 57534ee77d22e725d971ee89c77dc6aad61c573f. The
feature added in that commit requires that patterns behave the same way
from anywhere. But some patterns can behave differently depending on
current "working" directory. The conditions to catch and avoid these
patterns are too loose. The untracked listing and sparse-checkout
selection can become incorrect as a result.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/gitignore.txt        | 23 ++----------
 dir.c                              | 76 +-------------------------------------
 t/t3001-ls-files-others-exclude.sh | 25 -------------
 3 files changed, 6 insertions(+), 118 deletions(-)

diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt
index 79a1948..473623d 100644
--- a/Documentation/gitignore.txt
+++ b/Documentation/gitignore.txt
@@ -82,12 +82,12 @@ PATTERN FORMAT
 
  - An optional prefix "`!`" which negates the pattern; any
    matching file excluded by a previous pattern will become
-   included again.
+   included again. It is not possible to re-include a file if a parent
+   directory of that file is excluded. Git doesn't list excluded
+   directories for performance reasons, so any patterns on contained
+   files have no effect, no matter where they are defined.
    Put a backslash ("`\`") in front of the first "`!`" for patterns
    that begin with a literal "`!`", for example, "`\!important!.txt`".
-   It is possible to re-include a file if a parent directory of that
-   file is excluded if certain conditions are met. See section NOTES
-   for detail.
 
  - If the pattern ends with a slash, it is removed for the
    purpose of the following description, but it would only find
@@ -141,21 +141,6 @@ not tracked by Git remain untracked.
 To stop tracking a file that is currently tracked, use
 'git rm --cached'.
 
-To re-include files or directories when their parent directory is
-excluded, the following conditions must be met:
-
- - The rules to exclude a directory and re-include a subset back must
-   be in the same .gitignore file.
-
- - The directory part in the re-include rules must be literal (i.e. no
-   wildcards)
-
- - The rules to exclude the parent directory must not end with a
-   trailing slash.
-
- - The rules to exclude the parent directory must have at least one
-   slash.
-
 EXAMPLES
 --------
 
diff --git a/dir.c b/dir.c
index d2a8f06..206393a 100644
--- a/dir.c
+++ b/dir.c
@@ -882,25 +882,6 @@ int match_pathname(const char *pathname, int pathlen,
 		 */
 		if (!patternlen && !namelen)
 			return 1;
-		/*
-		 * This can happen when we ignore some exclude rules
-		 * on directories in other to see if negative rules
-		 * may match. E.g.
-		 *
-		 * /abc
-		 * !/abc/def/ghi
-		 *
-		 * The pattern of interest is "/abc". On the first
-		 * try, we should match path "abc" with this pattern
-		 * in the "if" statement right above, but the caller
-		 * ignores it.
-		 *
-		 * On the second try with paths within "abc",
-		 * e.g. "abc/xyz", we come here and try to match it
-		 * with "/abc".
-		 */
-		if (!patternlen && namelen && *name == '/')
-			return 1;
 	}
 
 	return fnmatch_icase_mem(pattern, patternlen,
@@ -909,48 +890,6 @@ int match_pathname(const char *pathname, int pathlen,
 }
 
 /*
- * Return non-zero if pathname is a directory and an ancestor of the
- * literal path in a (negative) pattern. This is used to keep
- * descending in "foo" and "foo/bar" when the pattern is
- * "!foo/bar/.gitignore". "foo/notbar" will not be descended however.
- */
-static int match_neg_path(const char *pathname, int pathlen, int *dtype,
-			  const char *base, int baselen,
-			  const char *pattern, int prefix, int patternlen,
-			  int flags)
-{
-	assert((flags & EXC_FLAG_NEGATIVE) && !(flags & EXC_FLAG_NODIR));
-
-	if (*dtype == DT_UNKNOWN)
-		*dtype = get_dtype(NULL, pathname, pathlen);
-	if (*dtype != DT_DIR)
-		return 0;
-
-	if (*pattern == '/') {
-		pattern++;
-		patternlen--;
-		prefix--;
-	}
-
-	if (baselen) {
-		if (((pathlen < baselen && base[pathlen] == '/') ||
-		     pathlen == baselen) &&
-		    !strncmp_icase(pathname, base, pathlen))
-			return 1;
-		pathname += baselen + 1;
-		pathlen  -= baselen + 1;
-	}
-
-
-	if (prefix &&
-	    ((pathlen < prefix && pattern[pathlen] == '/') &&
-	     !strncmp_icase(pathname, pattern, pathlen)))
-		return 1;
-
-	return 0;
-}
-
-/*
  * Scan the given exclude list in reverse to see whether pathname
  * should be ignored.  The first match (i.e. the last on the list), if
  * any, determines the fate.  Returns the exclude_list element which
@@ -963,7 +902,7 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
 						       struct exclude_list *el)
 {
 	struct exclude *exc = NULL; /* undecided */
-	int i, matched_negative_path = 0;
+	int i;
 
 	if (!el->nr)
 		return NULL;	/* undefined */
@@ -998,18 +937,7 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,
 			exc = x;
 			break;
 		}
-
-		if ((x->flags & EXC_FLAG_NEGATIVE) && !matched_negative_path &&
-		    match_neg_path(pathname, pathlen, dtype, x->base,
-				   x->baselen ? x->baselen - 1 : 0,
-				   exclude, prefix, x->patternlen, x->flags))
-			matched_negative_path = 1;
-	}
-	if (exc &&
-	    !(exc->flags & EXC_FLAG_NEGATIVE) &&
-	    !(exc->flags & EXC_FLAG_NODIR) &&
-	    matched_negative_path)
-		exc = NULL;
+	}
 	return exc;
 }
 
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index da257c0..3fc484e 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -305,29 +305,4 @@ test_expect_success 'ls-files with "**" patterns and no slashes' '
 	test_cmp expect actual
 '
 
-test_expect_success 'negative patterns' '
-	git init reinclude &&
-	(
-		cd reinclude &&
-		cat >.gitignore <<-\EOF &&
-		/fooo
-		/foo
-		!foo/bar/bar
-		EOF
-		mkdir fooo &&
-		cat >fooo/.gitignore <<-\EOF &&
-		!/*
-		EOF
-		mkdir -p foo/bar &&
-		touch abc foo/def foo/bar/ghi foo/bar/bar &&
-		git ls-files -o --exclude-standard >../actual &&
-		cat >../expected <<-\EOF &&
-		.gitignore
-		abc
-		foo/bar/bar
-		EOF
-		test_cmp ../expected ../actual
-	)
-'
-
 test_done
-- 
2.7.0.56.g46bc327

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Revert "dir.c: don't exclude whole dir prematurely if neg pattern may match"
  2016-01-08 12:05 [PATCH] Revert "dir.c: don't exclude whole dir prematurely if neg pattern may match" Nguyễn Thái Ngọc Duy
@ 2016-01-08 12:12 ` Duy Nguyen
  2016-01-08 19:52   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Duy Nguyen @ 2016-01-08 12:12 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

On Fri, Jan 8, 2016 at 7:05 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
> patterns are too loose. The untracked listing and sparse-checkout
> selection can become incorrect as a result.

These two lines should be this instead if you want to keep track of
problem references. I amended the commit then forgot to format-patch
again.

patterns are too loose. The untracked listing [1] and sparse-checkout
selection [2] can become incorrect as a result.

[1] http://article.gmane.org/gmane.comp.version-control.git/283520
[2] http://article.gmane.org/gmane.comp.version-control.git/283532
-- 
Duy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Revert "dir.c: don't exclude whole dir prematurely if neg pattern may match"
  2016-01-08 12:12 ` Duy Nguyen
@ 2016-01-08 19:52   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2016-01-08 19:52 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List

Duy Nguyen <pclouds@gmail.com> writes:

> On Fri, Jan 8, 2016 at 7:05 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:
>> patterns are too loose. The untracked listing and sparse-checkout
>> selection can become incorrect as a result.
>
> These two lines should be this instead if you want to keep track of
> problem references. I amended the commit then forgot to format-patch
> again.
>
> patterns are too loose. The untracked listing [1] and sparse-checkout
> selection [2] can become incorrect as a result.
>
> [1] http://article.gmane.org/gmane.comp.version-control.git/283520
> [2] http://article.gmane.org/gmane.comp.version-control.git/283532

Thanks.  I guess we need a 2.7.1 relatively soon now.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-01-08 19:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-08 12:05 [PATCH] Revert "dir.c: don't exclude whole dir prematurely if neg pattern may match" Nguyễn Thái Ngọc Duy
2016-01-08 12:12 ` Duy Nguyen
2016-01-08 19:52   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox