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

Re: [PATCHv2] rev-parse: add --show-superproject-working-tree

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 8, 2017, 06:01 UTC
Message-ID
<xmqq60jk488v.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170308005615.20321-1-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 6 quoted lines
> +			if (!strcmp(arg, "--show-superproject-working-tree")) {
> +				const char *superproject = get_superproject_working_tree();
> +				if (superproject)
> +					puts(superproject);
> +				continue;
> +			}

Returning the exact string of the path from the API function is absolutely the right thing. I however have to wonder if rev-parse need to do the c-quoting unless it is told to show pathnames in its output without quoting (perhaps with "-z"). Paths from "rev-parse" (like "--git-dir", "--show-toplevel", etc.) already are excempt from the usual quoting rules, so doing puts() and nothing else is fine to be consistent with the existing practice, but in the longer term, I am sure we would need to revisit so that scripts can handle paths with funny characters sensibly, but that would be a different topic if existing ones like "--git-dir" are already unsafe.

Show 29 quoted lines
>  			if (!strcmp(arg, "--show-prefix")) {
>  				if (prefix)
>  					puts(prefix);
> diff --git a/submodule.c b/submodule.c
> index 3b98766a6b..06473d3646 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1514,3 +1514,86 @@ void absorb_git_dir_into_superproject(const char *prefix,
>  		strbuf_release(&sb);
>  	}
>  }
> +
> +const char *get_superproject_working_tree(void)
> +{
> +...
> +	argv_array_pushl(&cp.args, "--literal-pathspecs", "-C", "..",
> +			"ls-files", "--stage", "--full-name", "--", subpath, NULL);
> +	strbuf_reset(&sb);
> +...
> +	if (starts_with(sb.buf, "160000")) {
> +		int super_sub_len;
> +		int cwd_len = strlen(cwd);
> +		char *super_sub, *super_wt;
> +
> +		/*
> +		 * There is a superproject having this repo as a submodule.
> +		 * The format is <mode> SP <hash> SP <stage> TAB <full name> LF,
> +		 * First remove LF, then skip up to \t.
> +		 */

Looks more or less right but invoke "ls-files -z" and reading the \0 delimited output would be easier; otherwise you would have to worry about c-unquoting the pathname when the submodule is bound at a path with funny character (like a double-quote) in it.

Previous: Stefan BellerNext: Stefan Beller
Message 15 of 53 in “git-prompt.sh: Full patch for submodule indicator”
  1. 0/4 git-prompt.sh: Full patch for submodule indicatorBenjamin Fuchs, Jan 30, 2017
  2. 3/4 git-prompt.sh: fix for submodule 'dirty' indicatorBenjamin Fuchs, Jan 30, 2017
  3. 4/4 git-prompt.sh: add tests for submodule indicatorBenjamin Fuchs, Jan 30, 2017
  4. SZEDER GáborJan 31, 2017
  5. Junio C HamanoJan 31, 2017
  6. Stefan BellerJan 31, 2017
  7. rev-parse: add --show-superproject-working-treeStefan Beller, Mar 7, 2017
  8. Junio C HamanoMar 7, 2017
  9. Junio C HamanoMar 7, 2017
  10. Junio C HamanoMar 7, 2017
  11. Junio C HamanoMar 7, 2017
  12. Stefan BellerMar 7, 2017
  13. Junio C HamanoMar 7, 2017
  14. [PATCHv2] rev-parse: add --show-superproject-working-treeStefan Beller, Mar 8, 2017
  15. Junio C HamanoMar 8, 2017
  16. [PATCHv3] rev-parse: add --show-superproject-working-treeStefan Beller, Mar 8, 2017
  17. Junio C HamanoMar 8, 2017
  18. [PATCHv4] rev-parse: add --show-superproject-working-treeStefan Beller, Mar 8, 2017
  19. Junio C HamanoMar 8, 2017
  20. Jonathan NiederMar 17, 2017
  21. Documentation/git-worktree: use working tree for trees on the file systemStefan Beller, Mar 17, 2017
  22. Jonathan NiederMar 17, 2017
  23. Stefan BellerMar 17, 2017
  24. Junio C HamanoMar 18, 2017
  25. Junio C HamanoMar 18, 2017
  26. Junio C HamanoMar 18, 2017
  27. Stefan BellerMar 20, 2017
  28. Junio C HamanoMar 20, 2017
  29. Jonathan NiederMar 20, 2017
  30. 0/2 use "working trees" instead of "worktree" in our APIStefan Beller, Mar 20, 2017
  31. 2/2 revparse: introduce --is-inside-working-treeStefan Beller, Mar 20, 2017
  32. Jonathan NiederMar 20, 2017
  33. 1/2 git.c: introduce --working-tree superseding --work-treeStefan Beller, Mar 20, 2017
  34. Jonathan NiederMar 20, 2017
  35. Junio C HamanoMar 20, 2017
  36. Duy NguyenMar 21, 2017
  37. Junio C HamanoMar 21, 2017
  38. Michael J GruberMar 23, 2017
  39. Junio C HamanoMar 23, 2017
  40. Duy NguyenMar 25, 2017
  41. Michael J GruberApr 7, 2017
  42. Jacob KellerApr 7, 2017
  43. Duy NguyenMar 25, 2017
  44. Junio C HamanoMar 8, 2017
  45. 2/4 git-prompt.sh: rework of submodule indicatorBenjamin Fuchs, Jan 30, 2017
  46. SZEDER GáborJan 31, 2017
  47. 1/4 git-prompt.sh: add submodule indicatorBenjamin Fuchs, Jan 30, 2017
  48. Junio C HamanoJan 30, 2017
  49. Benjamin FuchsJan 31, 2017
  50. Junio C HamanoJan 31, 2017
  51. Stefan BellerFeb 6, 2017
  52. Jacob KellerFeb 6, 2017
  53. Stefan BellerFeb 6, 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.