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

Re: [PATCH v3 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix

From
Glen Choo <chooglen@google.com>
Date
Jun 24, 2022, 16:48 UTC
Message-ID
<kl6ledzehusb.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<220624.86h74ahygt.gmgdl@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 134 quoted lines
> On Wed, Jun 22 2022, Glen Choo wrote:
>
>> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>>
>>> Remove the $prefix variable which isn't used anymore, and hasn't been
>>> since b3c5f5cb048 (submodule: move core cmd_update() logic to C,
>>> 2022-03-15).
>>>
>>> Before that we'd use it to invoke "git submodule--helper" with the
>>> "--recursive-prefix" option, but since b3c5f5cb048 that "git
>>> submodule--helper" option is only used when it invokes itself.
>>>
>>> Since we haven't used it since then we haven't been passing the
>>> --super-prefix option to "git submodule--helper", and can therefore
>>> remove the handling of it from builtin/submodule--helper.c as well.
>>>
>>> Note also that the still-existing code in builtin/submodule--helper.c
>>> to invoke other "git submodule--helper" processes with
>>> "--super-prefix" is not passing the option to
>>> "cmd_submodule__helper()", rather it's an argument to "git" itself.
>>>
>>> One way to verify that this is indeed dead code is to try to check out
>>> b3c5f5cb048^ and apply this change to a part of the code being removed
>>> here:
>>>
>>> 	-#define SUPPORT_SUPER_PREFIX (1<<0)
>>> 	+#define SUPPORT_SUPER_PREFIX 0
>>>
>>> Doing that will cause t7406-submodule-update.sh to fail with errors
>>> such as:
>>>
>>> 	-Submodule path '../super': checked out 'e1c658656b91df52a4634fbffeaa739807ce3521'
>>> 	+Submodule path 'super': checked out 'e1c658656b91df52a4634fbffeaa739807ce3521'
>>>
>>> I.e. the removal of the --super-prefix handling broke those cases, but
>>> when doing the same ad-hoc test with b3c5f5cb048 all of our tests will
>>> pass, since the "--super-prefix" will now be handled by earlier by
>>> "git" itself.
>>
>> Your finding is correct, but I just can't figure out why it is this way.
>> Neither b3c5f5cb048 nor b3c5f5cb048^ make any use of "--super-prefix"
>> (both use "--recursive-prefix"). And what's most puzzling to me is...
>>
>>> @@ -3402,15 +3399,9 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
>>>  	if (argc < 2 || !strcmp(argv[1], "-h"))
>>>  		usage("git submodule--helper <command>");
>>>  
>>> -	for (i = 0; i < ARRAY_SIZE(commands); i++) {
>>> -		if (!strcmp(argv[1], commands[i].cmd)) {
>>> -			if (get_super_prefix() &&
>>> -			    !(commands[i].option & SUPPORT_SUPER_PREFIX))
>>> -				die(_("%s doesn't support --super-prefix"),
>>> -				    commands[i].cmd);
>>> +	for (i = 0; i < ARRAY_SIZE(commands); i++)
>>> +		if (!strcmp(argv[1], commands[i].cmd))
>>>  			return commands[i].fn(argc - 1, argv + 1, prefix);
>>> -		}
>>> -	}
>>>  
>>>  	die(_("'%s' is not a valid submodule--helper "
>>>  	      "subcommand"), argv[1]);
>>
>> that all we do here is die() if we see "--super-prefix" but it is not
>> supported. I wouldn't expect that the printed result is different; I'd
>> expect git to die(). This isn't even an issue with SUPPORT_SUPER_PREFIX
>> either - if we just had:
>>
>> 	if (get_super_prefix())
>> 		die(_("%s doesn't support --super-prefix"),
>> 		    commands[i].cmd);
>>
>> we still see the same failure. At any rate, we don't seem to need
>> "--super-prefix" any more, so I didn't look deeper into it.
>>
>> One thing that I noticed (while trying to replace "--recursive-prefix"
>> with "--super-prefix" is that since this check checks the environment
>> for the super prefix and not the CLI option, it will complain if we do
>> "git --super-prefix=foo submodule unsupported-command", and e.g. t7407
>> will fail if we add
>>
>>   -	{"foreach", module_foreach, SUPPORT_SUPER_PREFIX},
>>   +	{"foreach", module_foreach, 0},
>>
>> I don't like this check but for another reason: the super prefix is set
>> in a GIT_* environment variable so it gets passed to all child
>> processes. So e.g. if we teach "git submodule update" to use
>> "--super-prefix", we must mark module_update with SUPPORT_SUPER_PREFIX.
>> But because that invokes "git submodule clone", "module_clone" must also
>> be marked SUPPORT_SUPER_PREFIX.
>>
>> Frankly, I'm not sure why we need to check for SUPPORT_SUPER_PREFIX in
>> the "git submodule--helper" subcommand. I see that it was introduced in
>> 89c8626557 (submodule helper: support super prefix, 2016-12-08) as part
>> of what eventually became absorbgitdirs, but I couldn't find any
>> discussion of why we need this check when it was first proposed [1].
>>
>> I'm not 100% sure of why we need the top level check either, but as I
>> understand it, it's a way of saying whether a command "supports
>> submodules" or not [2]. If so, then checking whether a "git
>> submodule--helper" command can recurse into submodules sounds like a
>> pointless exercise.
>>
>> I'm still all for deleting this because it really doesn't seem useful,
>> but I'd be lot more confident if someone knows why we have this to begin
>> with.
>>
>> [1] https://lore.kernel.org/git/20161122192235.6055-1-sbeller@google.com/
>> [2] https://lore.kernel.org/git/1474930003-83750-2-git-send-email-bmwill@google.com/
>
> I think I figured this out. I'm right about it being unnecessary, but
> the explanation in the commit message is wrong.
>
> What threw me off the trail is that the series that included b3c5f5cb048
> (submodule: move core cmd_update() logic to C, 2022-03-15) has in
> intra-series regression, which is what you're seeing here.
>
> I.e. its parent 75df9df0f81 (submodule--helper: reduce logic in
> run_update_procedure(), 2022-03-15) will fail with the above "../super"
> error without that local change. You won't get the failure on its
> parent, c9911c9358e (submodule--helper: teach update_data more options,
> 2022-03-15).
>
> I.e. 75df9df0f81 & b3c5f5cb048 should have been squashed, anyway.
>
> The actual point *for that test* at which we could have deleted that
> "define" is 29a5e9e1ffe (submodule--helper update-clone: learn --init,
> 2022-03-04), but other tests fail.
>
> The actual point is this commit in this series, I'll dig some more,
> sorry about sending you down the wrong path. That digression was just
> about chechking if we'd passed --super-prefix, which is changed in this
> same commit...
>
> I'll dig some more and re-roll.

Ah that might explain some things. I'm still not sure how removing SUPPORT_SUPER_PREFIX gives the result we see here, but here are some observations using the extra info I learned while converting "--recursive-prefix" -> "--super-prefix":

- 29a5e9e1ffe and its parent teach init_submodule() how to use the
  "--recursive-prefix" flag as a substitute for "--super-prefix".
  "--recursive-prefix" is used exclusively by "git submodule update" and
  does exactly the same thing as "--super-prefix".
  Those commits pass "--recursive-prefix" to
  do_get_submodule_displaypath(), which is an escape hatch to
  get_submodule_displaypath() (which always uses "--super-prefix").
- 75df9df0f81 introduced a regression because we now pass
  update_data.prefix to get_submodule_displaypath() instead of prefix,
  and update_data.prefix was never set (oops, that's my mistake). This
  was rectified in its child (b3c5f5cb048), where we start to set
  update_data.prefix when the two subcommands were combined.
  As a sidenote, in 75df9df0f81's diff, we see that recursive_prefix is
  used in conjunction with get_submodule_displaypath(), which means that
  we could theoretically use *both* "--recursive-prefix" AND
  "--super-prefix" at the same time. We don't do that though, because
  "--super-prefix" was never used by "git submodule update".
  (This prefixed_path stuff is going away when I convert
  "--recursive-prefix" to "--super-prefix", so don't feel the need to
  clean it up).
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 63 of 90 in “[RFC] submodule update: parse all options in C”
  1. 0/8 [RFC] submodule update: parse all options in CGlen Choo via GitGitGadget, Jun 10, 2022
  2. 1/8 submodule update: remove intermediate parsingGlen Choo via GitGitGadget, Jun 10, 2022
  3. 2/8 submodule update: pass options containing "[no-]"Glen Choo via GitGitGadget, Jun 10, 2022
  4. 3/8 submodule update: pass options with stuck formsGlen Choo via GitGitGadget, Jun 10, 2022
  5. 4/8 submodule update: pass --require-init and --initGlen Choo via GitGitGadget, Jun 10, 2022
  6. 5/8 submodule--helper update: use one param per typeGlen Choo via GitGitGadget, Jun 10, 2022
  7. 7/8 submodule update: stop parsing options in .shGlen Choo via GitGitGadget, Jun 10, 2022
  8. 8/8 submodule update: remove never-used expansionGlen Choo via GitGitGadget, Jun 10, 2022
  9. 6/8 submodule update: remove -v, pass --quietGlen Choo via GitGitGadget, Jun 10, 2022
  10. 00/20 submodule: remove git-submodule.sh, create bare builtin/submodule.cÆvar Arnfjörð Bjarmason, Jun 10, 2022
  11. 01/20 git-submodule.sh: remove unused sanitize_submodule_env()Ævar Arnfjörð Bjarmason, Jun 10, 2022
  12. 02/20 git-submodule.sh: remove unused $prefix variableÆvar Arnfjörð Bjarmason, Jun 10, 2022
  13. 04/20 git-submodule.sh: normalize parsing of "--branch"Ævar Arnfjörð Bjarmason, Jun 10, 2022
  14. 03/20 git-submodule.sh: remove unused --super-prefix logicÆvar Arnfjörð Bjarmason, Jun 10, 2022
  15. 05/20 git-submodule.sh: normalize parsing of --cachedÆvar Arnfjörð Bjarmason, Jun 10, 2022
  16. 06/20 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"Ævar Arnfjörð Bjarmason, Jun 10, 2022
  17. 07/20 git-submodule.sh: create a "case" dispatch statementÆvar Arnfjörð Bjarmason, Jun 10, 2022
  18. 09/20 git-submodule.sh: dispatch "sync" to helperÆvar Arnfjörð Bjarmason, Jun 10, 2022
  19. 08/20 submodule--helper: pretend to be "git submodule" in "-h" outputÆvar Arnfjörð Bjarmason, Jun 10, 2022
  20. 10/20 git-submodule.sh: dispatch directly to helperÆvar Arnfjörð Bjarmason, Jun 10, 2022
  21. 12/20 submodule--helper: have --require-init imply --initÆvar Arnfjörð Bjarmason, Jun 10, 2022
  22. 11/20 git-submodule.sh: dispatch "foreach" to helperÆvar Arnfjörð Bjarmason, Jun 10, 2022
  23. 15/20 submodule--helper: understand -v option for "update"Ævar Arnfjörð Bjarmason, Jun 10, 2022
  24. 14/20 git-submodule doc: document the -v" option to "update"Ævar Arnfjörð Bjarmason, Jun 10, 2022
  25. 18/20 git-submodule.sh: simplify parsing loopÆvar Arnfjörð Bjarmason, Jun 10, 2022
  26. 20/20 submodule: add a subprocess-less submodule.useBuiltin settingÆvar Arnfjörð Bjarmason, Jun 10, 2022
  27. 19/20 submodule: make it a built-in, remove git-submodule.shÆvar Arnfjörð Bjarmason, Jun 10, 2022
  28. 17/20 git-submodule.sh: use "$quiet", not "$GIT_QUIET"Ævar Arnfjörð Bjarmason, Jun 10, 2022
  29. 13/20 submodule--helper: understand --checkout, --merge and --rebase synonymsÆvar Arnfjörð Bjarmason, Jun 10, 2022
  30. 16/20 git-submodule.sh: dispatch "update" to helperÆvar Arnfjörð Bjarmason, Jun 10, 2022
  31. Glen ChooJun 13, 2022
  32. 00/12 submodule: make "git submodule--helper" behave like "git submodule"Ævar Arnfjörð Bjarmason, Jun 13, 2022
  33. 01/12 git-submodule.sh: remove unused sanitize_submodule_env()Ævar Arnfjörð Bjarmason, Jun 13, 2022
  34. 02/12 git-submodule.sh: remove unused $prefix var and --super-prefixÆvar Arnfjörð Bjarmason, Jun 13, 2022
  35. 03/12 git-submodule.sh: make "$cached" variable a booleanÆvar Arnfjörð Bjarmason, Jun 13, 2022
  36. 04/12 git-submodule.sh: remove unused top-level "--branch" argumentÆvar Arnfjörð Bjarmason, Jun 13, 2022
  37. Glen ChooJun 15, 2022
  38. 05/12 submodule--helper: have --require-init imply --initÆvar Arnfjörð Bjarmason, Jun 13, 2022
  39. Glen ChooJun 15, 2022
  40. 06/12 submodule update: remove "-v" optionÆvar Arnfjörð Bjarmason, Jun 13, 2022
  41. Glen ChooJun 15, 2022
  42. 09/12 submodule--helper: understand --checkout, --merge and --rebase synonymsÆvar Arnfjörð Bjarmason, Jun 13, 2022
  43. 08/12 submodule--helper: report "submodule" as our name in "-h" outputÆvar Arnfjörð Bjarmason, Jun 13, 2022
  44. Glen ChooJun 15, 2022
  45. Glen ChooJun 15, 2022
  46. Ævar Arnfjörð BjarmasonJun 15, 2022
  47. 07/12 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"Ævar Arnfjörð Bjarmason, Jun 13, 2022
  48. 11/12 git-submodule.sh: use "$quiet", not "$GIT_QUIET"Ævar Arnfjörð Bjarmason, Jun 13, 2022
  49. 12/12 git-sh-setup.sh: remove "say" function, change last usersÆvar Arnfjörð Bjarmason, Jun 13, 2022
  50. Glen ChooJun 15, 2022
  51. 10/12 submodule--helper: eliminate internal "--update" optionÆvar Arnfjörð Bjarmason, Jun 13, 2022
  52. Glen ChooJun 15, 2022
  53. Glen ChooJun 13, 2022
  54. Ævar Arnfjörð BjarmasonJun 13, 2022
  55. Glen ChooJun 15, 2022
  56. Glen ChooJun 15, 2022
  57. 00/12 submodule: make "git submodule--helper" behave like "git submodule"Ævar Arnfjörð Bjarmason, Jun 22, 2022
  58. 12/12 git-sh-setup.sh: remove "say" function, change last usersÆvar Arnfjörð Bjarmason, Jun 22, 2022
  59. 01/12 git-submodule.sh: remove unused sanitize_submodule_env()Ævar Arnfjörð Bjarmason, Jun 22, 2022
  60. 02/12 git-submodule.sh: remove unused $prefix var and --super-prefixÆvar Arnfjörð Bjarmason, Jun 22, 2022
  61. Glen ChooJun 22, 2022
  62. Ævar Arnfjörð BjarmasonJun 24, 2022
  63. Glen ChooJun 24, 2022
  64. 03/12 git-submodule.sh: make the "$cached" variable a booleanÆvar Arnfjörð Bjarmason, Jun 22, 2022
  65. 04/12 git-submodule.sh: remove unused top-level "--branch" argumentÆvar Arnfjörð Bjarmason, Jun 22, 2022
  66. 06/12 submodule update: remove "-v" optionÆvar Arnfjörð Bjarmason, Jun 22, 2022
  67. 05/12 submodule--helper: have --require-init imply --initÆvar Arnfjörð Bjarmason, Jun 22, 2022
  68. 10/12 submodule--helper: eliminate internal "--update" optionÆvar Arnfjörð Bjarmason, Jun 22, 2022
  69. 09/12 submodule--helper: understand --checkout, --merge and --rebase synonymsÆvar Arnfjörð Bjarmason, Jun 22, 2022
  70. Glen ChooJun 22, 2022
  71. Glen ChooJun 22, 2022
  72. 08/12 submodule--helper: report "submodule" as our name in some "-h" outputÆvar Arnfjörð Bjarmason, Jun 22, 2022
  73. Glen ChooJun 22, 2022
  74. 07/12 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"Ævar Arnfjörð Bjarmason, Jun 22, 2022
  75. 11/12 git-submodule.sh: use "$quiet", not "$GIT_QUIET"Ævar Arnfjörð Bjarmason, Jun 22, 2022
  76. Glen ChooJun 24, 2022
  77. 00/12 submodule: make "git submodule--helper" behave like "git submodule"Ævar Arnfjörð Bjarmason, Jun 28, 2022
  78. 01/12 git-submodule.sh: remove unused sanitize_submodule_env()Ævar Arnfjörð Bjarmason, Jun 28, 2022
  79. 02/12 git-submodule.sh: remove unused $prefix variableÆvar Arnfjörð Bjarmason, Jun 28, 2022
  80. 03/12 git-submodule.sh: make the "$cached" variable a booleanÆvar Arnfjörð Bjarmason, Jun 28, 2022
  81. 08/12 submodule--helper: report "submodule" as our name in some "-h" outputÆvar Arnfjörð Bjarmason, Jun 28, 2022
  82. 07/12 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"Ævar Arnfjörð Bjarmason, Jun 28, 2022
  83. 06/12 submodule update: remove "-v" optionÆvar Arnfjörð Bjarmason, Jun 28, 2022
  84. 12/12 git-sh-setup.sh: remove "say" function, change last usersÆvar Arnfjörð Bjarmason, Jun 28, 2022
  85. 04/12 git-submodule.sh: remove unused top-level "--branch" argumentÆvar Arnfjörð Bjarmason, Jun 28, 2022
  86. 05/12 submodule--helper: have --require-init imply --initÆvar Arnfjörð Bjarmason, Jun 28, 2022
  87. 10/12 submodule--helper: eliminate internal "--update" optionÆvar Arnfjörð Bjarmason, Jun 28, 2022
  88. 11/12 git-submodule.sh: use "$quiet", not "$GIT_QUIET"Ævar Arnfjörð Bjarmason, Jun 28, 2022
  89. 09/12 submodule--helper: understand --checkout, --merge and --rebase synonymsÆvar Arnfjörð Bjarmason, Jun 28, 2022
  90. Glen ChooJun 28, 2022

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.