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

Re: [PATCH 2/2] submodule.c: correctly handle nested submodules in is_submodule_modified

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 28, 2017, 23:42 UTC
Message-ID
<20170328234217.GU31294@aiede.mtv.corp.google.com>
In-Reply-To
<20170328230938.9887-3-sbeller@google.com>
Stefan Beller wrote:
Show 15 quoted lines
> Suppose I have a superproject 'super', with two submodules 'super/sub'
> and 'super/sub1'. 'super/sub' itself contains a submodule
> 'super/sub/subsub'. Now suppose I run, from within 'super':
>
>     echo hi >sub/subsub/stray-file
>     echo hi >sub1/stray-file
>
> Currently we get would see the following output in git-status:
>
>     git status --short
>      m sub
>      ? sub1
>
> With this patch applied, the untracked file in the nested submodule is
> turned into an untracked file on the 'super' level as well.
s/turned into/displayed as/
Show 12 quoted lines
>     git status --short
>      ? sub
>      ? sub1
>
> This doesn't change the output of 'git status --porcelain=1' for nested
> submodules, because its output is always ' M' for either untracked files
> or local modifications no matter the nesting level of the submodule.
>
> 'git status --porcelain=2' is affected by this change in a nested
> submodule, though. Without this patch it would report the direct submodule
> as modified and having no untracked files. With this patch it would report
> untracked files. Chalk this up as a bug fix.

I think that's reasonable, and the documentation does a good job of describing it.

Does this have any effect on the default mode of 'git status' (without --short or --porcelain)?

[...]
Show 8 quoted lines
> --- a/Documentation/git-status.txt
> +++ b/Documentation/git-status.txt
> @@ -187,6 +187,8 @@ Submodules have more state and instead report
>  		m    the submodule has modified content
>  		?    the submodule has untracked files
>  
> +Note that 'm' and '?' are applied recursively, e.g. if a nested submodule
> +in a submodule contains an untracked file, this is reported as '?' as well.
Language nits:
* Can simplify by leaving out "Note that ".
* s/, e\.g\./. For example,/

Should this say a brief word about rationale? The obvious way to describe it would involve "git add --recurse-submodules", which alas doesn't exist yet. But we could say

                                              this is reported as '?' as well,
   since the change cannot be added using "git add -u" from within any of the
   submodules.
[...]
Show 17 quoted lines
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1078,8 +1078,27 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
>  		/* regular untracked files */
>  		if (buf.buf[0] == '?')
>  			dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
> -		else
> -			dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
> +
> +		if (buf.buf[0] == 'u' ||
> +		    buf.buf[0] == '1' ||
> +		    buf.buf[0] == '2') {
> +			/*
> +			 * T XY SSSS:
> +			 * T = line type, XY = status, SSSS = submodule state
> +			 */
> +			if (buf.len < 1 + 1 + 2 + 1 + 4)
optional: Can shorten:
			/* T = line type, XY = status, SSSS = submodule state */
			if (buf.len < strlen("T XY SSSS"))
				...

That produces the same code at run time because compilers are able to inline the strlen of a constant. What you already have also seems sensible, though.

[...]
Show 11 quoted lines
> +				die("BUG: invalid status --porcelain=2 line %s",
> +				    buf.buf);
> +
> +			/* regular unmerged and renamed files */
> +			if (buf.buf[5] == 'S' && buf.buf[8] == 'U')
> +				/* nested untracked file */
> +				dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
> +
> +			if (memcmp(buf.buf + 5, "S..U", 4))
> +				/* other change */
> +				dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;

sanity check: What does this do for a "2" line indicating a sub-submodule that has been renamed that contains an untracked file? Do we need to rely on some other indication to show this as a change?

Enumerating some more cases, since I keep finding myself getting lost:
 - if the HEAD commit of "sub" changes, we show this as " M sub".
   What should we show if the HEAD commit of "sub/subsub" changes?
   I think this should be " m".
 - if "sub" is renamed, we show this as "R  sub -> newname".
   What should we show if "sub/subsub" is renamed?  It is tempting
   to show this as " m".
 - if "sub" is deleted, we show this as "D  sub". What should we
   show if "sub/subsub" is deleted? I think this is " m".
It keeps getting more complicated, but I think this is making sense.

Thanks and hope that helps, Jonathan

Previous: Stefan BellerNext: Stefan Beller
Message 62 of 73 in “[PATCHv3 0/3] short status: improve reporting for submodule changes”
  1. Stefan BellerMar 23, 2017
  2. 1/3 submodule.c: port is_submodule_modified to use porcelain 2Stefan Beller, Mar 23, 2017
  3. Jonathan NiederMar 23, 2017
  4. Junio C HamanoMar 23, 2017
  5. Stefan BellerMar 23, 2017
  6. 2/3 submodule.c, is_submodule_modified: stricter checking for submodulesStefan Beller, Mar 23, 2017
  7. Jonathan NiederMar 23, 2017
  8. 3/3 short status: improve reporting for submodule changesStefan Beller, Mar 23, 2017
  9. Jonathan NiederMar 23, 2017
  10. 0/8 short status: improve reporting for submodule changesStefan Beller, Mar 23, 2017
  11. 3/8 submodule.c: convert is_submodule_modified to use strbuf_getwholeline_fdStefan Beller, Mar 23, 2017
  12. 1/8 submodule.c: port is_submodule_modified to use porcelain 2Stefan Beller, Mar 23, 2017
  13. 5/8 submodule.c: factor out early loop termination in is_submodule_modifiedStefan Beller, Mar 23, 2017
  14. 2/8 submodule.c: use argv_array in is_submodule_modifiedStefan Beller, Mar 23, 2017
  15. 4/8 submodule.c: port is_submodule_modified to use porcelain 2Stefan Beller, Mar 23, 2017
  16. 8/8 submodule.c: correctly handle nested submodules in is_submodule_modifiedStefan Beller, Mar 23, 2017
  17. 6/8 submodule.c: stricter checking for submodules in is_submodule_modifiedStefan Beller, Mar 23, 2017
  18. 7/8 short status: improve reporting for submodule changesStefan Beller, Mar 23, 2017
  19. Stefan BellerMar 23, 2017
  20. 0/7 short status: improve reporting for submodule changesStefan Beller, Mar 23, 2017
  21. 1/7 submodule.c: use argv_array in is_submodule_modifiedStefan Beller, Mar 23, 2017
  22. Jonathan NiederMar 23, 2017
  23. 4/7 submodule.c: factor out early loop termination in is_submodule_modifiedStefan Beller, Mar 23, 2017
  24. 5/7 submodule.c: stricter checking for submodules in is_submodule_modifiedStefan Beller, Mar 23, 2017
  25. 2/7 submodule.c: convert is_submodule_modified to use strbuf_getwholeline_fdStefan Beller, Mar 23, 2017
  26. Jonathan NiederMar 23, 2017
  27. Stefan BellerMar 23, 2017
  28. Stefan BellerMar 23, 2017
  29. 6/7 short status: improve reporting for submodule changesStefan Beller, Mar 23, 2017
  30. 0/7 short status: improve reporting for submodule changesStefan Beller, Mar 24, 2017
  31. 1/7 submodule.c: use argv_array in is_submodule_modifiedStefan Beller, Mar 24, 2017
  32. Jonathan NiederMar 24, 2017
  33. 2/7 submodule.c: factor out early loop termination in is_submodule_modifiedStefan Beller, Mar 24, 2017
  34. Jonathan NiederMar 24, 2017
  35. 3/7 submodule.c: convert is_submodule_modified to use strbuf_getwholelineStefan Beller, Mar 24, 2017
  36. Jonathan NiederMar 24, 2017
  37. Stefan BellerMar 25, 2017
  38. 5/7 submodule.c: stricter checking for submodules in is_submodule_modifiedStefan Beller, Mar 24, 2017
  39. Jonathan NiederMar 24, 2017
  40. 6/7 short status: improve reporting for submodule changesStefan Beller, Mar 24, 2017
  41. Jonathan NiederMar 24, 2017
  42. 7/7 submodule.c: correctly handle nested submodules in is_submodule_modifiedStefan Beller, Mar 24, 2017
  43. Jonathan NiederMar 24, 2017
  44. Stefan BellerMar 25, 2017
  45. 4/7 submodule.c: port is_submodule_modified to use porcelain 2Stefan Beller, Mar 24, 2017
  46. Jonathan NiederMar 24, 2017
  47. 0/7 short status: improve reporting for submodule changesStefan Beller, Mar 25, 2017
  48. 1/7 submodule.c: use argv_array in is_submodule_modifiedStefan Beller, Mar 25, 2017
  49. 2/7 submodule.c: factor out early loop termination in is_submodule_modifiedStefan Beller, Mar 25, 2017
  50. 3/7 submodule.c: convert is_submodule_modified to use strbuf_getwholelineStefan Beller, Mar 25, 2017
  51. 4/7 submodule.c: port is_submodule_modified to use porcelain 2Stefan Beller, Mar 25, 2017
  52. 7/7 submodule.c: correctly handle nested submodules in is_submodule_modifiedStefan Beller, Mar 25, 2017
  53. Junio C HamanoMar 27, 2017
  54. Jonathan NiederMar 28, 2017
  55. Junio C HamanoMar 30, 2017
  56. Stefan BellerMar 28, 2017
  57. 6/7 short status: improve reporting for submodule changesStefan Beller, Mar 25, 2017
  58. 5/7 submodule.c: stricter checking for submodules in is_submodule_modifiedStefan Beller, Mar 25, 2017
  59. Jonathan NiederMar 25, 2017
  60. 0/7 short status: improve reporting for submodule changesStefan Beller, Mar 28, 2017
  61. 2/2 submodule.c: correctly handle nested submodules in is_submodule_modifiedStefan Beller, Mar 28, 2017
  62. Jonathan NiederMar 28, 2017
  63. Stefan BellerMar 29, 2017
  64. 1/2 short status: improve reporting for submodule changesStefan Beller, Mar 28, 2017
  65. Jonathan NiederMar 28, 2017
  66. [PATCHv9 (6,7)/7] short status: improve reporting for submodule changesStefan Beller, Mar 29, 2017
  67. 1/2 short status: improve reporting for submodule changesStefan Beller, Mar 29, 2017
  68. Jonathan NiederMar 29, 2017
  69. 2/2 submodule.c: correctly handle nested submodules in is_submodule_modifiedStefan Beller, Mar 29, 2017
  70. Jonathan NiederMar 29, 2017
  71. Junio C HamanoMar 30, 2017
  72. 3/7 submodule.c: port is_submodule_modified to use porcelain 2Stefan Beller, Mar 23, 2017
  73. 7/7 submodule.c: correctly handle nested submodules in is_submodule_modifiedStefan Beller, Mar 23, 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.