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

Re: [PATCH/RFC] attr: allow pattern escape using backslash

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 6, 2012, 07:54 UTC
Message-ID
<7vzk40qbm1.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1349508125-24775-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 29 quoted lines
> .gitattributes pattern syntax is supposed to be the same as .gitignore
> (except a few things that do not make sense in attr context, but
> that's a different issue). .gitignore uses fnmatch() as the matching
> machinery and "\" is accepted as an escape code. In theory the pattern
> 'foo\ bar' should match path 'foo bar' in .gitignore. Granted, no one
> would write 'foo\ bar' in .gitignore when 'foo bar' should
> suffice.
>
> Regardless, 'foo\ bar attr' does not (but should) attach "attr" to
> path "foo bar" because pattern/attr parse code does not understand
> backslash escape. It parses the line as path 'foo\' and attributes
> 'bar' and 'attr'. This patch teaches attr code to recognize the
> backslash in patterns (not macro names) and pass 'foo\ bar' down to
> fnmatch().
>
> This changes the attr behavior. "foo\ attr", if exists in the field,
> would match nothing because path "foo\" is invalid in UNIX and is a
> directory in Windows, which we do not accept attaching attributes
> to. With this patch, that line becomes invalid and is rejected. So
> it's not really bad (i.e. no silent changes in behavior).
>
> Other subtle behavioral changes may happen. Still, I think we should
> do this as it seems like a correct thing to do.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  We discussed the "spaces in path names in attr" before and I remember
>  using quotes or double quotes, even substituting spaces with
>  dots, were raised. I don't remember if backslashes were mentioned.

My knee-jerk reaction, without thinking things through, is that this makes sense and doing the same for .gitignore would, too (even though the one-item-per-line nature of .gitignore makes "\ " and " " practically equivalent).

Shouldn't we do the same for quoting fnmatch(3) metacharacters? To match a path component 'a' followed by an asterisk followed by 'b', you could then write 'a\*b'. Same for quoting the backslash itself.

Previous: Nguyễn Thái Ngọc DuyNext: Nguyen Thai Ngoc Duy
Message 2 of 3 in “attr: allow pattern escape using backslash”
  1. attr: allow pattern escape using backslashNguyễn Thái Ngọc Duy, Oct 6, 2012
  2. Junio C HamanoOct 6, 2012
  3. Nguyen Thai Ngoc DuyOct 6, 2012

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.