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

Re: [PATCH v2 2/2] grep: use '/' delimiter for paths

From
Jeff King <peff@peff.net>
Date
Feb 9, 2017, 03:58 UTC
Message-ID
<20170209035839.wqsh6ibgnmxyjusi@sigill.intra.peff.net>
In-Reply-To
<xmqq8tphzr41.fsf@gitster.mtv.corp.google.com>
On Tue, Feb 07, 2017 at 12:24:30PM -0800, Junio C Hamano wrote:
Show 11 quoted lines
> Having said that, I actually think "make it more convenient" without
> making anything incorrect would be to teach the revision parser to
> understand
> 
>     <any-expression-to-name-a-tree-ish:<path>
> 
> as an extended SHA-1 expression to name the blob or the tree at that
> path in the tree-ish, e.g. if we can make the revision parser to
> take this
> 
>     master:Documentation:git.txt

So here I was wondering what happens when you have a filename with a colon in it, but then...

Show 7 quoted lines
> to be able to show the same thing as well.  You'd need to backtrack
> the parsing (e.g. attempt to find "Documentation:git.txt" in
> "master", fail to find any, then fall back to find "git.txt" in
> "master:Documentation", find one, and be happy, or something like
> that), and define how to resolve potential ambiguity (e.g. there may
> indeed be "Documentation:git.txt" and "Documentation/git.txt" in the
> tree-ish "master"), though.

...you obviously did think of that. Backtracking sounds pretty nasty, though. What's the time complexity of parsing:

  master:a:a:a:a:a:a:a:a:a:a:a

I think there are 2^(n-1) possible paths (each colon can be a real colon or a slash). Though I guess if you walk the trees as you go, you only have to examine at most "n" paths to find the first-level tree, and then at most "n-1" paths at the second level, and so on.

Unless you really do have ambiguous trees, in which case you have to walk down multiple paths.

It certainly would not be the first combinatoric explosion you can convince Git to perform. But it does seem like a lot of complication for something as simple as path lookups.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 15 in “grep: make output consistent with revision syntax”
  1. 0/2 grep: make output consistent with revision syntaxStefan Hajnoczi, Jan 20, 2017
  2. 1/2 grep: only add delimiter if there isn't one alreadyStefan Hajnoczi, Jan 20, 2017
  3. Junio C HamanoJan 20, 2017
  4. 2/2 grep: use '/' delimiter for pathsStefan Hajnoczi, Jan 20, 2017
  5. Junio C HamanoJan 20, 2017
  6. Brandon WilliamsJan 20, 2017
  7. Stefan HajnocziFeb 7, 2017
  8. Jeff KingFeb 7, 2017
  9. Junio C HamanoFeb 7, 2017
  10. Junio C HamanoFeb 7, 2017
  11. Jeff KingFeb 9, 2017
  12. Junio C HamanoFeb 9, 2017
  13. Jeff KingFeb 9, 2017
  14. Stefan HajnocziFeb 14, 2017
  15. Junio C HamanoJan 20, 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.