{"thread":{"id":"41150","subject":"[PATCH] Revert \"dir.c: don't exclude whole dir prematurely if neg pattern may match\"","startedAt":"2016-01-08T12:05:25Z","lastAt":"2016-01-08T19:52:57Z","messageCount":3,"participants":["Nguyễn Thái Ngọc Duy","Duy Nguyen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"275543","messageId":"1452254725-22314-1-git-send-email-pclouds@gmail.com","threadId":"41150","inReplyTo":null,"subject":"[PATCH] Revert \"dir.c: don't exclude whole dir prematurely if neg pattern may match\"","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2016-01-08T12:05:25Z","receivedAt":"2016-01-08T12:05:25Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This reverts commit 57534ee77d22e725d971ee89c77dc6aad61c573f. The\nfeature added in that commit requires that patterns behave the same way\nfrom anywhere. But some patterns can behave differently depending on\ncurrent \"working\" directory. The conditions to catch and avoid these\npatterns are too loose. The untracked listing and sparse-checkout\nselection can become incorrect as a result.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/gitignore.txt        | 23 ++----------\n dir.c                              | 76 +-------------------------------------\n t/t3001-ls-files-others-exclude.sh | 25 -------------\n 3 files changed, 6 insertions(+), 118 deletions(-)\n\ndiff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt\nindex 79a1948..473623d 100644\n--- a/Documentation/gitignore.txt\n+++ b/Documentation/gitignore.txt\n@@ -82,12 +82,12 @@ PATTERN FORMAT\n \n  - An optional prefix \"`!`\" which negates the pattern; any\n    matching file excluded by a previous pattern will become\n-   included again.\n+   included again. It is not possible to re-include a file if a parent\n+   directory of that file is excluded. Git doesn't list excluded\n+   directories for performance reasons, so any patterns on contained\n+   files have no effect, no matter where they are defined.\n    Put a backslash (\"`\\`\") in front of the first \"`!`\" for patterns\n    that begin with a literal \"`!`\", for example, \"`\\!important!.txt`\".\n-   It is possible to re-include a file if a parent directory of that\n-   file is excluded if certain conditions are met. See section NOTES\n-   for detail.\n \n  - If the pattern ends with a slash, it is removed for the\n    purpose of the following description, but it would only find\n@@ -141,21 +141,6 @@ not tracked by Git remain untracked.\n To stop tracking a file that is currently tracked, use\n 'git rm --cached'.\n \n-To re-include files or directories when their parent directory is\n-excluded, the following conditions must be met:\n-\n- - The rules to exclude a directory and re-include a subset back must\n-   be in the same .gitignore file.\n-\n- - The directory part in the re-include rules must be literal (i.e. no\n-   wildcards)\n-\n- - The rules to exclude the parent directory must not end with a\n-   trailing slash.\n-\n- - The rules to exclude the parent directory must have at least one\n-   slash.\n-\n EXAMPLES\n --------\n \ndiff --git a/dir.c b/dir.c\nindex d2a8f06..206393a 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -882,25 +882,6 @@ int match_pathname(const char *pathname, int pathlen,\n \t\t */\n \t\tif (!patternlen && !namelen)\n \t\t\treturn 1;\n-\t\t/*\n-\t\t * This can happen when we ignore some exclude rules\n-\t\t * on directories in other to see if negative rules\n-\t\t * may match. E.g.\n-\t\t *\n-\t\t * /abc\n-\t\t * !/abc/def/ghi\n-\t\t *\n-\t\t * The pattern of interest is \"/abc\". On the first\n-\t\t * try, we should match path \"abc\" with this pattern\n-\t\t * in the \"if\" statement right above, but the caller\n-\t\t * ignores it.\n-\t\t *\n-\t\t * On the second try with paths within \"abc\",\n-\t\t * e.g. \"abc/xyz\", we come here and try to match it\n-\t\t * with \"/abc\".\n-\t\t */\n-\t\tif (!patternlen && namelen && *name == '/')\n-\t\t\treturn 1;\n \t}\n \n \treturn fnmatch_icase_mem(pattern, patternlen,\n@@ -909,48 +890,6 @@ int match_pathname(const char *pathname, int pathlen,\n }\n \n /*\n- * Return non-zero if pathname is a directory and an ancestor of the\n- * literal path in a (negative) pattern. This is used to keep\n- * descending in \"foo\" and \"foo/bar\" when the pattern is\n- * \"!foo/bar/.gitignore\". \"foo/notbar\" will not be descended however.\n- */\n-static int match_neg_path(const char *pathname, int pathlen, int *dtype,\n-\t\t\t  const char *base, int baselen,\n-\t\t\t  const char *pattern, int prefix, int patternlen,\n-\t\t\t  int flags)\n-{\n-\tassert((flags & EXC_FLAG_NEGATIVE) && !(flags & EXC_FLAG_NODIR));\n-\n-\tif (*dtype == DT_UNKNOWN)\n-\t\t*dtype = get_dtype(NULL, pathname, pathlen);\n-\tif (*dtype != DT_DIR)\n-\t\treturn 0;\n-\n-\tif (*pattern == '/') {\n-\t\tpattern++;\n-\t\tpatternlen--;\n-\t\tprefix--;\n-\t}\n-\n-\tif (baselen) {\n-\t\tif (((pathlen < baselen && base[pathlen] == '/') ||\n-\t\t     pathlen == baselen) &&\n-\t\t    !strncmp_icase(pathname, base, pathlen))\n-\t\t\treturn 1;\n-\t\tpathname += baselen + 1;\n-\t\tpathlen  -= baselen + 1;\n-\t}\n-\n-\n-\tif (prefix &&\n-\t    ((pathlen < prefix && pattern[pathlen] == '/') &&\n-\t     !strncmp_icase(pathname, pattern, pathlen)))\n-\t\treturn 1;\n-\n-\treturn 0;\n-}\n-\n-/*\n  * Scan the given exclude list in reverse to see whether pathname\n  * should be ignored.  The first match (i.e. the last on the list), if\n  * any, determines the fate.  Returns the exclude_list element which\n@@ -963,7 +902,7 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,\n \t\t\t\t\t\t       struct exclude_list *el)\n {\n \tstruct exclude *exc = NULL; /* undecided */\n-\tint i, matched_negative_path = 0;\n+\tint i;\n \n \tif (!el->nr)\n \t\treturn NULL;\t/* undefined */\n@@ -998,18 +937,7 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname,\n \t\t\texc = x;\n \t\t\tbreak;\n \t\t}\n-\n-\t\tif ((x->flags & EXC_FLAG_NEGATIVE) && !matched_negative_path &&\n-\t\t    match_neg_path(pathname, pathlen, dtype, x->base,\n-\t\t\t\t   x->baselen ? x->baselen - 1 : 0,\n-\t\t\t\t   exclude, prefix, x->patternlen, x->flags))\n-\t\t\tmatched_negative_path = 1;\n-\t}\n-\tif (exc &&\n-\t    !(exc->flags & EXC_FLAG_NEGATIVE) &&\n-\t    !(exc->flags & EXC_FLAG_NODIR) &&\n-\t    matched_negative_path)\n-\t\texc = NULL;\n+\t}\n \treturn exc;\n }\n \ndiff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh\nindex da257c0..3fc484e 100755\n--- a/t/t3001-ls-files-others-exclude.sh\n+++ b/t/t3001-ls-files-others-exclude.sh\n@@ -305,29 +305,4 @@ test_expect_success 'ls-files with \"**\" patterns and no slashes' '\n \ttest_cmp expect actual\n '\n \n-test_expect_success 'negative patterns' '\n-\tgit init reinclude &&\n-\t(\n-\t\tcd reinclude &&\n-\t\tcat >.gitignore <<-\\EOF &&\n-\t\t/fooo\n-\t\t/foo\n-\t\t!foo/bar/bar\n-\t\tEOF\n-\t\tmkdir fooo &&\n-\t\tcat >fooo/.gitignore <<-\\EOF &&\n-\t\t!/*\n-\t\tEOF\n-\t\tmkdir -p foo/bar &&\n-\t\ttouch abc foo/def foo/bar/ghi foo/bar/bar &&\n-\t\tgit ls-files -o --exclude-standard >../actual &&\n-\t\tcat >../expected <<-\\EOF &&\n-\t\t.gitignore\n-\t\tabc\n-\t\tfoo/bar/bar\n-\t\tEOF\n-\t\ttest_cmp ../expected ../actual\n-\t)\n-'\n-\n test_done\n-- \n2.7.0.56.g46bc327\n"},{"id":"275545","messageId":"CACsJy8Bg+xnKxkq8-Da4-GKUWAOjGB6xyya+zzydhMWBEPPT8g@mail.gmail.com","threadId":"41150","inReplyTo":"1452254725-22314-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] Revert \"dir.c: don't exclude whole dir prematurely if neg pattern may match\"","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2016-01-08T12:12:30Z","receivedAt":"2016-01-08T12:12:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Jan 8, 2016 at 7:05 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> patterns are too loose. The untracked listing and sparse-checkout\n> selection can become incorrect as a result.\n\nThese two lines should be this instead if you want to keep track of\nproblem references. I amended the commit then forgot to format-patch\nagain.\n\npatterns are too loose. The untracked listing [1] and sparse-checkout\nselection [2] can become incorrect as a result.\n\n[1] http://article.gmane.org/gmane.comp.version-control.git/283520\n[2] http://article.gmane.org/gmane.comp.version-control.git/283532\n-- \nDuy\n"},{"id":"275573","messageId":"xmqqlh7z26hy.fsf@gitster.mtv.corp.google.com","threadId":"41150","inReplyTo":"CACsJy8Bg+xnKxkq8-Da4-GKUWAOjGB6xyya+zzydhMWBEPPT8g@mail.gmail.com","subject":"Re: [PATCH] Revert \"dir.c: don't exclude whole dir prematurely if neg pattern may match\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-08T19:52:57Z","receivedAt":"2016-01-08T19:52:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Duy Nguyen <pclouds@gmail.com> writes:\n\n> On Fri, Jan 8, 2016 at 7:05 PM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n>> patterns are too loose. The untracked listing and sparse-checkout\n>> selection can become incorrect as a result.\n>\n> These two lines should be this instead if you want to keep track of\n> problem references. I amended the commit then forgot to format-patch\n> again.\n>\n> patterns are too loose. The untracked listing [1] and sparse-checkout\n> selection [2] can become incorrect as a result.\n>\n> [1] http://article.gmane.org/gmane.comp.version-control.git/283520\n> [2] http://article.gmane.org/gmane.comp.version-control.git/283532\n\nThanks.  I guess we need a 2.7.1 relatively soon now.\n"}]}