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

Re: [PATCH] rev-parse --git-path: fix output when running in a subdirectory

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 8, 2017, 18:47 UTC
Message-ID
<xmqqh944wmcs.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<50fe3ea3302c40f4c96eaa5a568837e3334f9dc4.1486555851.git.johannes.schindelin@gmx.de>
Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> The problem lies deeper, much deeper...
> ... but it bought us many, many problems.

I think you are making a mountain out of molehill here. This looks like as an opposite problem of a bug that forgets to prepend the prefix to relative pathnames given by the end user.

I do agree that some calling scripts may find it more convenient if the output were relative to their current directory, and in that sense, this is worth addressing.

However.

How long has "rev-parse --git-path" been around? Had scripts in the wild chance to learn to live with the "output is relative to the top of the working tree" reality? I think the answers are "since 2.5" and "yes".

I do not think we can make this unconditionally without breaking users. We instead need something like a new "--git-path-relative" option, similar in the spirit that output from "git diff" can be made relative to the current directory with the "--relative" option.

Assuming that we are discussing the new behaviour that is conditionally triggered, let's see the implementation.

Show 5 quoted lines
> -			puts(git_path("%s", argv[i + 1]));
> +			path = git_path("%s", argv[i + 1]);
> +			if (prefix && !is_absolute_path(path))
> +				path = real_path(path);
> +			puts(path);

Duy, want to help me out here? I am wondering if using a logic similar to what is used by "cd t && git grep -e foo :/" to emit paths as "../Documentation/CodingGuidelines" as relative to the current working directory is more appropriate than forcing the absolute path output here (and if so, it may be preferrable to use the relative_path() helper to do so), or the paths to files in $GIT_DIR are conceptually different enough from paths to files in the working tree and it will be more robust to have the output as an absolute path.

I am leaning toward the latter (i.e. the above use of real_path() is simple and good), but I haven't thought things through and since we have an area expert here in the thread...

Previous: Johannes SchindelinNext: Johannes Schindelin
Message 2 of 27 in “rev-parse --git-path: fix output when running in a subdirectory”
  1. rev-parse --git-path: fix output when running in a subdirectoryJohannes Schindelin, Feb 8, 2017
  2. Junio C HamanoFeb 8, 2017
  3. Johannes SchindelinFeb 9, 2017
  4. Junio C HamanoFeb 9, 2017
  5. Jeff KingFeb 10, 2017
  6. Duy NguyenFeb 9, 2017
  7. Mike RappazzoFeb 9, 2017
  8. Johannes SchindelinFeb 9, 2017
  9. Junio C HamanoFeb 9, 2017
  10. Johannes SchindelinFeb 9, 2017
  11. Junio C HamanoFeb 9, 2017
  12. Mike RappazzoFeb 10, 2017
  13. Johannes SchindelinFeb 10, 2017
  14. 0/2 Fix bugs in rev-parse's output when run in a subdirectoryJohannes Schindelin, Feb 10, 2017
  15. 2/2 rev-parse: fix several options when running in a subdirectoryJohannes Schindelin, Feb 10, 2017
  16. Junio C HamanoFeb 10, 2017
  17. Johannes SchindelinFeb 17, 2017
  18. 1/2 rev-parse tests: add tests executed from a subdirectoryJohannes Schindelin, Feb 10, 2017
  19. Junio C HamanoFeb 10, 2017
  20. Johannes SchindelinFeb 17, 2017
  21. Junio C HamanoFeb 10, 2017
  22. Johannes SchindelinFeb 17, 2017
  23. Junio C HamanoFeb 10, 2017
  24. 0/2 Fix bugs in rev-parse's output when run in a subdirectoryJohannes Schindelin, Feb 17, 2017
  25. 1/2 rev-parse tests: add tests executed from a subdirectoryJohannes Schindelin, Feb 17, 2017
  26. 2/2 rev-parse: fix several options when running in a subdirectoryJohannes Schindelin, Feb 17, 2017
  27. Junio C HamanoFeb 17, 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.