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 7, 2017, 19:50 UTC
Message-ID
<20170207195011.2yvq6hutssl4htol@sigill.intra.peff.net>
In-Reply-To
<20170207150414.GD8583@stefanha-x1.localdomain>
On Tue, Feb 07, 2017 at 03:04:14PM +0000, Stefan Hajnoczi wrote:
Show 9 quoted lines
> > I assume Stefan just grabbed my naive suggestion hence why it checks
> > equality with a commit.  So that's my fault :)  Either of these may
> > not be enough though, since if you do 'git grep malloc v2.9.3^{tree}'
> > with this change the output prefix is 'v2.9.3^{tree}/' instead of the
> > correct prefix 'v2.9.3^{tree}:'
> 
> I revisited this series again today and am coming to the conclusion that
> forming output based on the user's rev is really hard to get right in
> all cases.  I don't have a good solution to the v2.9.3^{tree} problem.

I think the rule you need is not "are we at a tree", but rather "did we traverse a path while resolving the name?". Only the get_sha1() parser can tell you that. I think:

  char delim = ':';
  struct object_context oc;
  if (get_sha1_with_context(name, 0, sha1, &oc))
          die("...");
  if (oc.path[0])
          delim = '/'; /* name had a partial path */

would work. Root trees via "v2.9.3^{tree}" or "v2.9.3:" would have no path, but "v2.9.3:Documentation" would. I think you'd still need to avoid duplicating a trailing delimiter, but I can't think of a case where it is wrong to do that based purely on the name.

-Peff
Previous: Stefan HajnocziNext: Junio C Hamano
Message 8 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.