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

Re: [RFC/PATCH] recognize pathspec magic without "--" disambiguation

From
Jeff King <peff@peff.net>
Date
May 27, 2017, 20:39 UTC
Message-ID
<20170527203937.hto7lwxfbjvl5f7o@sigill.intra.peff.net>
In-Reply-To
<CACBZZX6K7ppVB0qYah76_+pjTKjsco3rHT0xRyKtF2H1dS4k_w@mail.gmail.com>
On Sat, May 27, 2017 at 11:54:07AM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 5 quoted lines
> On Thu, May 25, 2017 at 5:27 PM, Jeff King <peff@peff.net> wrote:
> >         git log :/foo.*bar
> 
> Another option would be to deprecate the :/rx syntax over some period
> in favor of ^{/rx}.

Yeah, the latter is more flexible (can start at a tip of your choosing) and syntactically matches other object selectors much better.

> I think it's too ugly to live, and really useless. It's equivalent to
> "--grep=<rx> --all". Does anyone use this and not really mean to use
> ^{/rx}? E.g. "git show :/fix" might show a fix on some unrelated
> branch you recently rebased.

It's actually _worse_ than that --grep because it only picks one result. So not only do we look at unrelated branches, but they may take precedence (based on commit timestamp) over the current branch.

It is shorter than "HEAD^{/re}", though. So I suspect people do use it and would be slightly annoyed if it went away.

Show 7 quoted lines
> >       will be treated as a pathspec (if it doesn't match a
> >       commit message) due to the wildcard matching in
> >       28fcc0b71.
> 
> So it might DWYM after hanging there looking at your entire history
> for a commit message matching foo.*bar? And if you make such a commit
> it'll start meaning something else entirely?

Yeah. That's a good reason not to use ":/" without a disambiguating "--" (which _does_ work, even without my series, because check_filename() does specific path-matching). At best, you pay for a complete useless history traversal before the command actually starts running. But much more likely is that Git just complains of ambiguity, because people tend to mention top-level paths in their commit messages. E.g.:

  $ cd t
  $ git grep foo :/Documentation
  fatal: ambiguous argument ':/Documentation': both revision and filename
So it really is a pretty horrible syntax.
-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 12 of 13 in “recognize pathspec magic without "--" disambiguation”
  1. recognize pathspec magic without "--" disambiguationJeff King, May 25, 2017
  2. Junio C HamanoMay 26, 2017
  3. Jeff KingMay 26, 2017
  4. 0/6 make "^:foo" work without disambiguating "--"Jeff King, May 26, 2017
  5. 1/6 t4208: add check for ":/" without matching fileJeff King, May 26, 2017
  6. 3/6 check_filename(): use skip_prefixJeff King, May 26, 2017
  7. 2/6 check_filename(): refactor ":/" handlingJeff King, May 26, 2017
  8. 4/6 check_filename(): handle ":^" path magicJeff King, May 26, 2017
  9. 6/6 verify_filename(): flip order of checksJeff King, May 26, 2017
  10. 5/6 verify_filename(): treat ":(magic)" as a pathspecJeff King, May 26, 2017
  11. Ævar Arnfjörð BjarmasonMay 27, 2017
  12. Jeff KingMay 27, 2017
  13. Junio C HamanoMay 28, 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.