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

Re: [RFC PATCH 0/8] Get rid of "git --super-prefix"

From
Glen Choo <chooglen@google.com>
Date
Nov 11, 2022, 01:07 UTC
Message-ID
<kl6l5yfm2taf.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<221110.86zgcznjah.gmgdl@evledraar.gmail.com>

Rereading this series and thinking about this some more, let's go with your approach, primarily because it avoids global state.

From this series, it seems that it's not that hard to make this change and support whatever use cases we currently have.

This does make it more tedious to add more "--super-prefix" in the future, but that's a good push for us to do more things in-process and/or be more principled about passing context objects through the call stack instead of relying on globals.

Let me know what I can add to this effort besides reviewing :)
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 47 quoted lines
> On Wed, Nov 09 2022, Glen Choo wrote:
>
>> Thanks for the series! I haven't fully figured out where I stand on
>> this, but I can share some initial thoughts and comparisons to my RFC.
>>
>> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
>>
>>> An RFC alternative to Glen's [1], and what I *thought* he might be be
>>> going for in the earlier discussion[2].
>>>
>>> The difference is that in Glen's there's no "git --super-prefix", but
>>> rather each set of commands still using it ("submodule--helper",
>>> "read-tree" etc.) geit their own command-level option.
>>
>> Yes, and a secondary intent was to give exact definitions and a shared
>> implementation to the command-level options instead of having each new
>> command figure out what to do every time a similar use case pops up.
>
> ... (more below)...
>
>>>
>>> But it still works substantially the same, in that we're juggling a
>>> global variable that we set, and read out later somewhere down the
>>> stack.
>>
>> Yes, intentionally so. I was under the assumption that the various
>> prefixes would still be used, and that adding them to commands will be a
>> necessary evil, so it was better to have them share a single
>> implementation.
>
> I'm not sure I understand what you mean here exactly, but as an example
> that might clarify things: In my "foreach" patch:
> https://lore.kernel.org/git/RFC-patch-3.8-4858e2ad0ed-20221109T192315Z-avarab@gmail.com/
>
> I'm making use of "OPT__SUPER_PREFIX()" to share the things that need to
> be shared, and after that we ferry the "super_prefix" from
> module_foreach() down through "struct foreach_cb" to
> "runcommand_in_submodule_cb()", and that's all the places we need it.
>
> With how OPT_SUBCOMMAND() works we'd need a file-level static variable
> (or similar) if we took the "--super-prefix" in the
> cmd_submodule__helper() instead, which we could do, and it would have
> pretty much the same effect.
>
> But I don't really see the advantage in any one individiual case. Isn't
> it just trading that one repeated "OPT__SUPER_PREFIX()" line for more
> clarity about who needs what?

The other concern I had was that we'd have to repeat the "super_prefix" field in all of the command options structs, and then pass them down through all of the call chain that would need it. Or even worse, create new structs for call chains that didn't have them.

But, since want to move away from global state altogether, the "effort saving" of having a global will end up causing more headache for us in the future, so we should just bite the bullet now, especially since this series shows thats it's not _that_ hard.

Show 13 quoted lines
> We can be sure it's just clone/update/foreach/status/sync/absorbgitdirs,
> because if the others are invoked with the --super-prefix they'll die().
>
> Which aside from the specific approaches in either of our topics is, I
> think, a really nice thing to have. I.e. it makes reasoning about the
> code easier if we can confidently say "this is a feature with global
> effect, but it only has an impact on this subset of stuff".
>
> Which is an aspect of your proposed RFC that I don't like in
> isolation. I.e. if/when we're going to do the eventual refactoring that
> I've done in my RFC we'd need to reason that we need to change "foreach"
> and not "create-branch" or whatever, which the current whitelisting
> really helps us with.

Fair. I also had the same worries, which is probably a sign of smelly code.

Show 36 quoted lines
>
>> (As an aside, when you remove git-submodule.sh, I wonder if we should
>> split up submodule--helper along this dual-use line? e.g. the ones that
>> are entrypoints could be moved to "builtin/submodule.c", and the
>> implementation details can stay in "builtin/submodule--helper.c". Or
>> maybe you're already one step ahead of me here :))
>
> Yes, I'm ahead of you there.
>
> The ones that are purely internal, such as "push-check" etc. are still
> going to be invoked as "submodule--helper push-check".
>
> Before my RFC topic here I was planning on having both a "foreach" and
> "submodule--helper-foreach", as seen in:
> https://lore.kernel.org/git/221104.86wn8bzeus.gmgdl@evledraar.gmail.com/
>
> That was because I:
>
>  1. Didn't want to make "foreach"'s "--super-prefix" interface "public",
>     which it isn't now, as it's a purely internal thing we're trying to
>     eventually get rid of.
>  2. Didn't want to list all of "submodule--helper" as accepting it, as
>     some of it doesn't need it (e.g. "push-check").
>
> So having a "git submodule foreach" *not* accept it and it then
> recursing to an internal "git submodule--helper-foreach" which did
> accept it seemed like the least sucky thing to do.
>
> But if I rebase those patches on my RFC topic here we can invoke both as
> just "git submodule foreach".
>
> Pedantically, that's also exposing a "private" interface to the
> public. But:
>
>  * I'm listing it as OPT_HIDDEN, so we're not showing it outside fo
>    --help-all.

IMO I think OPT_HIDDEN is good enough, so yes, let's avoid having "submodule foo" and "submodule--helper foo".

Show 9 quoted lines
>  * More importantly, you need to provide that specific flag, it's not
>    accepting it "at a distance" via an env variable, which was the main
>    thing I was being paranod about.
>
>    Or rather. Even if *I knew* that "read-tree" or whatever wasn't
>    invoking a hook, which then invoked "submodule foreach" down the
>    line, and that "foreach" was slurping up the env var, I wanted to
>    leave it in a state where the next maintainer of this code didn't
>    have to worry about that.
Agree.
Show 38 quoted lines
>> [1] https://lore.kernel.org/git/20221109004708.97668-2-chooglen@google.com/
>>
>>>  * There's no passing of the "super_prefix" as a global, instead we
>>>    pass it all the way along until we recurse to ourselves. For
>>>    "submodule--helper" this is quite straightforward.
>>>
>>>  * Then in 8/8 we're left with just "read-tree" needing the remaining
>>>    "--super-prefix", and we likewise don't pass it as a global, but
>>>    instead add it to the "struct unpack_trees_options", which will
>>>    pass it all the way down into unpack-trees.c and entry.c, until
>>>    we're going to recursively invoke another "read-tree".
>>
>> I worry a little about two "necessary evils":
>>
>> - (As stated earlier) we may have to add "--super-prefix" or similar to
>>   more commands
>> - We may need to read "--super-prefix" from many parts of the code,
>>   since many parts might print paths.
>>
>> Having globals makes both of these cases easier, and is quite a bit
>> closer to the original implementation of "--super-prefix" (so your
>> characterization of only getting to a halfway point is accurate). This
>> was mostly to stave off opposition that it would tedious to add new
>> per-command "--super-prefix"-es, but if nobody else cares, maybe it's ok
>> to get of the globals.
>>
>> If we do want to pass a context object around, we probably have to be
>> more principled about it (e.g. in 8/8 I notice that checkout_stage()
>> doesn't receive the context object and we resort to passing NULL
>> instead), but we'd want that anyway if we want Git to move towards being
>> more library-like.
>
> Quick aside: Yes, that unlink_entry(ce) in builtin/checkout.c is now
> unlink_entry(ce, NULL).
>
> The API had only 3 users, and two potentially cared about the
> super_prefix. So I just amended the existing function, we could also add
> a unlink_entry_sp() or whatever.

I definitely prefer modifying the existing function in place since it avoids accidental omissions of the super prefix.

My original diagnosis is wrong though, that checkout_stage() caller is passed "struct checkout", so there is a super_prefix available.

Show 21 quoted lines
>
>> It's quite likely that if any new "--super-prefix"-es are added, they
>> would be added by a Googler (even the original ones were ;)), so I can
>> probably go through the roadmap and figure out how costly these extra
>> "--super-prefix"-es might be.
>
> I don't really see that happening, but let me just grant that point for
> the sake of argument: 
>
> Next month we're going to add a new "--super-prefix"-like use, and we're
> going to want some combinatino of a global, setenv()/getenv() etc. back,
> because it's the "sparse" code or whatever, and it'll be daunting to
> pass the state through 30 levels of callstack, we'll want to bypass it.
>
> I still don't see how it follows that we'd want to keep any of structure
> for this, which I think my series shows none of the current code needs.
>
> We can easily add such functionality back, adding a global variable
> isn't hard, and I think if anything such a future future would benefit
> from having to explain why it needs global state to do this sort of
> thing, when these other commands and sub-commands don't.

Yeah, I think the stakes of removing the global variable weren't as high as I originally thought.

Previous: Ævar Arnfjörð BjarmasonNext: Glen Choo
Message 26 of 105 in “git: remove --super-prefix”
  1. 0/4 git: remove --super-prefixGlen Choo, Nov 9, 2022
  2. 1/4 submodule--helper: teach --toplevel-cwd-prefixGlen Choo, Nov 9, 2022
  3. Ævar Arnfjörð BjarmasonNov 9, 2022
  4. 2/4 fetch: refactor --submodule-prefixGlen Choo, Nov 9, 2022
  5. Ævar Arnfjörð BjarmasonNov 9, 2022
  6. 3/4 read-tree: teach --submodule-prefixGlen Choo, Nov 9, 2022
  7. Ævar Arnfjörð BjarmasonNov 9, 2022
  8. 4/4 git: remove --super-prefixGlen Choo, Nov 9, 2022
  9. 0/8 Get rid of "git --super-prefix"Ævar Arnfjörð Bjarmason, Nov 9, 2022
  10. 1/8 submodule--helper: don't use global --super-prefix in "absorbgitdirs"Ævar Arnfjörð Bjarmason, Nov 9, 2022
  11. Glen ChooNov 11, 2022
  12. 2/8 submodule--helper: "deinit" has never used "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 9, 2022
  13. 3/8 submodule--helper: convert "foreach" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 9, 2022
  14. 4/8 submodule--helper: convert "sync" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 9, 2022
  15. 5/8 submodule--helper: convert "status" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 9, 2022
  16. 6/8 submodule--helper: convert "{update,clone}" to their own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 9, 2022
  17. 7/8 submodule tests: test "git branch -t" output and stderrÆvar Arnfjörð Bjarmason, Nov 9, 2022
  18. 8/8 read-tree: add "--super-prefix" option, eliminate globalÆvar Arnfjörð Bjarmason, Nov 9, 2022
  19. Glen ChooNov 11, 2022
  20. Taylor BlauNov 9, 2022
  21. Ævar Arnfjörð BjarmasonNov 9, 2022
  22. Taylor BlauNov 9, 2022
  23. Ævar Arnfjörð BjarmasonNov 9, 2022
  24. Glen ChooNov 10, 2022
  25. Ævar Arnfjörð BjarmasonNov 10, 2022
  26. Glen ChooNov 11, 2022
  27. Glen ChooNov 11, 2022
  28. Ævar Arnfjörð BjarmasonNov 11, 2022
  29. Taylor BlauNov 11, 2022
  30. Glen ChooNov 12, 2022
  31. Ævar Arnfjörð BjarmasonNov 14, 2022
  32. Glen ChooNov 14, 2022
  33. Ævar Arnfjörð BjarmasonNov 15, 2022
  34. 00/10 Get rid of "git --super-prefix"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  35. 01/10 read-tree + fetch tests: test failing "--super-prefix" interactionÆvar Arnfjörð Bjarmason, Nov 14, 2022
  36. Glen ChooNov 14, 2022
  37. Ævar Arnfjörð BjarmasonNov 14, 2022
  38. Glen ChooNov 14, 2022
  39. 02/10 submodule--helper: don't use global --super-prefix in "absorbgitdirs"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  40. Glen ChooNov 14, 2022
  41. Ævar Arnfjörð BjarmasonNov 17, 2022
  42. 03/10 submodule--helper: "deinit" has never used "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  43. 04/10 submodule--helper: convert "foreach" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  44. Glen ChooNov 14, 2022
  45. Ævar Arnfjörð BjarmasonNov 17, 2022
  46. 05/10 submodule--helper: convert "sync" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  47. 06/10 submodule--helper: convert "status" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  48. 07/10 submodule--helper: convert "{update,clone}" to their own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  49. Glen ChooNov 14, 2022
  50. 08/10 submodule tests: test "git branch -t" output and stderrÆvar Arnfjörð Bjarmason, Nov 14, 2022
  51. Glen ChooNov 14, 2022
  52. 10/10 fetch: rename "--submodule-prefix" to "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 14, 2022
  53. Glen ChooNov 14, 2022
  54. 09/10 read-tree: add "--super-prefix" option, eliminate globalÆvar Arnfjörð Bjarmason, Nov 14, 2022
  55. Glen ChooNov 14, 2022
  56. Taylor BlauNov 14, 2022
  57. Glen ChooNov 14, 2022
  58. Glen ChooNov 14, 2022
  59. Ævar Arnfjörð BjarmasonNov 15, 2022
  60. Glen ChooNov 16, 2022
  61. Ævar Arnfjörð BjarmasonNov 17, 2022
  62. Glen ChooNov 21, 2022
  63. 0/9 Get rid of "git --super-prefix"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  64. 1/9 read-tree + fetch tests: test failing "--super-prefix" interactionÆvar Arnfjörð Bjarmason, Nov 19, 2022
  65. 3/9 submodule--helper: don't use global --super-prefix in "absorbgitdirs"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  66. Glen ChooNov 22, 2022
  67. 2/9 submodule.c & submodule--helper: pass along "super_prefix" paramÆvar Arnfjörð Bjarmason, Nov 19, 2022
  68. 4/9 submodule--helper: convert "foreach" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  69. 6/9 submodule--helper: convert "status" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  70. 5/9 submodule--helper: convert "sync" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  71. 7/9 submodule--helper: convert "{update,clone}" to their own "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  72. 9/9 fetch: rename "--submodule-prefix" to "--super-prefix"Ævar Arnfjörð Bjarmason, Nov 19, 2022
  73. 8/9 read-tree: add "--super-prefix" option, eliminate globalÆvar Arnfjörð Bjarmason, Nov 19, 2022
  74. Glen ChooNov 22, 2022
  75. Glen ChooNov 22, 2022
  76. 0/9 Get rid of "git --super-prefix"Ævar Arnfjörð Bjarmason, Dec 15, 2022
  77. 2/9 read-tree + fetch tests: test failing "--super-prefix" interactionÆvar Arnfjörð Bjarmason, Dec 15, 2022
  78. 1/9 submodule absorbgitdirs tests: add missing "Migrating git..." testsÆvar Arnfjörð Bjarmason, Dec 15, 2022
  79. Glen ChooDec 15, 2022
  80. Ævar Arnfjörð BjarmasonDec 20, 2022
  81. 3/9 submodule.c & submodule--helper: pass along "super_prefix" paramÆvar Arnfjörð Bjarmason, Dec 15, 2022
  82. 5/9 submodule--helper: convert "foreach" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 15, 2022
  83. 4/9 submodule--helper: don't use global --super-prefix in "absorbgitdirs"Ævar Arnfjörð Bjarmason, Dec 15, 2022
  84. Glen ChooDec 15, 2022
  85. 6/9 submodule--helper: convert "sync" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 15, 2022
  86. 7/9 submodule--helper: convert "status" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 15, 2022
  87. 8/9 submodule--helper: convert "{update,clone}" to their own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 15, 2022
  88. 9/9 read-tree: add "--super-prefix" option, eliminate globalÆvar Arnfjörð Bjarmason, Dec 15, 2022
  89. Glen ChooDec 15, 2022
  90. Junio C HamanoDec 15, 2022
  91. Junio C HamanoDec 15, 2022
  92. 0/9 Get rid of "git --super-prefix"Ævar Arnfjörð Bjarmason, Dec 20, 2022
  93. 2/9 read-tree + fetch tests: test failing "--super-prefix" interactionÆvar Arnfjörð Bjarmason, Dec 20, 2022
  94. 1/9 submodule absorbgitdirs tests: add missing "Migrating git..." testsÆvar Arnfjörð Bjarmason, Dec 20, 2022
  95. 3/9 submodule.c & submodule--helper: pass along "super_prefix" paramÆvar Arnfjörð Bjarmason, Dec 20, 2022
  96. 5/9 submodule--helper: convert "foreach" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 20, 2022
  97. 4/9 submodule--helper: don't use global --super-prefix in "absorbgitdirs"Ævar Arnfjörð Bjarmason, Dec 20, 2022
  98. 6/9 submodule--helper: convert "sync" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 20, 2022
  99. 7/9 submodule--helper: convert "status" to its own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 20, 2022
  100. 8/9 submodule--helper: convert "{update,clone}" to their own "--super-prefix"Ævar Arnfjörð Bjarmason, Dec 20, 2022
  101. 9/9 read-tree: add "--super-prefix" option, eliminate globalÆvar Arnfjörð Bjarmason, Dec 20, 2022
  102. Taylor BlauNov 9, 2022
  103. Glen ChooNov 9, 2022
  104. Taylor BlauNov 10, 2022
  105. Glen ChooNov 10, 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.