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

Re: [PATCH] rev-parse: add option for absolute or relative path formatting

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Sep 11, 2020, 00:03 UTC
Message-ID
<20200911000315.GL241078@camp.crustytoothpaste.net>
In-Reply-To
<20200910151935.GA5265@szeder.dev>
On 2020-09-10 at 15:19:35, SZEDER Gábor wrote:
> Well, on first sight it seems nice that scripts have to specify
> '--path-format=absolute' only once when querying multiple paths at
> once, though on second thought no prudent script would query multiple
> paths at once, because they might contain newlines.

We do that in Git LFS at the cost of not handling paths with newlines because calling out to Git multiple times is expensive, very especially on Windows. Of course, Windows doesn't allow newlines in paths, but it seems silly to have two different code paths for the same thing, especially on top of the different paths we have for versions of Git with and without worktrees (and therefore --git-common-dir).

If you're writing a script, you're not expecting great performance (or you wouldn't be writing shell), so it's less of a problem and you can actually afford the cost of being a little more correct.

I think if we wanted to prudently handle paths with newlines, we'd want to add a -z option to rev-parse (think about the case in shell where the path ends with a trailing newline). I may get around to that at some point, but anyone is welcome to pick it up before me.

Show 8 quoted lines
> Yeah, I think I found trouble that way, too.  I wonder whether
> '--path-format=relative' is really worth having, though.  Clearly
> there's a need for absolute paths, because getting relative paths
> causes difficulties for some scripts; I described one such use case in
> a2f5a87626 (rev-parse: add '--absolute-git-dir' option, 2017-02-03),
> and you just ran into another with Git LFS.  However, is there really
> a use case that requires relative paths, because an absolute path
> would cause similar difficulties?  I couldn't come with any.

The only case I can come up with is possibly wanting to know if a path is within another path, or if it's outside, and doing that with relative paths may be easier.

Show 5 quoted lines
> So perhaps it would be sufficient to introduce only
> '--path-format=absolute' (or equivalent) for now, and add a relative
> path variant only when there will be an actual compelling reason to do
> so.  And that would save you from the pain of addressing these bugs
> shown above.

I'll consider it when I do my reroll, which will probably be this weekend.

-- 
brian m. carlson: Houston, Texas, US
Previous: SZEDER GáborNext: Jonathan Nieder
Message 7 of 11 in “rev-parse: add option for absolute or relative path formatting”
  1. rev-parse: add option for absolute or relative path formattingbrian m. carlson, Sep 8, 2020
  2. Johannes SchindelinSep 9, 2020
  3. brian m. carlsonSep 9, 2020
  4. SZEDER GáborSep 9, 2020
  5. brian m. carlsonSep 9, 2020
  6. SZEDER GáborSep 10, 2020
  7. brian m. carlsonSep 11, 2020
  8. Jonathan NiederNov 4, 2020
  9. brian m. carlsonNov 5, 2020
  10. Jonathan NiederNov 6, 2020
  11. brian m. carlsonNov 6, 2020

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.