{"thread":{"id":"45081","subject":"[PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns","startedAt":"2017-02-08T05:14:48Z","lastAt":"2017-02-08T22:24:44Z","messageCount":4,"participants":["Linus Torvalds","Cornelius Weig","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"311035","messageId":"alpine.LFD.2.20.1702072113380.25002@i7.lan","threadId":"45081","inReplyTo":null,"subject":"[PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2017-02-08T05:14:40Z","receivedAt":"2017-02-08T05:14:48Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nFrom: Linus Torvalds <torvalds@linux-foundation.org>\nDate: Tue, 7 Feb 2017 21:08:15 -0800\nSubject: [PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns\n\nInstead of erroring out and telling the user that they should add a \npositive pattern that covers everything else, just _do_ that.\n\nFor commands where we honor the current cwd by default (ie grep, ls-files \netc), we make that default positive pathspec be the current working \ndirectory.  And for commands that default to the whole project (ie diff, \nlog, etc), the default positive pathspec is the whole project.\n\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n---\n pathspec.c | 16 +++++++++++-----\n 1 file changed, 11 insertions(+), 5 deletions(-)\n\ndiff --git a/pathspec.c b/pathspec.c\nindex ecad03406..d8f78088c 100644\n--- a/pathspec.c\n+++ b/pathspec.c\n@@ -522,7 +522,7 @@ void parse_pathspec(struct pathspec *pathspec,\n \t}\n \n \tpathspec->nr = n;\n-\tALLOC_ARRAY(pathspec->items, n);\n+\tALLOC_ARRAY(pathspec->items, n+1);\n \titem = pathspec->items;\n \tprefixlen = prefix ? strlen(prefix) : 0;\n \n@@ -546,10 +546,16 @@ void parse_pathspec(struct pathspec *pathspec,\n \t\tpathspec->magic |= item[i].magic;\n \t}\n \n-\tif (nr_exclude == n)\n-\t\tdie(_(\"There is nothing to exclude from by :(exclude) patterns.\\n\"\n-\t\t      \"Perhaps you forgot to add either ':/' or '.' ?\"));\n-\n+\t/*\n+\t * If everything is an exclude pattern, add one positive pattern\n+\t * that matches everyting. We allocated an extra one for this.\n+\t */\n+\tif (nr_exclude == n) {\n+\t\tif (!(flags & PATHSPEC_PREFER_CWD))\n+\t\t\tprefixlen = 0;\n+\t\tinit_pathspec_item(item + n, 0, prefix, prefixlen, \"\");\n+\t\tpathspec->nr++;\n+\t}\n \n \tif (pathspec->magic & PATHSPEC_MAXDEPTH) {\n \t\tif (flags & PATHSPEC_KEEP_ORDER)\n-- \n2.12.0.rc0.1.g02555c1b2.dirty\n\n"},{"id":"311059","messageId":"35bd1d35-4cb8-cf40-38ee-7442efc0f139@tngtech.com","threadId":"45081","inReplyTo":"alpine.LFD.2.20.1702072113380.25002@i7.lan","subject":"Re: [PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns","fromName":"Cornelius Weig","fromEmail":"cornelius.weig@tngtech.com","sentAt":"2017-02-08T13:23:08Z","receivedAt":"2017-02-08T14:18:15Z","isPatch":true,"sender":{"key":"cornelius.weig@tngtech.com","avatar":null},"body":"Again, as Duy pointed out this should be documented.\n\nHow about something like this:\n\ndiff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt\nindex f127fe9..781cde3 100644\n--- a/Documentation/glossary-content.txt\n+++ b/Documentation/glossary-content.txt\n@@ -387,7 +387,9 @@ Glob magic is incompatible with literal magic.\n exclude;;\n        After a path matches any non-exclude pathspec, it will be run\n        through all exclude pathspec (magic signature: `!` or `^`). If it\n-       matches, the path is ignored.\n+       matches, the path is ignored. If only exclude pathspec are given,\n+       the exclusion is applied to the result set as if invoked without any\n+       pathspec.\n --\n \n [[def_parent]]parent::\n"},{"id":"311107","messageId":"xmqqk290uywp.fsf@gitster.mtv.corp.google.com","threadId":"45081","inReplyTo":"alpine.LFD.2.20.1702072113380.25002@i7.lan","subject":"Re: [PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-08T21:59:34Z","receivedAt":"2017-02-08T22:08:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Torvalds <torvalds@linux-foundation.org> writes:\n\n> @@ -546,10 +546,16 @@ void parse_pathspec(struct pathspec *pathspec,\n>  \t\tpathspec->magic |= item[i].magic;\n>  \t}\n>  \n> -\tif (nr_exclude == n)\n> -\t\tdie(_(\"There is nothing to exclude from by :(exclude) patterns.\\n\"\n> -\t\t      \"Perhaps you forgot to add either ':/' or '.' ?\"));\n> -\n> +\t/*\n> +\t * If everything is an exclude pattern, add one positive pattern\n> +\t * that matches everyting. We allocated an extra one for this.\n> +\t */\n> +\tif (nr_exclude == n) {\n> +\t\tif (!(flags & PATHSPEC_PREFER_CWD))\n> +\t\t\tprefixlen = 0;\n> +\t\tinit_pathspec_item(item + n, 0, prefix, prefixlen, \"\");\n> +\t\tpathspec->nr++;\n> +\t}\n>  \n>  \tif (pathspec->magic & PATHSPEC_MAXDEPTH) {\n>  \t\tif (flags & PATHSPEC_KEEP_ORDER)\n\nThanks.  Even though the current code does not refer to the original\nprefixlen after the added hunk, I'd prefer not to destroy it to\navoid future troubles, so I'll queue with a bit of tweak there,\nperhaps like the attached.\n\nAlso this has an obvious fallout to the tests, whose (minimum) fix\nis rather trivial.\n\nThanks.\n\n pathspec.c                  | 7 +++----\n t/t6132-pathspec-exclude.sh | 6 ++++--\n 2 files changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/pathspec.c b/pathspec.c\nindex d8f78088c8..b961f00c8c 100644\n--- a/pathspec.c\n+++ b/pathspec.c\n@@ -522,7 +522,7 @@ void parse_pathspec(struct pathspec *pathspec,\n \t}\n \n \tpathspec->nr = n;\n-\tALLOC_ARRAY(pathspec->items, n+1);\n+\tALLOC_ARRAY(pathspec->items, n + 1);\n \titem = pathspec->items;\n \tprefixlen = prefix ? strlen(prefix) : 0;\n \n@@ -551,9 +551,8 @@ void parse_pathspec(struct pathspec *pathspec,\n \t * that matches everyting. We allocated an extra one for this.\n \t */\n \tif (nr_exclude == n) {\n-\t\tif (!(flags & PATHSPEC_PREFER_CWD))\n-\t\t\tprefixlen = 0;\n-\t\tinit_pathspec_item(item + n, 0, prefix, prefixlen, \"\");\n+\t\tint plen = (!(flags & PATHSPEC_PREFER_CWD)) ? 0 : prefixlen;\n+\t\tinit_pathspec_item(item + n, 0, prefix, plen, \"\");\n \t\tpathspec->nr++;\n \t}\n \ndiff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh\nindex d51595cf6b..9dd5cde5fc 100755\n--- a/t/t6132-pathspec-exclude.sh\n+++ b/t/t6132-pathspec-exclude.sh\n@@ -25,8 +25,10 @@ EOF\n \ttest_cmp expect actual\n '\n \n-test_expect_success 'exclude only should error out' '\n-\ttest_must_fail git log --oneline --format=%s -- \":(exclude)sub\"\n+test_expect_success 'exclude only no longer errors out' '\n+\tgit log --oneline --format=%s -- . \":(exclude)sub\" >expect &&\n+\tgit log --oneline --format=%s -- \":(exclude)sub\" >actual &&\n+\ttest_cmp expect actual\n '\n \n test_expect_success 't_e_i() exclude sub' '\n"},{"id":"311110","messageId":"CA+55aFycVda9LYtLuG-oBci1Q2-7TVx3jv0HRZzSP0gQsWvXjw@mail.gmail.com","threadId":"45081","inReplyTo":"xmqqk290uywp.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH 2/2] pathspec: don't error out on all-exclusionary pathspec patterns","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2017-02-08T22:16:50Z","receivedAt":"2017-02-08T22:24:44Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"On Wed, Feb 8, 2017 at 1:59 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Thanks.  Even though the current code does not refer to the original\n> prefixlen after the added hunk, I'd prefer not to destroy it to\n> avoid future troubles, so I'll queue with a bit of tweak there,\n> perhaps like the attached.\n\nYeah, I considered that. Along with just passing in a NULL prefix\nstring too for that case. Not that it matters.\n\nSo ack on that change,\n\n             Linus\n"}]}