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

[PATCH v4 00/12] submodule: make "git submodule--helper" behave like "git submodule"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 28, 2022, 10:05 UTC
Message-ID
<cover-v4-00.12-00000000000-20220628T095914Z-avarab@gmail.com>
In-Reply-To
<cover-v3-00.12-00000000000-20220622T142012Z-avarab@gmail.com>

These are preparatory changes to make "git submodule--helper"'s behavior align with that of "git submodule". The next step after this is to get rid of git-submodule.sh entirely, and make "git submodule" a built-in.

The last two patches here are post-cleanup of related submodule code that isn't strictly necessary, but good to do. Similarly this starts with the removal of some dead code in the area.

The goal is to make these changes as small as possible, and as obviously correct as possible. This will help to make the meaty changes that follow easier to review.

Changes since v3:
 * Leave the --super-prefix changes aside for now. As discussed in the
   v3 follow-up, now we're only removing the unused $prefix variable.
   Since the v2 was submitted Glen's submitted a series of his own. I
   think any non-trivial updates to --super-prefix are better done
   there, as noted in:
   https://lore.kernel.org/git/220628.86wnd1f9t1.gmgdl@evledraar.gmail.com/
   The overall diffstat is much smaller as a result, and I think this
   series should be ready for "next" now, as the remaining changes are
   well-revieweda at this point, with no outstanding issues.
Glen Choo (1):
  submodule--helper: eliminate internal "--update" option
Ævar Arnfjörð Bjarmason (11):
  git-submodule.sh: remove unused sanitize_submodule_env()
  git-submodule.sh: remove unused $prefix variable
  git-submodule.sh: make the "$cached" variable a boolean
  git-submodule.sh: remove unused top-level "--branch" argument
  submodule--helper: have --require-init imply --init
  submodule update: remove "-v" option
  submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
  submodule--helper: report "submodule" as our name in some "-h" output
  submodule--helper: understand --checkout, --merge and --rebase
    synonyms
  git-submodule.sh: use "$quiet", not "$GIT_QUIET"
  git-sh-setup.sh: remove "say" function, change last users
 builtin/submodule--helper.c    | 74 ++++++++++++++++++----------
 contrib/subtree/git-subtree.sh | 15 ++++--
 git-instaweb.sh                |  2 +-
 git-sh-setup.sh                | 16 -------
 git-submodule.sh               | 88 ++++++++++++----------------------
 submodule.c                    |  2 +-
 t/t7406-submodule-update.sh    |  2 +-
 7 files changed, 96 insertions(+), 103 deletions(-)
Range-diff against v3:
 1:  ed487469d62 =  1:  63150b4091c git-submodule.sh: remove unused sanitize_submodule_env()
 2:  082e015781e !  2:  7bf62497c54 git-submodule.sh: remove unused $prefix var and --super-prefix
    @@ Metadata
     Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
      ## Commit message ##
    -    git-submodule.sh: remove unused $prefix var and --super-prefix
    +    git-submodule.sh: remove unused $prefix variable
     
         Remove the $prefix variable which isn't used anymore, and hasn't been
         since b3c5f5cb048 (submodule: move core cmd_update() logic to C,
    @@ Commit message
         "--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.
    -
    -    So this is just one of the things that were overly complex in "git
    -    submodule--helper", because parts of it had to bridge the gap between
    -    *.sh and *.c land, but once we moved more parts to C we ended up
    -    getting that for free.
    +    So the "--recursive-prefix" option is still in use, but at this point
    +    only when the helper invokes itself during submodule recursion. See
    +    the "--recursive-prefix" option added in
    +    c51f8f94e5b (submodule--helper: run update procedures from C,
    +    2021-08-24).
     
         Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
     
    - ## builtin/submodule--helper.c ##
    -@@ builtin/submodule--helper.c: static int module_add(int argc, const char **argv, const char *prefix)
    - 	return 0;
    - }
    - 
    --#define SUPPORT_SUPER_PREFIX (1<<0)
    --
    - struct cmd_struct {
    - 	const char *cmd;
    - 	int (*fn)(int, const char **, const char *);
    --	unsigned option;
    - };
    - 
    - static struct cmd_struct commands[] = {
    --	{"list", module_list, 0},
    --	{"name", module_name, 0},
    --	{"clone", module_clone, 0},
    --	{"add", module_add, SUPPORT_SUPER_PREFIX},
    --	{"update", module_update, 0},
    --	{"resolve-relative-url-test", resolve_relative_url_test, 0},
    --	{"foreach", module_foreach, SUPPORT_SUPER_PREFIX},
    --	{"init", module_init, SUPPORT_SUPER_PREFIX},
    --	{"status", module_status, SUPPORT_SUPER_PREFIX},
    --	{"sync", module_sync, SUPPORT_SUPER_PREFIX},
    --	{"deinit", module_deinit, 0},
    --	{"summary", module_summary, SUPPORT_SUPER_PREFIX},
    --	{"push-check", push_check, 0},
    --	{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
    --	{"is-active", is_active, 0},
    --	{"check-name", check_name, 0},
    --	{"config", module_config, 0},
    --	{"set-url", module_set_url, 0},
    --	{"set-branch", module_set_branch, 0},
    --	{"create-branch", module_create_branch, 0},
    -+	{"list", module_list},
    -+	{"name", module_name},
    -+	{"clone", module_clone},
    -+	{"add", module_add},
    -+	{"update", module_update},
    -+	{"resolve-relative-url-test", resolve_relative_url_test},
    -+	{"foreach", module_foreach},
    -+	{"init", module_init},
    -+	{"status", module_status},
    -+	{"sync", module_sync},
    -+	{"deinit", module_deinit},
    -+	{"summary", module_summary},
    -+	{"push-check", push_check},
    -+	{"absorb-git-dirs", absorb_git_dirs},
    -+	{"is-active", is_active},
    -+	{"check-name", check_name},
    -+	{"config", module_config},
    -+	{"set-url", module_set_url},
    -+	{"set-branch", module_set_branch},
    -+	{"create-branch", module_create_branch},
    - };
    - 
    - int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
    -@@ builtin/submodule--helper.c: 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]);
    -
      ## git-submodule.sh ##
     @@ git-submodule.sh: files=
      remote=
 3:  3948aa5d782 =  3:  e4750f190f8 git-submodule.sh: make the "$cached" variable a boolean
 4:  b5967afd59f =  4:  52d97fd4c36 git-submodule.sh: remove unused top-level "--branch" argument
 5:  64e4aa41d21 =  5:  a4632f00a4a submodule--helper: have --require-init imply --init
 6:  b82faad77bb =  6:  ad5aad8fed7 submodule update: remove "-v" option
 7:  ff557f3c81a !  7:  9c8a102acc0 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
    @@ builtin/submodule--helper.c: static int absorb_git_dirs(int argc, const char **a
      	};
      
     @@ builtin/submodule--helper.c: static struct cmd_struct commands[] = {
    - 	{"deinit", module_deinit},
    - 	{"summary", module_summary},
    - 	{"push-check", push_check},
    --	{"absorb-git-dirs", absorb_git_dirs},
    -+	{"absorbgitdirs", absorb_git_dirs},
    - 	{"is-active", is_active},
    - 	{"check-name", check_name},
    - 	{"config", module_config},
    + 	{"deinit", module_deinit, 0},
    + 	{"summary", module_summary, SUPPORT_SUPER_PREFIX},
    + 	{"push-check", push_check, 0},
    +-	{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
    ++	{"absorbgitdirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
    + 	{"is-active", is_active, 0},
    + 	{"check-name", check_name, 0},
    + 	{"config", module_config, 0},
     
      ## git-submodule.sh ##
     @@ git-submodule.sh: cmd_sync()
 8:  bb1310b9abe =  8:  b8a9b085633 submodule--helper: report "submodule" as our name in some "-h" output
 9:  e251fc115e1 =  9:  e8ddb95dcbf submodule--helper: understand --checkout, --merge and --rebase synonyms
10:  66a229227a1 = 10:  abb5cb499aa submodule--helper: eliminate internal "--update" option
11:  f8219cd461d = 11:  c7eac40a0f2 git-submodule.sh: use "$quiet", not "$GIT_QUIET"
12:  ecdd8c6ed28 = 12:  f8f332f3c0a git-sh-setup.sh: remove "say" function, change last users
-- 
2.37.0.880.gf07d56b18ba
Previous: Glen ChooNext: Ævar Arnfjörð Bjarmason
Message 77 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.