git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Possible bug: Empty magic word list in pathspec is handled differently in short vs. long form
@ 2025-02-19 10:49 Anselm Schüler
  2025-02-19 14:28 ` Lucas Oshiro
  2025-02-19 17:11 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Anselm Schüler @ 2025-02-19 10:49 UTC (permalink / raw)
  To: git

If you run git diff for a pathspec with an empty magic word/symbol list 
in short form (prefixed by ::) and in long form (prefixed by :():), you 
get different results.

Here’s an example use of git that illustrates this:

~☭ mkdir gittest
~☭ y gittest/
~/gittest☭ git init
Initialized empty Git repository in /home/anselmschueler/gittest/.git/
~/gittest (b0)☭ uuidgen >file
~/gittest (b0)☭ git add file && git commit -m "$(read)"
read> initial commit
[b0 (root-commit) cd3bd43] initial commit
  1 file changed, 1 insertion(+)
  create mode 100644 file
~/gittest (b0)☭ uuidgen >file
~/gittest (b0)☭ git diff -- "::file"

file
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

───┐
1: │
───┘
66d18ffa-1128-42a5-8d4e-f9d75eb86b92
9acea2b5-50a6-4f87-ae1a-64019a93e55e
~/gittest (b0)☭ git diff -- ":():file"
~/gittest (b0)☭

Is there a reason for this? I couldn’t find it documented in the git 
glossary <https://git-scm.com/docs/gitglossary>.

I’m running git 2.47.2, built with Nix (nixpkgs commit 2ff53fe) from the 
kernel.org source tarball.

~Anselm Schüler ⚙️


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

* Re: Possible bug: Empty magic word list in pathspec is handled differently in short vs. long form
  2025-02-19 10:49 Possible bug: Empty magic word list in pathspec is handled differently in short vs. long form Anselm Schüler
@ 2025-02-19 14:28 ` Lucas Oshiro
  2025-02-19 17:11 ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Lucas Oshiro @ 2025-02-19 14:28 UTC (permalink / raw)
  To: Anselm Schüler; +Cc: git


> If you run git diff for a pathspec with an empty magic word/symbol list in short form (prefixed by ::) and in long form (prefixed by :():), you get different results.
> 

From the gitglossary, pathspec section:

"""
In the short form, the leading colon `:` is followed by zero or more
"magic signature" letters (which optionally is terminated by another colon
:), and the remainder is the pattern to match against the path.
"""

and:

"""
In the long form, the leading colon : is followed by an open
parenthesis `(`, a comma-separated list of zero or more "magic words", and
a close parentheses `)` , and the remainder is the pattern to match against
the path. 
"""

Note that the long form doesn't mention that a second colon has the same
meaning as in the short form. In the short form, the second colon is
optionally used to separate the magic signatures from the file pattern. It
wouldn't be necessary in the long form, as the close parentheses acts just
like that.

This way, "::" and ":():" doesn't have the same meaning, just like, for
example, ":(exclude):" doesn't mean ":!" (but ":(exclude)" does).

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

* Re: Possible bug: Empty magic word list in pathspec is handled differently in short vs. long form
  2025-02-19 10:49 Possible bug: Empty magic word list in pathspec is handled differently in short vs. long form Anselm Schüler
  2025-02-19 14:28 ` Lucas Oshiro
@ 2025-02-19 17:11 ` Junio C Hamano
  2025-02-24 14:11   ` Anselm Schüler
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2025-02-19 17:11 UTC (permalink / raw)
  To: Anselm Schüler; +Cc: git

Anselm Schüler <mail@anselmschueler.com> writes:

> If you run git diff for a pathspec with an empty magic word/symbol
> list in short form (prefixed by ::) and in long form (prefixed by
> :():), you get different results.

The short form is prefixed by a ":" and optionally ends by a ":",
but the optional termination may not be required when there is no
ambiguity (e.g. ":/!path" is "from the top, not matching "path", as
"p" cannot be a magic signature; ":/:!path" is "from the top,
matching "!path", as the set of magic signatures ends with the
second disambiguating colon).

The long form is prefixed by a ":(" and ends by a ")".


> Here’s an example use of git that illustrates this:
>
> ~☭ mkdir gittest
> ~☭ y gittest/
> ~/gittest☭ git init
> Initialized empty Git repository in /home/anselmschueler/gittest/.git/
> ~/gittest (b0)☭ uuidgen >file
> ~/gittest (b0)☭ git add file && git commit -m "$(read)"
> read> initial commit
> [b0 (root-commit) cd3bd43] initial commit
>  1 file changed, 1 insertion(+)
>  create mode 100644 file
> ~/gittest (b0)☭ uuidgen >file
> ~/gittest (b0)☭ git diff -- "::file"
>
> file
> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>
> ───┐
> 1: │
> ───┘
> 66d18ffa-1128-42a5-8d4e-f9d75eb86b92
> 9acea2b5-50a6-4f87-ae1a-64019a93e55e
> ~/gittest (b0)☭ git diff -- ":():file"
> ~/gittest (b0)☭

Doesn't ":():file" ask for a match for the pattern ":file", with a
leading colon?

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

* Re: Possible bug: Empty magic word list in pathspec is handled differently in short vs. long form
  2025-02-19 17:11 ` Junio C Hamano
@ 2025-02-24 14:11   ` Anselm Schüler
  0 siblings, 0 replies; 4+ messages in thread
From: Anselm Schüler @ 2025-02-24 14:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Thank you and Lucas Oshiro <lucasseikioshiro@gmail.com> for the 
clarification

On 19/02/2025 18:11, Junio C Hamano wrote:
> Anselm Schüler <mail@anselmschueler.com> writes:
>
>> If you run git diff for a pathspec with an empty magic word/symbol
>> list in short form (prefixed by ::) and in long form (prefixed by
>> :():), you get different results.
> The short form is prefixed by a ":" and optionally ends by a ":",
> but the optional termination may not be required when there is no
> ambiguity (e.g. ":/!path" is "from the top, not matching "path", as
> "p" cannot be a magic signature; ":/:!path" is "from the top,
> matching "!path", as the set of magic signatures ends with the
> second disambiguating colon).
>
> The long form is prefixed by a ":(" and ends by a ")".
>
>
>> Here’s an example use of git that illustrates this:
>>
>> ~☭ mkdir gittest
>> ~☭ y gittest/
>> ~/gittest☭ git init
>> Initialized empty Git repository in /home/anselmschueler/gittest/.git/
>> ~/gittest (b0)☭ uuidgen >file
>> ~/gittest (b0)☭ git add file && git commit -m "$(read)"
>> read> initial commit
>> [b0 (root-commit) cd3bd43] initial commit
>>   1 file changed, 1 insertion(+)
>>   create mode 100644 file
>> ~/gittest (b0)☭ uuidgen >file
>> ~/gittest (b0)☭ git diff -- "::file"
>>
>> file
>> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>>
>> ───┐
>> 1: │
>> ───┘
>> 66d18ffa-1128-42a5-8d4e-f9d75eb86b92
>> 9acea2b5-50a6-4f87-ae1a-64019a93e55e
>> ~/gittest (b0)☭ git diff -- ":():file"
>> ~/gittest (b0)☭
> Doesn't ":():file" ask for a match for the pattern ":file", with a
> leading colon?

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

end of thread, other threads:[~2025-02-24 14:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-19 10:49 Possible bug: Empty magic word list in pathspec is handled differently in short vs. long form Anselm Schüler
2025-02-19 14:28 ` Lucas Oshiro
2025-02-19 17:11 ` Junio C Hamano
2025-02-24 14:11   ` Anselm Schüler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).