git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] pathspec magic: add '^' as alias for '!'

From
BWBrandon Williams <bmwill@google.com>
Date
Feb 8, 2017, 22:35 UTC
Message-ID
<20170208223532.GB108686@google.com>
In-Reply-To
<alpine.LFD.2.20.1702072113040.25002@i7.lan>
On 02/07, Linus Torvalds wrote:
Show 32 quoted lines
> 
> 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
Previous: Cornelius WeigNext: Junio C Hamano
Message 3 of 5 in “pathspec magic: add '^' as alias for '!'”
  1. 1/2 pathspec magic: add '^' as alias for '!'Linus Torvalds, Feb 8, 2017
  2. Cornelius WeigFeb 8, 2017
  3. Brandon WilliamsFeb 8, 2017
  4. Junio C HamanoFeb 8, 2017
  5. Stefan BellerFeb 8, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.