{"thread":{"id":"45080","subject":"[PATCH 1/2] pathspec magic: add '^' as alias for '!'","startedAt":"2017-02-08T05:13:41Z","lastAt":"2017-02-09T00:19:19Z","messageCount":5,"participants":["Linus Torvalds","Cornelius Weig","Brandon Williams","Junio C Hamano","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"311033","messageId":"alpine.LFD.2.20.1702072113040.25002@i7.lan","threadId":"45080","inReplyTo":null,"subject":"[PATCH 1/2] pathspec magic: add '^' as alias for '!'","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2017-02-08T05:13:32Z","receivedAt":"2017-02-08T05:13:41Z","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:05:28 -0800\nSubject: [PATCH 1/2] pathspec magic: add '^' as alias for '!'\n\nThe choice of '!' for a negative pathspec ends up not only not matching\nwhat we do for revisions, it's also a horrible character for shell\nexpansion since it needs quoting.\n\nSo add '^' as an alternative alias for an excluding pathspec entry.\n\nSigned-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n---\n pathspec.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/pathspec.c b/pathspec.c\nindex 7ababb315..ecad03406 100644\n--- a/pathspec.c\n+++ b/pathspec.c\n@@ -224,6 +224,12 @@ static const char *parse_short_magic(unsigned *magic, const char *elem)\n \t\tchar ch = *pos;\n \t\tint i;\n \n+\t\t/* Special case alias for '!' */\n+\t\tif (ch == '^') {\n+\t\t\t*magic |= PATHSPEC_EXCLUDE;\n+\t\t\tcontinue;\n+\t\t}\n+\n \t\tif (!is_pathspec_magic(ch))\n \t\t\tbreak;\n \n-- \n2.12.0.rc0.1.g02555c1b2.dirty\n\n"},{"id":"311060","messageId":"72ce071a-064d-5123-3248-d8486843c767@tngtech.com","threadId":"45080","inReplyTo":"alpine.LFD.2.20.1702072113040.25002@i7.lan","subject":"Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'","fromName":"Cornelius Weig","fromEmail":"cornelius.weig@tngtech.com","sentAt":"2017-02-08T13:23:00Z","receivedAt":"2017-02-08T14:18:50Z","isPatch":true,"sender":{"key":"cornelius.weig@tngtech.com","avatar":null},"body":"As Duy pointed out, the glossary needs an update too.\n\nFor this one, the cange can be minimal I think:\n\ndiff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt\nindex 8ad29e6..f127fe9 100644\n--- a/Documentation/glossary-content.txt\n+++ b/Documentation/glossary-content.txt\n@@ -386,7 +386,7 @@ Glob magic is incompatible with literal magic.\n \n exclude;;\n        After a path matches any non-exclude pathspec, it will be run\n-       through all exclude pathspec (magic signature: `!`). If it\n+       through all exclude pathspec (magic signature: `!` or `^`). If it\n        matches, the path is ignored.\n --\n \n"},{"id":"311112","messageId":"20170208223532.GB108686@google.com","threadId":"45080","inReplyTo":"alpine.LFD.2.20.1702072113040.25002@i7.lan","subject":"Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-02-08T22:35:32Z","receivedAt":"2017-02-08T22:37:30Z","isPatch":true,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 02/07, Linus Torvalds wrote:\n> \n> From: Linus Torvalds <torvalds@linux-foundation.org>\n> Date: Tue, 7 Feb 2017 21:05:28 -0800\n> Subject: [PATCH 1/2] pathspec magic: add '^' as alias for '!'\n> \n> The choice of '!' for a negative pathspec ends up not only not matching\n> what we do for revisions, it's also a horrible character for shell\n> expansion since it needs quoting.\n> \n> So add '^' as an alternative alias for an excluding pathspec entry.\n> \n> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>\n> ---\n>  pathspec.c | 6 ++++++\n>  1 file changed, 6 insertions(+)\n> \n> diff --git a/pathspec.c b/pathspec.c\n> index 7ababb315..ecad03406 100644\n> --- a/pathspec.c\n> +++ b/pathspec.c\n> @@ -224,6 +224,12 @@ static const char *parse_short_magic(unsigned *magic, const char *elem)\n>  \t\tchar ch = *pos;\n>  \t\tint i;\n>  \n> +\t\t/* Special case alias for '!' */\n> +\t\tif (ch == '^') {\n> +\t\t\t*magic |= PATHSPEC_EXCLUDE;\n> +\t\t\tcontinue;\n> +\t\t}\n> +\n>  \t\tif (!is_pathspec_magic(ch))\n>  \t\t\tbreak;\n\nI like adding '^' to be an alias for excluding patterns.  There have\nbeen numerous times where I have wanted to use exclude patterns and\nforgotten that I've needed to do some escape magic to get my shell to\nleave '!' alone.\n\nThe only issue I see with doing this is that if a user supplies an\nexclude pattern for a command which doesn't support exclude pathspec\nmagic the unsupported_magic() function will have slightly cryptic\noutput.\n\ngit cmd -- :^dir\n\nwould produce some output which says:\n':^dir': pathspec magic not supported by this command: 'exclude' (mnemonic: '!')\n\nAnd the user may scratch their head for a second since they didn't\nsupply the '!' character, but rather '^'.  That being said I think it\nshould be fine since the long name of the magic is also printed so the\nuser should be able to figure out what's wrong.  I also don't think\nthere are any users of pathspecs which disallow exclude magic so this\nmay not even be an issue.\n\n-- \nBrandon Williams\n"},{"id":"311118","messageId":"xmqq37fouvu3.fsf@gitster.mtv.corp.google.com","threadId":"45080","inReplyTo":"20170208223532.GB108686@google.com","subject":"Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-08T23:05:56Z","receivedAt":"2017-02-08T23:13:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brandon Williams <bmwill@google.com> writes:\n\n> git cmd -- :^dir\n>\n> would produce some output which says:\n> ':^dir': pathspec magic not supported by this command: 'exclude' (mnemonic: '!')\n>\n> And the user may scratch their head for a second since they didn't\n> supply the '!' character, but rather '^'.\n\nYup, I am tempted to tweak Cornelius's glossary fixup and squash\nthis into the series, for two purposes.\n\n - it makes it clear that '^' and '!' mean the same thing (and\n   clearer than Cornelius's original, \"! or ^\", which could leave\n   the reader wondering \"ok there are two ways to say negative; do\n   they subtly mean different things?\").\n\n - it hints that '!' is the more official spelling, making the\n   output you showed above acceptable.\n\ndiff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt\nindex 8ad29e61a9..822ca83264 100644\n--- a/Documentation/glossary-content.txt\n+++ b/Documentation/glossary-content.txt\n@@ -386,8 +386,8 @@ Glob magic is incompatible with literal magic.\n \n exclude;;\n \tAfter a path matches any non-exclude pathspec, it will be run\n-\tthrough all exclude pathspec (magic signature: `!`). If it\n-\tmatches, the path is ignored.\n+\tthrough all exclude pathspec (magic signature: `!` or its\n+\tsynonym `^`). If it matches, the path is ignored.\n --\n \n [[def_parent]]parent::\n"},{"id":"311130","messageId":"CAGZ79kaGtsaAKbjaX1b+fS_pqAZPsoFLHjf9CpwffP7uBV4R3g@mail.gmail.com","threadId":"45080","inReplyTo":"xmqq37fouvu3.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-02-08T23:16:36Z","receivedAt":"2017-02-09T00:19:19Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Feb 8, 2017 at 3:05 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>  - it hints that '!' is the more official spelling, making the\n>    output you showed above acceptable.\n\nLong term , I'd rather have ^ as the \"official\" spelling as that is easier\nto teach to people. ! being a historic mistake as it is hard to type?\n"}]}