git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* [PATCH 1/2] pathspec magic: add '^' as alias for '!'
@ 2017-02-08  5:13 Linus Torvalds
  2017-02-08 13:23 ` Cornelius Weig
  2017-02-08 22:35 ` Brandon Williams
  0 siblings, 2 replies; 5+ messages in thread
From: Linus Torvalds @ 2017-02-08  5:13 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List


From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Tue, 7 Feb 2017 21:05:28 -0800
Subject: [PATCH 1/2] pathspec magic: add '^' as alias for '!'

The choice of '!' for a negative pathspec ends up not only not matching
what we do for revisions, it's also a horrible character for shell
expansion since it needs quoting.

So add '^' as an alternative alias for an excluding pathspec entry.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 pathspec.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/pathspec.c b/pathspec.c
index 7ababb315..ecad03406 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -224,6 +224,12 @@ static const char *parse_short_magic(unsigned *magic, const char *elem)
 		char ch = *pos;
 		int i;
 
+		/* Special case alias for '!' */
+		if (ch == '^') {
+			*magic |= PATHSPEC_EXCLUDE;
+			continue;
+		}
+
 		if (!is_pathspec_magic(ch))
 			break;
 
-- 
2.12.0.rc0.1.g02555c1b2.dirty


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

* Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'
  2017-02-08  5:13 [PATCH 1/2] pathspec magic: add '^' as alias for '!' Linus Torvalds
@ 2017-02-08 13:23 ` Cornelius Weig
  2017-02-08 22:35 ` Brandon Williams
  1 sibling, 0 replies; 5+ messages in thread
From: Cornelius Weig @ 2017-02-08 13:23 UTC (permalink / raw)
  To: Linus Torvalds, Junio C Hamano; +Cc: Git Mailing List

As Duy pointed out, the glossary needs an update too.

For this one, the cange can be minimal I think:

diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 8ad29e6..f127fe9 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -386,7 +386,7 @@ Glob magic is incompatible with literal magic.
 
 exclude;;
        After a path matches any non-exclude pathspec, it will be run
-       through all exclude pathspec (magic signature: `!`). If it
+       through all exclude pathspec (magic signature: `!` or `^`). If it
        matches, the path is ignored.
 --
 

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

* Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'
  2017-02-08  5:13 [PATCH 1/2] pathspec magic: add '^' as alias for '!' Linus Torvalds
  2017-02-08 13:23 ` Cornelius Weig
@ 2017-02-08 22:35 ` Brandon Williams
  2017-02-08 23:05   ` Junio C Hamano
  1 sibling, 1 reply; 5+ messages in thread
From: Brandon Williams @ 2017-02-08 22:35 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Junio C Hamano, Git Mailing List

On 02/07, Linus Torvalds wrote:
> 
> From: Linus Torvalds <torvalds@linux-foundation.org>
> Date: Tue, 7 Feb 2017 21:05:28 -0800
> Subject: [PATCH 1/2] pathspec magic: add '^' as alias for '!'
> 
> The choice of '!' for a negative pathspec ends up not only not matching
> what we do for revisions, it's also a horrible character for shell
> expansion since it needs quoting.
> 
> So add '^' as an alternative alias for an excluding pathspec entry.
> 
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> ---
>  pathspec.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/pathspec.c b/pathspec.c
> index 7ababb315..ecad03406 100644
> --- a/pathspec.c
> +++ b/pathspec.c
> @@ -224,6 +224,12 @@ static const char *parse_short_magic(unsigned *magic, const char *elem)
>  		char ch = *pos;
>  		int i;
>  
> +		/* Special case alias for '!' */
> +		if (ch == '^') {
> +			*magic |= PATHSPEC_EXCLUDE;
> +			continue;
> +		}
> +
>  		if (!is_pathspec_magic(ch))
>  			break;

I like adding '^' to be an alias for excluding patterns.  There have
been numerous times where I have wanted to use exclude patterns and
forgotten that I've needed to do some escape magic to get my shell to
leave '!' alone.

The only issue I see with doing this is that if a user supplies an
exclude pattern for a command which doesn't support exclude pathspec
magic the unsupported_magic() function will have slightly cryptic
output.

git cmd -- :^dir

would produce some output which says:
':^dir': pathspec magic not supported by this command: 'exclude' (mnemonic: '!')

And the user may scratch their head for a second since they didn't
supply the '!' character, but rather '^'.  That being said I think it
should be fine since the long name of the magic is also printed so the
user should be able to figure out what's wrong.  I also don't think
there are any users of pathspecs which disallow exclude magic so this
may not even be an issue.

-- 
Brandon Williams

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

* Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'
  2017-02-08 22:35 ` Brandon Williams
@ 2017-02-08 23:05   ` Junio C Hamano
  2017-02-08 23:16     ` Stefan Beller
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2017-02-08 23:05 UTC (permalink / raw)
  To: Brandon Williams; +Cc: Linus Torvalds, Git Mailing List

Brandon Williams <bmwill@google.com> writes:

> git cmd -- :^dir
>
> would produce some output which says:
> ':^dir': pathspec magic not supported by this command: 'exclude' (mnemonic: '!')
>
> And the user may scratch their head for a second since they didn't
> supply the '!' character, but rather '^'.

Yup, I am tempted to tweak Cornelius's glossary fixup and squash
this into the series, for two purposes.

 - it makes it clear that '^' and '!' mean the same thing (and
   clearer than Cornelius's original, "! or ^", which could leave
   the reader wondering "ok there are two ways to say negative; do
   they subtly mean different things?").

 - it hints that '!' is the more official spelling, making the
   output you showed above acceptable.

diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt
index 8ad29e61a9..822ca83264 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -386,8 +386,8 @@ Glob magic is incompatible with literal magic.
 
 exclude;;
 	After a path matches any non-exclude pathspec, it will be run
-	through all exclude pathspec (magic signature: `!`). If it
-	matches, the path is ignored.
+	through all exclude pathspec (magic signature: `!` or its
+	synonym `^`). If it matches, the path is ignored.
 --
 
 [[def_parent]]parent::

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

* Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'
  2017-02-08 23:05   ` Junio C Hamano
@ 2017-02-08 23:16     ` Stefan Beller
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Beller @ 2017-02-08 23:16 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Brandon Williams, Linus Torvalds, Git Mailing List

On Wed, Feb 8, 2017 at 3:05 PM, Junio C Hamano <gitster@pobox.com> wrote:
>  - it hints that '!' is the more official spelling, making the
>    output you showed above acceptable.

Long term , I'd rather have ^ as the "official" spelling as that is easier
to teach to people. ! being a historic mistake as it is hard to type?

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08  5:13 [PATCH 1/2] pathspec magic: add '^' as alias for '!' Linus Torvalds
2017-02-08 13:23 ` Cornelius Weig
2017-02-08 22:35 ` Brandon Williams
2017-02-08 23:05   ` Junio C Hamano
2017-02-08 23:16     ` Stefan Beller

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror http://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox