submodule update: parse all options in C
Subsystems (2)
PATCH 1/8 submodule update: remove intermediate parsing
In reply to Glen Choo via GitGitGadgetFrom: Glen Choo <[email protected]>
When the cmd_*() functions in git-submodule.sh parse options, they sometimes set an intermediate variable to "1", check if the variable is set, and if so, pass a string option to "git submodule--helper".
In many cases, this parsing and unparsing is unnecessary because the "git submodule--helper" command already understands the literal options passed to "git submodule", e.g. when we see "--init", we don't need to set "init=1" only to pass "${init:+--init}" again.
In cmd_update(), remove unnecessary "${variable+option}" expressions by passing the literal option to "git submodule--helper update". Do this by appending the string option into a catch-all "opts", so that the intermediate variable becomes unused and can be removed.
This slightly changes the options we pass to "git submodule--helper update" because we now pass every instance of the option instead of only passing it once. This is probably a good thing though, because it's more consistent to handle this in C instead of custom shell code.
--- git-submodule.sh | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
git-submodule.sh +8 -17
@@ -38,17 +38,13 @@ recursive= init= require_init= files= -remote= -nofetch= update= prefix= custom_name= depth= progress= dissociate= -single_branch= jobs= -recommend_shallow= filter= isnumber()
@@ -246,6 +242,7 @@ cmd_deinit() # cmd_update() { + opts= # parse $args after "submodule ... update". while test $# -ne 0 do
@@ -257,7 +254,7 @@ cmd_update() unset GIT_QUIET ;; --progress) - progress=1 + opts="$opts $1" ;; -i|--init) init=1
@@ -267,13 +264,13 @@ cmd_update() require_init=1 ;; --remote) - remote=1 + opts="$opts $1" ;; -N|--no-fetch) - nofetch=1 + opts="$opts $1" ;; -f|--force) - force=$1 + opts="$opts $1" ;; -r|--rebase) update="rebase"
@@ -287,13 +284,13 @@ cmd_update() reference="$1" ;; --dissociate) - dissociate=1 + opts="$opts $1" ;; -m|--merge) update="merge" ;; --recursive) - recursive=1 + opts="$opts $1" ;; --checkout) update="checkout"
@@ -350,24 +347,18 @@ cmd_update() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ ${GIT_QUIET:+--quiet} \ - ${force:+--force} \ - ${progress:+"--progress"} \ - ${remote:+--remote} \ - ${recursive:+--recursive} \ ${init:+--init} \ - ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ ${reference:+"$reference"} \ - ${dissociate:+"--dissociate"} \ ${depth:+"$depth"} \ ${require_init:+--require-init} \ - ${dissociate:+"--dissociate"} \ $single_branch \ $recommend_shallow \ $jobs \ $filter \ + $opts \ -- \ "$@" }
Signature · 1 line
gitgitgadget
cover submodule update: parse all options in C
As a follow up to ar/submodule-update [1] and its successors gc/submodule-update-part* [2] [3], this series converts the last remaining piece of "git submodule update" into C, namely, the option parsing in git-submodule.sh.
As a result, git-submodule.sh::cmd_update() is now an (almost) one-liner:
cmd_update() { git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update ${wt_prefix:+--prefix "$wt_prefix"}
"$@" }
and best of all, "git submodule update" now shows a usage string for its own subcommand instead of a giant usage string for all of "git submodule" :)
Given how many options "git submodule update" accepts, this series takes a gradual approach:
1. Create a variable opts, which holds the literal options we want to pass to "git submodule--helper update". Then, for each option...
2. If "git submodule--helper update" already understands the string option, append it to opts and remove any special handling (1-3/8).
3. Otherwise, if the option makes sense, teach "git submodule--helper update" to understand the option. Goto 2. (4-5/8).
4. Otherwise, if the option makes no sense, drop it (6/8).
5. When we've processed all options, delete all the option parsing code
(7/8) and clean up (8/8).
I read over the other "git submodule" subcommands very briefly to see how much work this would be if we were to repeat the process for all subcommands. It should be relatively simple - most "git submodule--helper" commands already understand every CLI option that they need to, so we can skip step 3 (i.e. the tedious one).
I'm sending this as an RFC because even though this series is pretty low-risk, the previous topics [1] [2] [3] had their fair share of regressions (even when the conversions seemed 'obviously correct') and showed that the test coverage of "git submodule "update" is quite poor. I'd like to get feedback on the general approach before I invest more time into improving the test coverage and/or checking the before/after output for regressions [4].
[1] https://lore.kernel.org/git/[email protected]/
[2] Part 1
https://lore.kernel.org/git/[email protected]/ [3] Part 2
https://lore.kernel.org/git/[email protected]/ [4] Ævar suggested a way to do this using the test suite and "--tee" in
https://lore.kernel.org/git/[email protected]/
Glen Choo (8):
submodule update: remove intermediate parsing submodule update: pass options containing "[no-]" submodule update: pass options with stuck forms submodule update: pass --require-init and --init submodule--helper update: use one param per type submodule update: remove -v, pass --quiet submodule update: stop parsing options in .sh submodule update: remove never-used expansion
builtin/submodule--helper.c | 41 +++++++---- git-submodule.sh | 131 ------------------------------------ t/t7406-submodule-update.sh | 2 +- 3 files changed, 29 insertions(+), 145 deletions(-)
base-commit: 1e59178e3f65880188caedb965e70db5ceeb2d64
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1275%2Fchooglen%2Fsubmodule%2Fparse-update-opts-in-c-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1275/chooglen/submodule/parse-update-opts-in-c-v1
Pull-Request: https://github.com/git/git/pull/1275
Signature · 1 line
gitgitgadget
PATCH 2/8 submodule update: pass options containing "[no-]"
From: Glen Choo <[email protected]>
"git submodule--helper update" understands these options, so append them to opts and remove their intermediate variables.
As a result, we now pass every instance of the option and its "no-" variant to "git submodule--helper update" instead of only passing the last instance. As we noted in the previous commit, this is good because this makes our options parsing consistent.
--- git-submodule.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
git-submodule.sh +4 -6
@@ -296,10 +296,10 @@ cmd_update() update="checkout" ;; --recommend-shallow) - recommend_shallow="--recommend-shallow" + opts="$opts $1" ;; --no-recommend-shallow) - recommend_shallow="--no-recommend-shallow" + opts="$opts $1" ;; --depth) case "$2" in '') usage ;; esac
@@ -318,10 +318,10 @@ cmd_update() jobs=$1 ;; --single-branch) - single_branch="--single-branch" + opts="$opts $1" ;; --no-single-branch) - single_branch="--no-single-branch" + opts="$opts $1" ;; --filter) case "$2" in '') usage ;; esac
@@ -354,8 +354,6 @@ cmd_update() ${reference:+"$reference"} \ ${depth:+"$depth"} \ ${require_init:+--require-init} \ - $single_branch \ - $recommend_shallow \ $jobs \ $filter \ $opts \
Signature · 1 line
gitgitgadget
PATCH 3/8 submodule update: pass options with stuck forms
In reply to Glen Choo via GitGitGadgetFrom: Glen Choo <[email protected]>
git-submodule.sh::cmd_update() converts 'unstuck' forms of options into their 'stuck' forms before passing them to "git submodule--helper update". Remove this special handling of 'unstuck' options and append the options to opts.
--- git-submodule.sh | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
git-submodule.sh +8 -15
@@ -32,7 +32,6 @@ export GIT_PROTOCOL_FROM_USER command= branch= force= -reference= cached= recursive= init=
@@ -44,8 +43,6 @@ custom_name= depth= progress= dissociate= -jobs= -filter= isnumber() {
@@ -277,11 +274,11 @@ cmd_update() ;; --reference) case "$2" in '') usage ;; esac - reference="--reference=$2" + opts="$opts $1 $2" shift ;; --reference=*) - reference="$1" + opts="$opts $1" ;; --dissociate) opts="$opts $1"
@@ -303,19 +300,19 @@ cmd_update() ;; --depth) case "$2" in '') usage ;; esac - depth="--depth=$2" + opts="$opts $1 $2" shift ;; --depth=*) - depth=$1 + opts="$opts $1" ;; -j|--jobs) case "$2" in '') usage ;; esac - jobs="--jobs=$2" + opts="$opts $1 $2" shift ;; --jobs=*) - jobs=$1 + opts="$opts $1" ;; --single-branch) opts="$opts $1"
@@ -325,11 +322,11 @@ cmd_update() ;; --filter) case "$2" in '') usage ;; esac - filter="--filter=$2" + opts="$opts $1 $2" shift ;; --filter=*) - filter="$1" + opts="$opts $1" ;; --) shift
@@ -351,11 +348,7 @@ cmd_update() ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ - ${reference:+"$reference"} \ - ${depth:+"$depth"} \ ${require_init:+--require-init} \ - $jobs \ - $filter \ $opts \ -- \ "$@"
Signature · 1 line
gitgitgadget
PATCH 4/8 submodule update: pass --require-init and --init
In reply to Glen Choo via GitGitGadgetFrom: Glen Choo <[email protected]>
git-submodule.sh::cmd_update() makes "--require-init" imply "--init". Move this logic into "git submodule--helper update" instead, and append both options to opts.
--- builtin/submodule--helper.c | 4 ++++ git-submodule.sh | 9 ++------- 2 files changed, 6 insertions(+), 7 deletions(-)
builtin/submodule--helper.c +4 -0
@@ -2642,6 +2642,10 @@ static int module_update(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, module_update_options, git_submodule_helper_usage,0 ); +if (opt.require_init) { + opt.init =1 ; + } +if (filter_options.choice && !opt.init) {usage_with_options (git_submodule_helper_usage, module_update_options);
git-submodule.sh +2 -7
@@ -34,8 +34,6 @@ branch= force= cached= recursive= -init= -require_init= files= update= prefix=
@@ -254,11 +252,10 @@ cmd_update() opts="$opts $1" ;; -i|--init) - init=1 + opts="$opts $1" ;; --require-init) - init=1 - require_init=1 + opts="$opts $1" ;; --remote) opts="$opts $1"
@@ -344,11 +341,9 @@ cmd_update() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ ${GIT_QUIET:+--quiet} \ - ${init:+--init} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ - ${require_init:+--require-init} \ $opts \ -- \ "$@"
Signature · 1 line
gitgitgadget
PATCH 5/8 submodule--helper update: use one param per type
In reply to Glen Choo via GitGitGadgetFrom: Glen Choo <[email protected]>
git-submodule.sh accepts literal 'update types' as options, but parses them into a "--update" option for "git submodule--helper update", e.g. "--checkout" becomes "--update=checkout".
Teach the 'update type' options to "git submodule--helper update" so that we no longer have to do this parsing in git-submodule.sh, and append them to opts.
--- builtin/submodule--helper.c | 37 ++++++++++++++++++++++++------------- git-submodule.sh | 8 +++----- 2 files changed, 27 insertions(+), 18 deletions(-)
builtin/submodule--helper.c +24 -13
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)static void determine_submodule_update_strategy (struct repository *r,int just_cloned,const char *path, -const char *update, +enum submodule_update_type update,struct submodule_update_strategy *out) {const struct submodule *sub =submodule_from_path (r,null_oid (), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r, key =xstrfmt ("submodule.%s.update" , sub->name);if (update) { -if (parse_submodule_update_strategy (update, out) <0 ) -die (_ ("Invalid update mode '%s' for submodule path '%s'" ), - update, path); + out->type = update; }else if (!repo_config_get_string_tmp (r, key, &val)) {if (parse_submodule_update_strategy (val, out) <0 ) die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,6 @@ struct update_data {const char *prefix;const char *recursive_prefix;const char *displaypath; -const char *update_default;struct object_id suboid;struct string_list references;struct submodule_update_strategy update_strategy;
@@ -1892,6 +1889,7 @@ struct update_data {int max_jobs;int single_branch;int recommend_shallow; +enum submodule_update_type update_default;unsigned int require_init;unsigned int force;unsigned int quiet;
@@ -2429,8 +2427,20 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *strvec_push (args,"--require-init" );if (update_data->depth)strvec_pushf (args,"--depth=%d" , update_data->depth); -if (update_data->update_default) -strvec_pushl (args,"--update" , update_data->update_default,NULL ); +switch (update_data->update_default) { +case SM_UPDATE_MERGE : +strvec_push (args,"--merge" ); +break ; +case SM_UPDATE_CHECKOUT : +strvec_push (args,"--checkout" ); +break ; +case SM_UPDATE_REBASE : +strvec_push (args,"--rebase" ); +break ; +default : +break ; + } +if (update_data->references.nr) {struct string_list_item *item;for_each_string_list_item (item, &update_data->references)
@@ -2600,9 +2610,12 @@ static int module_update(int argc, const char **argv, const char *prefix) N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), -OPT_STRING (0 ,"update" , &opt.update_default, -N_ ("string" ), -N_ ("rebase, merge, checkout or none" )), +OPT_SET_INT (0 ,"checkout" , &opt.update_default, +N_ ("update using checkout" ),SM_UPDATE_CHECKOUT ), +OPT_SET_INT ('r' ,"rebase" , &opt.update_default, +N_ ("update using rebase" ),SM_UPDATE_REBASE ), +OPT_SET_INT ('m' ,"merge" , &opt.update_default, +N_ ("update using merge" ),SM_UPDATE_MERGE ),OPT_STRING_LIST (0 ,"reference" , &opt.references,N_ ("repo" ),N_ ("reference repository" )), OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2654,9 +2667,7 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options;if (opt.update_default) -if (parse_submodule_update_strategy (opt.update_default, - &opt.update_strategy) <0 ) -die (_ ("bad value for update parameter" )); + opt.update_strategy.type = opt.update_default;if (module_list_compute (argc, argv, prefix, &pathspec, &opt.list) <0 ) {list_objects_filter_release (&filter_options);
git-submodule.sh +3 -5
@@ -35,7 +35,6 @@ force= cached= recursive= files= -update= prefix= custom_name= depth=
@@ -267,7 +266,7 @@ cmd_update() opts="$opts $1" ;; -r|--rebase) - update="rebase" + opts="$opts $1" ;; --reference) case "$2" in '') usage ;; esac
@@ -281,13 +280,13 @@ cmd_update() opts="$opts $1" ;; -m|--merge) - update="merge" + opts="$opts $1" ;; --recursive) opts="$opts $1" ;; --checkout) - update="checkout" + opts="$opts $1" ;; --recommend-shallow) opts="$opts $1"
@@ -343,7 +342,6 @@ cmd_update() ${GIT_QUIET:+--quiet} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ - ${update:+--update "$update"} \ $opts \ -- \ "$@"
Signature · 1 line
gitgitgadget
PATCH 7/8 submodule update: stop parsing options in .sh
In reply to Glen Choo via GitGitGadgetFrom: Glen Choo <[email protected]>
cmd_update()'s option parsing loop is now obsolete - it only appends options to opts without doing additional parsing. Remove it.
--- git-submodule.sh | 101 ----------------------------------------------- 1 file changed, 101 deletions(-)
git-submodule.sh +0 -101
@@ -236,110 +236,9 @@ cmd_deinit() # cmd_update() { - opts= - # parse $args after "submodule ... update". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - opts="$opts $1" - ;; - --progress) - opts="$opts $1" - ;; - -i|--init) - opts="$opts $1" - ;; - --require-init) - opts="$opts $1" - ;; - --remote) - opts="$opts $1" - ;; - -N|--no-fetch) - opts="$opts $1" - ;; - -f|--force) - opts="$opts $1" - ;; - -r|--rebase) - opts="$opts $1" - ;; - --reference) - case "$2" in '') usage ;; esac - opts="$opts $1 $2" - shift - ;; - --reference=*) - opts="$opts $1" - ;; - --dissociate) - opts="$opts $1" - ;; - -m|--merge) - opts="$opts $1" - ;; - --recursive) - opts="$opts $1" - ;; - --checkout) - opts="$opts $1" - ;; - --recommend-shallow) - opts="$opts $1" - ;; - --no-recommend-shallow) - opts="$opts $1" - ;; - --depth) - case "$2" in '') usage ;; esac - opts="$opts $1 $2" - shift - ;; - --depth=*) - opts="$opts $1" - ;; - -j|--jobs) - case "$2" in '') usage ;; esac - opts="$opts $1 $2" - shift - ;; - --jobs=*) - opts="$opts $1" - ;; - --single-branch) - opts="$opts $1" - ;; - --no-single-branch) - opts="$opts $1" - ;; - --filter) - case "$2" in '') usage ;; esac - opts="$opts $1 $2" - shift - ;; - --filter=*) - opts="$opts $1" - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ - $opts \ - -- \ "$@" }
Signature · 1 line
gitgitgadget
PATCH 8/8 submodule update: remove never-used expansion
In reply to Glen Choo via GitGitGadgetFrom: Glen Choo <[email protected]>
The prefix variable is never set, so this conditional expansion is always '' (which does nothing).
--- git-submodule.sh | 1 - 1 file changed, 1 deletion(-)
git-submodule.sh +0 -1
@@ -238,7 +238,6 @@ cmd_update() { git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${prefix:+--recursive-prefix "$prefix"} \ "$@" }
Signature · 1 line
gitgitgadget
PATCH 6/8 submodule update: remove -v, pass --quiet
In reply to Glen Choo via GitGitGadgetFrom: Glen Choo <[email protected]>
In cmd_update(), "-v" unsets GIT_QUIET, but this does nothing because GIT_QUIET is only set when "-q|--quiet" is passed.
Remove "-v", and since "git submodule--helper update" already understands 'quiet' options, append them to opts. This makes GIT_QUIET obsolete, so remove it.
--- git-submodule.sh | 6 +----- t/t7406-submodule-update.sh | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-)
git-submodule.sh +1 -5
@@ -242,10 +242,7 @@ cmd_update() do case "$1" in -q|--quiet) - GIT_QUIET=1 - ;; - -v) - unset GIT_QUIET + opts="$opts $1" ;; --progress) opts="$opts $1"
@@ -339,7 +336,6 @@ cmd_update() done git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ - ${GIT_QUIET:+--quiet} \ ${wt_prefix:+--prefix "$wt_prefix"} \ ${prefix:+--recursive-prefix "$prefix"} \ $opts \
t/t7406-submodule-update.sh +1 -1
@@ -1074,7 +1074,7 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase' git submodule update --rebase --quiet >out 2>err && test_must_be_empty out && test_must_be_empty err && - git submodule update --rebase -v >out 2>err && + git submodule update --rebase >out 2>err && test_file_not_empty out && test_must_be_empty err )
Signature · 1 line
gitgitgadget
RFC PATCH 1/20 git-submodule.sh: remove unused sanitize_submodule_env()
In reply to Ævar Arnfjörð BjarmasonThe sanitize_submodule_env() function was last used in b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15), let's remove it.
This also allows us to remove clear_local_git_env() from git-sh-setup.sh. That function hasn't been documented in Documentation/git-sh-setup.sh, and since 14111fc4927 (git: submodule honor -c credential.* from command line, 2016-02-29) it had only been used in the sanitize_submodule_env() function being removed here.
--- git-sh-setup.sh | 7 ------- git-submodule.sh | 11 ----------- 2 files changed, 18 deletions(-)
git-sh-setup.sh +0 -7
@@ -285,13 +285,6 @@ get_author_ident_from_commit () { parse_ident_from_commit author AUTHOR } -# Clear repo-local GIT_* environment variables. Useful when switching to -# another repository (e.g. when entering a submodule). See also the env -# list in git_connect() -clear_local_git_env() { - unset $(git rev-parse --local-env-vars) -} - # Generate a virtual base file for a two-file merge. Uses git apply to # remove lines from $1 that are not in $2, leaving only common lines. create_virtual_base() {
git-submodule.sh +0 -11
@@ -56,17 +56,6 @@ isnumber() n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" } -# Sanitize the local git environment for use within a submodule. We -# can't simply use clear_local_git_env since we want to preserve some -# of the settings from GIT_CONFIG_PARAMETERS. -sanitize_submodule_env() -{ - save_config=$GIT_CONFIG_PARAMETERS - clear_local_git_env - GIT_CONFIG_PARAMETERS=$save_config - export GIT_CONFIG_PARAMETERS -} - # # Add a new submodule to the working tree, .gitmodules and the index #
Signature · 1 line
2.36.1.1178.gb5b1747c546
cover submodule: remove git-submodule.sh, create bare builtin/submodule.c
In reply to Glen Choo via GitGitGadgetQuoted 4 lines · Glen Choo via GitGitGadget
As a follow up to ar/submodule-update [1] and its successors gc/submodule-update-part* [2] [3], this series converts the last remaining piece of "git submodule update" into C, namely, the option parsing in
git-submodule.sh.
Aside at the end at [2].
Quoted 20 lines
As a result, git-submodule.sh::cmd_update() is now an (almost) one-liner:
cmd_update(){ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update ${wt_prefix:+--prefix "$wt_prefix"}
"$@" }and best of all, "git submodule update" now shows a usage string for its own subcommand instead of a giant usage string for all of "git submodule" :)
Given how many options "git submodule update" accepts, this series takes a gradual approach:
1. Create a variable opts, which holds the literal options we want to pass to "git submodule--helper update". Then, for each option...
2. If "git submodule--helper update" already understands the string option, append it to opts and remove any special handling (1-3/8).
3. Otherwise, if the option makes sense, teach "git submodule--helper update" to understand the option. Goto 2. (4-5/8).
4. Otherwise, if the option makes no sense, drop it (6/8).
5. When we've processed all options, delete all the option parsing code
Quoted 1 line
(7/8) and clean up (8/8).
That's quite the timing coincidence. I hacked this up yesterday, thinking that the submodule topic had been too quiet for a while, and wondering how hard it was to convert the rest of git-submodule.sh.
It's more than 2x the length of yours, but gets to the point where we can "git rm git-submodule.sh".
Some brief comparison/commentary:
Quoted 4 lines
Glen Choo (8):
submodule update: remove intermediate parsing submodule update: pass options containing "[no-]" submodule update: pass options with stuck forms
Yeah, this is the alternate approach I considered and ended up discarding. I.e. to make forward progress with migrating things away from the cmd_*() functions you either have to prepare things in advance and then sweep the rug from under them in one go.
Or, as you're doing here teaching them about the options they're not-really-parsing anymore, but must know about because they're in a loop that ends with a "if unknown option, usage".
Quoted 1 line
submodule update: pass --require-init and --init
Almost the same as my 12/20.
Quoted 1 line
submodule--helper update: use one param per type
Same as my 13/20, but I ended up doing it in a more narrow/smaller way. I tried your way and ran into some bug, then figured I'd do it more narrowly instead of debugging it.
Quoted 1 line
submodule update: remove -v, pass --quiet
Hrm, so we don't need it at all then. Well, that's a bit simpler than my 1[45]/20 and 17/20 :)
So yeah, definitely RFC-quality, but I ran into that one test that used -v, and then saw the missing docs etc. But no cheating, so I've left it in :)
I do wonder if we should leave it in anyway, we never documented -v, but we *did* understand it, and if you look at:
git log -p -Gsay -- git-submodule.sh
We used to have a lot more code impacted by it, but looking at this again now it would have only been for users of command-lines like:
git submodule --quiet update -v [...]
I.e. where we already set the flag to the non-default quiet, and then used -v to flip it.
I think at this point I've talked myself into "let's just remove it", but maybe...
Quoted 1 line
submodule update: stop parsing options in .sh
Same effect as my 16/20, but it's the last one I converted, the cmd_update() case being the trickiest.
Quoted 1 line
submodule update: remove never-used expansion
Same as my 02/20, but as seen there I think you missed several "prefix" non-uses.
Brief commentary on my patches, details in commit messages:
Ævar Arnfjörð Bjarmason (20):
git-submodule.sh: remove unused sanitize_submodule_env() git-submodule.sh: remove unused $prefix variable git-submodule.sh: remove unused --super-prefix logic
I removed a bit more dead code here than yours.
git-submodule.sh: normalize parsing of "--branch" git-submodule.sh: normalize parsing of --cached
This & various other prep commits (hereafter "easy prep") make subsequent one-time conversions of whole cmd_*() easier.
submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" git-submodule.sh: create a "case" dispatch statement
easy prep
submodule--helper: pretend to be "git submodule" in "-h" output
easy prep & bug fix for existing (on master) output bugs.
git-submodule.sh: dispatch "sync" to helper
git-submodule.sh: dispatch directly to helper
git-submodule.sh: dispatch "foreach" to helper
These are easy conversions as the options 1=1 map after the above prep.
submodule--helper: have --require-init imply --init
submodule--helper: understand --checkout, --merge and --rebase
synonyms
git-submodule doc: document the -v" option to "update"
submodule--helper: understand -v option for "update"not-so-easy prep for "cmd_update()"
git-submodule.sh: dispatch "update" to helper
Full cmd_update() migration in one go.
git-submodule.sh: use "$quiet", not "$GIT_QUIET"
"easy prep", but this one is less overall churn if done at the end, but as noted above could/should maybe be dropped entirely.
git-submodule.sh: simplify parsing loop
Not really needed, but I wanted to get the code as close to minimal for the next step, to eyeball the resulting sh v.s. C version.
submodule: make it a built-in, remove git-submodule.sh
We now have a builtin/submodule.c *and* the current builtin/submodule--helper.c, and we even dispatch to "git submodule--helper" via run_command()!
The idea is to be as close as possible to a bug-for-bug implementation of the shellscript, and that reviewers should be confident in being able to trace what commands we invoked before/after, we're invoking the same "git submodule--helper" commands.
Of course we eventually want to get to some full union of builtin/submodule{,--helper}.c, but that can wait.
submodule: add a subprocess-less submodule.useBuiltin setting
Wait, a useBuiltin setting to switch between two built-ins? Yeah, maybe it makes little sense, but here we get rid of the run_command() overhead, and could generally use the built-in to experiment with deeper integration between the two.
Performance is around ~2x faster with the "real" built-in than the run_command() version, whic hin turn is more than 6x as fast on basic overhead than the shellscript version, to the extent that anyone cares about "git submodule" overhead. See [1] at the end for a benchmark.
That last change adds a CI target for GIT_TEST_SUBMODULE_USE_BUILTIN=true, full CI run here:
https://github.com/avar/git/actions/runs/2472131257
Documentation/config/submodule.txt | 4 + Documentation/git-submodule.txt | 8 +- Makefile | 2 +- builtin.h | 1 + builtin/submodule--helper.c | 118 +++--- builtin/submodule.c | 169 ++++++++ ci/run-build-and-tests.sh | 1 + git-sh-setup.sh | 7 - git-submodule.sh | 637 ----------------------------- git.c | 1 + submodule.c | 2 +- t/README | 4 + 12 files changed, 255 insertions(+), 699 deletions(-) create mode 100644 builtin/submodule.c delete mode 100755 git-submodule.sh
1. GIT_TEST_SUBMODULE_USE_BUILTIN=true git hyperfine -L rev origin/master,HEAD~0 -L v false,true -s 'make CFLAGS=-O3' 'GIT_TEST_SUBMODULE_USE_BUILTIN={v} ./git --exec-path=$PWD submodule status' -r 20 Benchmark 1: GIT_TEST_SUBMODULE_USE_BUILTIN=false ./git --exec-path=$PWD submodule status' in 'origin/master
Time (mean ± σ): 40.9 ms ± 0.3 ms [User: 33.3 ms, System: 9.7 ms] Range (min … max): 40.2 ms … 41.5 ms 20 runs
Benchmark 2: GIT_TEST_SUBMODULE_USE_BUILTIN=false ./git --exec-path=$PWD submodule status' in 'HEAD~0
Time (mean ± σ): 12.4 ms ± 0.1 ms [User: 9.9 ms, System: 2.5 ms] Range (min … max): 12.2 ms … 12.7 ms 20 runs
Benchmark 3: GIT_TEST_SUBMODULE_USE_BUILTIN=true ./git --exec-path=$PWD submodule status' in 'origin/master
Time (mean ± σ): 40.9 ms ± 0.5 ms [User: 35.6 ms, System: 7.2 ms] Range (min … max): 40.1 ms … 41.8 ms 20 runs
Benchmark 4: GIT_TEST_SUBMODULE_USE_BUILTIN=true ./git --exec-path=$PWD submodule status' in 'HEAD~0
Time (mean ± σ): 6.4 ms ± 0.1 ms [User: 3.9 ms, System: 2.5 ms]
Range (min … max): 6.3 ms … 6.6 ms 20 runs
Summary
'GIT_TEST_SUBMODULE_USE_BUILTIN=true ./git --exec-path=$PWD submodule status' in 'HEAD~0' ran
1.94 ± 0.03 times faster than 'GIT_TEST_SUBMODULE_USE_BUILTIN=false ./git --exec-path=$PWD submodule status' in 'HEAD~0'
6.40 ± 0.11 times faster than 'GIT_TEST_SUBMODULE_USE_BUILTIN=true ./git --exec-path=$PWD submodule status' in 'origin/master'
6.40 ± 0.10 times faster than 'GIT_TEST_SUBMODULE_USE_BUILTIN=false ./git --exec-path=$PWD submodule status' in 'origin/master'2. Aside: I don't think these ever made it on-list but Atharva's version of what we're trying to do here is at:
https://github.com/tfidfwastaken/git/tree/submodule-make-builtin-2
I'd looked those over at some distant point in the past, and skimmed them again yesterday, but thought they were too much all-at-once to be confident in testing it myself, hence coming up with this alternate & smaller approach.
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 2/20 git-submodule.sh: remove unused $prefix variable
Remove the $prefix variable which is never set, and never resulted in an option being passed to our "git submodule--helper". The --recursive-prefix option to "git submodule--helper" is still used, but only when it invokes itself.
--- git-submodule.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
git-submodule.sh +2 -4
@@ -41,7 +41,6 @@ files= remote= nofetch= update= -prefix= custom_name= depth= progress=
@@ -127,7 +126,7 @@ cmd_add() usage fi - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } #
@@ -189,7 +188,7 @@ cmd_init() shift done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" } #
@@ -346,7 +345,6 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 4/20 git-submodule.sh: normalize parsing of "--branch"
In reply to Ævar Arnfjörð BjarmasonIn 5c08dbbdf1a (git-submodule: fix subcommand parser, 2008-01-15) the "--branch" option was supported as an option to "git submodule" itself, i.e. "git submodule --branch" as a side-effect of its implementation.
Then in b57e8119e6e (submodule: teach set-branch subcommand, 2019-02-08) when the "set-branch" subcommand was added the assertion that we shouldn't have "--branch" anywhere except as an argument to "add" and "set-branch" was copy/pasted from the adjacent check for "--cache" added (or rather modified) in 496eeeb19b9 (git-submodule.sh:
avoid "test <cond> -a/-o <cond>", 2014-06-10).
But there's been a logic error in that check, this looked like it should be supporting:
git submodule --branch <branch> (add | set-branch) [<options>]
But due to "||" in the condition (as opposed to "&&" for "--cache") if we have "--branch" here already we'll emit usage, even for "add" and "set-branch".
Since nobody's complained about "--branch <branch>" not being supported as argument to "git submodule" itself, i.e. we want to support:
git submodule (add | set-branch) --branch <branch> [<options>]
But not the first form noted above. Let's just remove this code, we've never documented "--branch" as a top-level option (unlike "--quiet"), so this looks like it was an accident of the implementation, which we broke v2.22.0, so we also know it must not have been important to anyone.
--- git-submodule.sh | 14 -------------- 1 file changed, 14 deletions(-)
git-submodule.sh +0 -14
@@ -574,14 +574,6 @@ do -q|--quiet) GIT_QUIET=1 ;; - -b|--branch) - case "$2" in - '') - usage - ;; - esac - branch="$2"; shift - ;; --cached) cached="$1" ;;
@@ -609,12 +601,6 @@ then fi fi -# "-b branch" is accepted only by "add" and "set-branch" -if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) -then - usage -fi - # "--cached" is accepted only by "status" and "summary" if test -n "$cached" && test "$command" != status && test "$command" != summary then
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 3/20 git-submodule.sh: remove unused --super-prefix logic
In reply to Ævar Arnfjörð BjarmasonThe "$prefix" variable has not been set since b3c5f5cb048 (submodule:
move core cmd_update() logic to C, 2022-03-15), so we'd never pass the --super-prefix option to "git submodule--helper", and can therefore remove the handling of it from builtin/submodule--helper.c as well.
--- builtin/submodule--helper.c | 53 +++++++++++++++---------------------- 1 file changed, 22 insertions(+), 31 deletions(-)
builtin/submodule--helper.c +22 -31
@@ -3364,35 +3364,32 @@ 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)
@@ -3401,15 +3398,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 ]);
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 5/20 git-submodule.sh: normalize parsing of --cached
In reply to Ævar Arnfjörð BjarmasonRemove the assignment of "$1" to the "$cached" variable. As seen in the initial implementation in 70c7ac22de6 (Add git-submodule command, 2007-05-26) we only need to keep track of if we've seen the --cached option. In 28f9af5d25e (git-submodule summary: code framework, 2008-03-11) "$1" was assigned to it, but there was no reason to do so. Let's undo that.
--- git-submodule.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
git-submodule.sh +2 -2
@@ -446,7 +446,7 @@ cmd_summary() { do case "$1" in --cached) - cached="$1" + cached=1 ;; --files) files="$1"
@@ -575,7 +575,7 @@ do GIT_QUIET=1 ;; --cached) - cached="$1" + cached=1 ;; --) break
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 6/20 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
In reply to Ævar Arnfjörð BjarmasonRename the "absorb-git-dirs" subcommand to "absorbgitdirs", which is what the "git submodule" command itself has called it since the subcommand was implemented in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12).
Having these two be different will make it more tedious to dispatch to "git submodule--helper" directly, so let's get rid of this needless inconsistency.
--- builtin/submodule--helper.c | 4 ++-- git-submodule.sh | 2 +- submodule.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/submodule--helper.c +2 -2
@@ -2784,7 +2784,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorb-git-dirs [<options>] [<path>...]" ), +N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -3383,7 +3383,7 @@ 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},
git-submodule.sh +1 -1
@@ -556,7 +556,7 @@ cmd_sync() cmd_absorbgitdirs() { - git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" + git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@" } # This loop parses the command line arguments to find the
submodule.c +1 -1
@@ -2374,7 +2374,7 @@ void absorb_git_dir_into_superproject(const char *path, cp.no_stdin =1 ;strvec_pushl (&cp.args,"--super-prefix" , sb.buf,"submodule--helper" , -"absorb-git-dirs" ,NULL ); +"absorbgitdirs" ,NULL );prepare_submodule_repo_env (&cp.env_array);if (run_command (&cp))die (_ ("could not recurse into submodule '%s'" ), path);
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 7/20 git-submodule.sh: create a "case" dispatch statement
In reply to Ævar Arnfjörð BjarmasonCreate a "case/esac" dispatch statement at the end of git-submodule.sh and move the contents of the trivial cmd_absorbgitdirs() function to it.
This template will be expanded on in subsequent commits, but for now we're moving the trivial "git submodule absorb-git-dirs" to it.
--- git-submodule.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
git-submodule.sh +8 -6
@@ -554,11 +554,6 @@ cmd_sync() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" } -cmd_absorbgitdirs() -{ - git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@" -} - # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific # options are primarily done by the subcommand implementations.
@@ -607,4 +602,11 @@ then usage fi -"cmd_$(echo $command | sed -e s/-/_/g)" "$@" +case "$command" in +absorbgitdirs) + git submodule--helper "$command" --prefix "$wt_prefix" "$@" + ;; +*) + "cmd_$(echo $command | sed -e s/-/_/g)" "$@" + ;; +esac
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 9/20 git-submodule.sh: dispatch "sync" to helper
In reply to Ævar Arnfjörð BjarmasonRemove the cmd_sync() wrapper for "git submodule--helper sync" in favor of dispatching the raw command-line directly to the helper.
At this point we've already parsed out the optional "--quiet" flag that we need to support for "git submodule --quiet" (as opposed to "git submodule <subcommand> --quiet").
This changes the output we'll display on invalid usage for the better, before this we'd emit e.g.:
$ git submodule sync --blah usage: git submodule [--quiet] [--cached] or: [...many lines of "or" usage omitted...]
But now we'll emit the much more useful:
$ git submodule sync --blah error: unknown option `blah' usage: git submodule sync [--quiet] [--recursive] [<path>]
-q, --quiet suppress output of synchronizing submodule url
--recursive recurse into nested submodules
This is because we'll now get as far as module_sync()'s failing call to parse_options() when we have invalid usage.
--- git-submodule.sh | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-)
git-submodule.sh +4 -33
@@ -520,39 +520,6 @@ cmd_status() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" } -# -# Sync remote urls for submodules -# This makes the value for remote.$remote.url match the value -# specified in .gitmodules. -# -cmd_sync() -{ - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - GIT_QUIET=1 - shift - ;; - --recursive) - recursive=1 - shift - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" -} # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific
@@ -606,6 +573,10 @@ case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; +sync) + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ + ${GIT_QUIET:+--quiet} "$@" + ;; *) "cmd_$(echo $command | sed -e s/-/_/g)" "$@" ;;
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 8/20 submodule--helper: pretend to be "git submodule" in "-h" output
In reply to Ævar Arnfjörð BjarmasonChange the usage output for "git submodule--helper" so that it will pretend to be named "git submodule". This will allow us to dispatch further into "git submodule--helper" from git-submodule.sh while emitting the correct usage output.
This fixes a bug that's been there ever since "git submodule absorbgitdirs" was added in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12). Before this we'd emit e.g. this on invalid usage:
$ git submodule absorbgitdirs --blah error: unknown option `blah' usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
Now we'll emit the same, except that the usage line is now referring to the correct command run by the user:
usage: git submodule absorbgitdirs [<options>] [<path>...] [.. same usage output ...]
Note that in the case of "status", "deinit" and "update" we were already referring to ourselves as "git submodule" in builtin/submodule--helper.c.
--- builtin/submodule--helper.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
builtin/submodule--helper.c +16 -16
@@ -286,7 +286,7 @@ static int module_list(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper list [--prefix=<path>] [<path>...]" ), +N_ ("git submodule list [--prefix=<path>] [<path>...]" ),NULL };
@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper foreach [--quiet] [--recursive] [--] <command>" ), +N_ ("git submodule foreach [--quiet] [--recursive] [--] <command>" ),NULL };
@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper init [<options>] [<path>]" ), +N_ ("git submodule init [<options>] [<path>]" ),NULL };
@@ -786,7 +786,7 @@ static int module_name(int argc, const char **argv, const char *prefix)const struct submodule *sub;if (argc !=2 ) -usage (_ ("git submodule--helper name <path>" )); +usage (_ ("git submodule name <path>" )); sub =submodule_from_path (the_repository,null_oid (), argv[1 ]);
@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper summary [<options>] [<commit>] [--] [<path>]" ), +N_ ("git submodule summary [<options>] [<commit>] [--] [<path>]" ),NULL };
@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper sync [--quiet] [--recursive] [<path>]" ), +N_ ("git submodule sync [--quiet] [--recursive] [<path>]" ),NULL };
@@ -1789,7 +1789,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper clone [--prefix=<path>] [--quiet] " +N_ ("git submodule clone [--prefix=<path>] [--quiet] " "[--reference <repository>] [--name <name>] [--depth <depth>] " "[--single-branch] [--filter <filter-spec>] " "--url <url> --path <path>" ),
@@ -2784,7 +2784,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ), +N_ ("git submodule absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -2848,9 +2848,9 @@ static int module_config(int argc, const char **argv, const char *prefix) OPT_END() };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper config <name> [<value>]" ), -N_ ("git submodule--helper config --unset <name>" ), -"git submodule--helper config --check-writeable" , +N_ ("git submodule config <name> [<value>]" ), +N_ ("git submodule config --unset <name>" ), +"git submodule config --check-writeable" ,NULL };
@@ -2889,7 +2889,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-url [--quiet] <path> <newurl>" ), +N_ ("git submodule set-url [--quiet] <path> <newurl>" ),NULL };
@@ -2928,8 +2928,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>" ), -N_ ("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-d|--default) <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ),NULL };
@@ -2970,7 +2970,7 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ), +N_ ("git submodule create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ),NULL };
@@ -3273,7 +3273,7 @@ static int module_add(int argc, const char **argv, const char *prefix) };const char *const usage[] = { -N_ ("git submodule--helper add [<options>] [--] <repository> [<path>]" ), +N_ ("git submodule add [<options>] [--] <repository> [<path>]" ),NULL };
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 10/20 git-submodule.sh: dispatch directly to helper
In reply to Ævar Arnfjörð BjarmasonChange the dispatching logic in "git-submodule.sh" for the "add", "init", "deinit", "set-branch", "set-url", "summary" and "status" sub-commands to do away with the argument parsing in git-submodule.sh, and instead dispatch directly to "git submodule--helper".
As in a preceding commit the only functional change here should be that on invalid options we'll now emit more targeted "-h" output.
The isnumber() helper function was only used in the now-removed cmd_summary(), the same goes for the $files variable. The $custom_name and $branch variables were only used in cmd_add().
Since there are no dashed commands anymore in git-submodule.sh we can get rid of the "$(echo | sed ...)" one-liner to change e.g. "set-url" to "set_url".
--- git-submodule.sh | 321 +---------------------------------------------- 1 file changed, 5 insertions(+), 316 deletions(-)
git-submodule.sh +5 -316
@@ -30,18 +30,15 @@ GIT_PROTOCOL_FROM_USER=0 export GIT_PROTOCOL_FROM_USER command= -branch= force= reference= cached= recursive= init= require_init= -files= remote= nofetch= update= -custom_name= depth= progress= dissociate=
@@ -50,86 +47,7 @@ jobs= recommend_shallow= filter= -isnumber() -{ - n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" -} - -# -# Add a new submodule to the working tree, .gitmodules and the index -# -# $@ = repo path -# -# optional branch is stored in global branch variable -# -cmd_add() -{ - # parse $args after "submodule ... add". - reference_path= - while test $# -ne 0 - do - case "$1" in - -b | --branch) - case "$2" in '') usage ;; esac - branch=$2 - shift - ;; - -f | --force) - force=$1 - ;; - -q|--quiet) - GIT_QUIET=1 - ;; - --progress) - progress=1 - ;; - --reference) - case "$2" in '') usage ;; esac - reference_path=$2 - shift - ;; - --reference=*) - reference_path="${1#--reference=}" - ;; - --dissociate) - dissociate=1 - ;; - --name) - case "$2" in '') usage ;; esac - custom_name=$2 - shift - ;; - --depth) - case "$2" in '') usage ;; esac - depth="--depth=$2" - shift - ;; - --depth=*) - depth=$1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - if test -z "$1" - then - usage - fi - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" -} -# # Execute an arbitrary command sequence in each checked out # submodule #
@@ -160,73 +78,6 @@ cmd_foreach() git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" } -# -# Register submodules in .git/config -# -# $@ = requested paths (default to all) -# -cmd_init() -{ - # parse $args after "submodule ... init". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - GIT_QUIET=1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" -} - -# -# Unregister submodules from .git/config and remove their work tree -# -cmd_deinit() -{ - # parse $args after "submodule ... deinit". - deinit_all= - while test $# -ne 0 - do - case "$1" in - -f|--force) - force=$1 - ;; - -q|--quiet) - GIT_QUIET=1 - ;; - --all) - deinit_all=t - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" -} - # # Update each submodule path to correct revision, using clone and checkout as needed #
@@ -359,168 +210,6 @@ cmd_update() "$@" } -# -# Configures a submodule's default branch -# -# $@ = requested path -# -cmd_set_branch() { - default= - branch= - - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - # we don't do anything with this but we need to accept it - ;; - -d|--default) - default=1 - ;; - -b|--branch) - case "$2" in '') usage ;; esac - branch=$2 - shift - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" -} - -# -# Configures a submodule's remote url -# -# $@ = requested path, requested url -# -cmd_set_url() { - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - GIT_QUIET=1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@" -} - -# -# Show commit summary for submodules in index or working tree -# -# If '--cached' is given, show summary between index and given commit, -# or between working tree and given commit -# -# $@ = [commit (default 'HEAD'),] requested paths (default all) -# -cmd_summary() { - summary_limit=-1 - for_status= - diff_cmd=diff-index - - # parse $args after "submodule ... summary". - while test $# -ne 0 - do - case "$1" in - --cached) - cached=1 - ;; - --files) - files="$1" - ;; - --for-status) - for_status="$1" - ;; - -n|--summary-limit) - summary_limit="$2" - isnumber "$summary_limit" || usage - shift - ;; - --summary-limit=*) - summary_limit="${1#--summary-limit=}" - isnumber "$summary_limit" || usage - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary ${files:+--files} ${cached:+--cached} ${for_status:+--for-status} ${summary_limit:+-n $summary_limit} -- "$@" -} -# -# List all submodules, prefixed with: -# - submodule not initialized -# + different revision checked out -# -# If --cached was specified the revision in the index will be printed -# instead of the currently checked out revision. -# -# $@ = requested paths (default to all) -# -cmd_status() -{ - # parse $args after "submodule ... status". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - GIT_QUIET=1 - ;; - --cached) - cached=1 - ;; - --recursive) - recursive=1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" -} - # This loop parses the command line arguments to find the # subcommand name to dispatch. Parsing of the subcommand specific # options are primarily done by the subcommand implementations.
@@ -573,11 +262,11 @@ case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; -sync) - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ - ${GIT_QUIET:+--quiet} "$@" +foreach | update) + "cmd_$command" "$@" ;; -*) - "cmd_$(echo $command | sed -e s/-/_/g)" "$@" +add | init | deinit | set-branch | set-url | status | summary | sync) + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ + ${GIT_QUIET:+--quiet} ${cached:+--cached} "$@" ;; esac
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 12/20 submodule--helper: have --require-init imply --init
In reply to Ævar Arnfjörð BjarmasonAdjust code added in 0060fd1511b (clone --recurse-submodules: prevent name squatting on Windows, 2019-09-12) to have the internal --require-init option imply --init, rather than having "git-submodule.sh" add it implicitly.
--- builtin/submodule--helper.c | 5 ++++- git-submodule.sh | 1 - 2 files changed, 4 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +4 -1
@@ -2619,7 +2619,7 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"progress" , &opt.progress,N_ ("force cloning progress" )),OPT_BOOL (0 ,"require-init" , &opt.require_init, -N_ ("disallow cloning into non-empty directory" )), +N_ ("disallow cloning into non-empty directory, implies --init" )),OPT_BOOL (0 ,"single-branch" , &opt.single_branch,N_ ("clone only one branch, HEAD or --branch" )), OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
@@ -2643,6 +2643,9 @@ static int module_update(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, module_update_options, git_submodule_helper_usage,0 ); +if (opt.require_init) + opt.init =1 ; +if (filter_options.choice && !opt.init) {usage_with_options (git_submodule_helper_usage, module_update_options);
git-submodule.sh +0 -1
@@ -71,7 +71,6 @@ cmd_update() init=1 ;; --require-init) - init=1 require_init=1 ;; --remote)
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 11/20 git-submodule.sh: dispatch "foreach" to helper
In reply to Ævar Arnfjörð BjarmasonDispatch the "git submodule foreach" command directly to "git submodule--helper foreach". This case requires the addition of the PARSE_OPT_STOP_AT_NON_OPTION flag, since the shellscript was unconditionally adding "--" to the "git submodule--helper" command-line.
--- builtin/submodule--helper.c | 3 ++- git-submodule.sh | 37 +++---------------------------------- 2 files changed, 5 insertions(+), 35 deletions(-)
builtin/submodule--helper.c +2 -1
@@ -449,7 +449,8 @@ static int module_foreach(int argc, const char **argv, const char *prefix) }; argc =parse_options (argc, argv, prefix, module_foreach_options, - git_submodule_helper_usage,0 ); + git_submodule_helper_usage, +PARSE_OPT_STOP_AT_NON_OPTION );if (module_list_compute (0 ,NULL , prefix, &pathspec, &list) <0 )return 1 ;
git-submodule.sh +3 -34
@@ -47,37 +47,6 @@ jobs= recommend_shallow= filter= - -# Execute an arbitrary command sequence in each checked out -# submodule -# -# $@ = command to execute -# -cmd_foreach() -{ - # parse $args after "submodule ... foreach". - while test $# -ne 0 - do - case "$1" in - -q|--quiet) - GIT_QUIET=1 - ;; - --recursive) - recursive=1 - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" -} - # # Update each submodule path to correct revision, using clone and checkout as needed #
@@ -262,10 +231,10 @@ case "$command" in absorbgitdirs) git submodule--helper "$command" --prefix "$wt_prefix" "$@" ;; -foreach | update) - "cmd_$command" "$@" +update) + cmd_update "$@" ;; -add | init | deinit | set-branch | set-url | status | summary | sync) +add | foreach | init | deinit | set-branch | set-url | status | summary | sync) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ ${GIT_QUIET:+--quiet} ${cached:+--cached} "$@" ;;
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 15/20 submodule--helper: understand -v option for "update"
In reply to Ævar Arnfjörð BjarmasonChange the "OPT__QUIET()" in module_update() to use OPT__VERBOSITY() instead. This is in preparation for passing the command in "git-submodule.sh" to "git submodule update" directly.
Note that this implementation supports the "--verbose" synonym for "-v", but "git-submodule.sh" does not. Once we make the switch to calling "git submodule--helper update" directly we should update the documentation to reflect that.
--- builtin/submodule--helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +6 -2
@@ -2584,6 +2584,7 @@ static int module_update(int argc, const char **argv, const char *prefix)struct list_objects_filter_options filter_options;int ret;enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ; +int verbosity =0 ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2625,7 +2626,7 @@ static int module_update(int argc, const char **argv, const char *prefix) N_("parallel jobs")),OPT_BOOL (0 ,"recommend-shallow" , &opt.recommend_shallow,N_ ("whether the initial clone should follow the shallow recommendation" )), -OPT__QUIET (&opt.quiet,N_ ("don't print cloning progress" )), +OPT__VERBOSITY (&verbosity),OPT_BOOL (0 ,"progress" , &opt.progress,N_ ("force cloning progress" )), OPT_BOOL(0, "require-init", &opt.require_init,
@@ -2637,7 +2638,7 @@ static int module_update(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { - N_("git submodule [--quiet] update" + N_("git submodule [--quiet] update [-v | --verbose]" " [--init [--filter=<filter-spec>]] [--remote]" " [-N|--no-fetch] [-f|--force]" " [--checkout|--merge|--rebase]"
@@ -2656,6 +2657,9 @@ static int module_update(int argc, const char **argv, const char *prefix)if (opt.require_init) opt.init =1 ; +if (verbosity <0 ) + opt.quiet =1 ; +if (filter_options.choice && !opt.init) {usage_with_options (git_submodule_helper_usage, module_update_options);
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 14/20 git-submodule doc: document the -v" option to "update"
In reply to Ævar Arnfjörð BjarmasonIn e84c3cf3dc3 (git-submodule.sh: accept verbose flag in cmd_update to be non-quiet, 2018-08-14) the "git submodule update" sub-command was made to understand "-v" for "don't be quiet" (but not "--verbose"). Let's update the documentation to reflect this.
--- Documentation/git-submodule.txt | 7 +++++-- git-submodule.sh | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-)
Documentation/git-submodule.txt +5 -2
@@ -14,7 +14,7 @@ SYNOPSIS 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...] 'git submodule' [--quiet] init [--] [<path>...] 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...) -'git submodule' [--quiet] update [<options>] [--] [<path>...] +'git submodule' [--quiet] update [-v] [<options>] [--] [<path>...] 'git submodule' [--quiet] set-branch [<options>] [--] <path> 'git submodule' [--quiet] set-url [--] <path> <newurl> 'git submodule' [--quiet] summary [<options>] [--] [<path>...]
@@ -133,7 +133,7 @@ If you really want to remove a submodule from the repository and commit that use linkgit:git-rm[1] instead. See linkgit:gitsubmodules[7] for removal options. -update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--filter <filter spec>] [--] [<path>...]:: +update [-v] [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--filter <filter spec>] [--] [<path>...]:: + -- Update the registered submodules to match what the superproject
@@ -270,6 +270,9 @@ OPTIONS --quiet:: Only print error messages. +-v:: + Don't be quiet. This option is only valid for the update command. + --progress:: This option is only valid for add and update commands. Progress status is reported on the standard error stream
git-submodule.sh +1 -1
@@ -10,7 +10,7 @@ USAGE="[--quiet] [--cached] or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...] or: $dashless [--quiet] init [--] [<path>...] or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...) - or: $dashless [--quiet] update [--init [--filter=<filter-spec>]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...] + or: $dashless [--quiet] update [-v] [--init [--filter=<filter-spec>]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--[no-]single-branch] [--] [<path>...] or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path> or: $dashless [--quiet] set-url [--] <path> <newurl> or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 18/20 git-submodule.sh: simplify parsing loop
In reply to Ævar Arnfjörð BjarmasonSimplify the parsing loop so that we don't try to find out the "$command" when looping over arguments initially, we'll only look for the --quiet and --cached options.
Then if we have no more arguments we default to "status", otherwise we emit our usage info. Most importantly we don't need to give --cache to only "status" and "summary", instead we trust that "submodule--helper" is checking those arguments, if some subcommands don't them they can emit their own errors.
--- git-submodule.sh | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-)
git-submodule.sh +17 -27
@@ -29,50 +29,40 @@ cd_to_toplevel GIT_PROTOCOL_FROM_USER=0 export GIT_PROTOCOL_FROM_USER -command= quiet= cached= -while test $# != 0 && test -z "$command" +while test $# != 0 do case "$1" in - add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) - command=$1 - ;; -q|--quiet) - quiet=1 + quiet=1 && + shift ;; --cached) - cached=1 - ;; - --) - break - ;; - -*) - usage + cached=1 && + shift ;; *) break ;; esac - shift done # No command word defaults to "status" -if test -z "$command" +command= +if test $# = 0 then - if test $# = 0 - then command=status - else - usage - fi -fi - -# "--cached" is accepted only by "status" and "summary" -if test -n "$cached" && test "$command" != status && test "$command" != summary -then - usage +else + case "$1" in + add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs) + command=$1 && + shift + ;; + *) + usage + esac fi case "$command" in
@@ -83,7 +73,7 @@ update) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ ${quiet:+--quiet} ${wt_prefix:+--prefix "$wt_prefix"} "$@" ;; -add | foreach | init | deinit | set-branch | set-url | status | summary | sync) +*) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ ${quiet:+--quiet} ${cached:+--cached} "$@" ;;
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 20/20 submodule: add a subprocess-less submodule.useBuiltin setting
In reply to Ævar Arnfjörð BjarmasonAdd an experimental setting to avoid the subprocess invocation of "git submodule--helper", instead we'll call cmd_submodule__helper() directly.
--- Documentation/config/submodule.txt | 4 ++++ builtin/submodule.c | 35 ++++++++++++++++++++++++++++-- ci/run-build-and-tests.sh | 1 + t/README | 4 ++++ 4 files changed, 42 insertions(+), 2 deletions(-)
Documentation/config/submodule.txt +4 -0
@@ -79,6 +79,10 @@ setting. * `branch` is supported only if `submodule.propagateBranches` is enabled +submodule.useBuiltin:: + Set to `true` to use a faster but possibly less stable subprocess-less + implementation of linkgit:git-submodule[1]. Is `false` by default. + submodule.propagateBranches:: [EXPERIMENTAL] A boolean that enables branching support when using `--recurse-submodules` or `submodule.recurse=true`.
builtin/submodule.c +33 -2
@@ -6,6 +6,7 @@#include "parse-options.h" #include "run-command.h" #include "strvec.h" +#include "config.h" #define BUILTIN_SUBMODULE_USAGE \ "git submodule [--quiet] [--cached]"
@@ -105,17 +106,33 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix,strvec_pushv (args, argv); } +static int get_use_builtin (void ) +{ +int v; + +if (git_env_bool ("GIT_TEST_SUBMODULE_USE_BUILTIN" ,0 )) + v =1 ; +else if (!git_config_get_bool ("submodule.usebuiltin" , &v)) + ; +else if (!git_config_get_bool ("feature.experimental" , &v)) + ; + +return v; +} +int cmd_submodule (int argc,const char **argv,const char *prefix) {int opt_quiet =0 ;int opt_cached =0 ;struct child_process cp =CHILD_PROCESS_INIT ; +struct strvec args =STRVEC_INIT ;struct option options[] = {OPT__QUIET (&opt_quiet,N_ ("be quiet" )),OPT_BOOL (0 ,"cached" , &opt_cached,N_ ("print the OID of submodules" )),OPT_END () }; +const int use_builtin =get_use_builtin ();int ret; argc = parse_options(argc, argv, prefix, options, git_submodule_usage,
@@ -125,14 +142,28 @@ int cmd_submodule(int argc, const char **argv, const char *prefix)* Tell the rest of git that any URLs we get don't come * directly from the user, so it can apply policy as appropriate. */ -strvec_push (&cp.env_array,"GIT_PROTOCOL_FROM_USER=0" ); +if (use_builtin) +xsetenv ("GIT_PROTOCOL_FROM_USER" ,"0" ,1 ); +else +strvec_push (&cp.env_array,"GIT_PROTOCOL_FROM_USER=0" ); +setup_helper_args (argc, argv, prefix, opt_quiet, opt_cached, - &cp.args); + use_builtin ? &args : &cp.args); + +if (use_builtin) { + ret =cmd_submodule__helper (args.nr, args.v, prefix); + goto cleanup; + } cp.git_cmd =1 ; cp.no_stdin =0 ;/* for git submodule foreach */ cp.dir = startup_info->original_cwd; ret =run_command (&cp); +cleanup: +if (!use_builtin) +/* TODO: Double free? */ +strvec_clear (&args); +return ret; }
ci/run-build-and-tests.sh +1 -0
@@ -27,6 +27,7 @@ linux-TEST-vars) export GIT_TEST_MULTI_PACK_INDEX=1 export GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=1 export GIT_TEST_ADD_I_USE_BUILTIN=0 + export GIT_TEST_SUBMODULE_USE_BUILTIN=1 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master export GIT_TEST_WRITE_REV_INDEX=1 export GIT_TEST_CHECKOUT_WORKERS=2
t/README +4 -0
@@ -423,6 +423,10 @@ GIT_TEST_ADD_I_USE_BUILTIN=<boolean>, when false, disables the built-in version of git add -i. See 'add.interactive.useBuiltin' in git-config(1). +GIT_TEST_SUBMODULE_USE_BUILTIN=<boolean>, when true, enables the +built-in subprocess-less invocation of "git submodule--helper". +See 'submodule.useBuiltin' in git-config(1). + GIT_TEST_INDEX_THREADS=<n> enables exercising the multi-threaded loading of the index for the whole test suite by bypassing the default number of cache entries and thread minimums. Setting this to 1 will make the
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 19/20 submodule: make it a built-in, remove git-submodule.sh
In reply to Ævar Arnfjörð BjarmasonReplace the now-trivial git-submodule.sh script with a built-in builtin/submodule.c. For now this new command is only a dumb dispatcher that uses run-command.c to invoke "git submodule--helper", just as "git-submodule.sh" used to do.
This is obviously not ideal, and we should follow-up and merge the builtin/submodule--helper.c code into builtin/submodule.c, but doing it this way makes it easy to review that this new C implementation isn't doing anything more clever than the old shellscript implementation.
The "define BUILTIN_" macros will help with that, i.e. the usage information we emit can be merged with what builtin/submodule--helper.c is now emitting. See 8757b35d443 (commit-graph: define common usage with a macro, 2021-08-23) and 1e91d3faf6c (reflog: move "usage" variables and use macros, 2022-03-17) for prior art using this pattern.
The "(argc < 2 || !strcmp(argv[1], "-h"))" path at the top of cmd_submodule__helper() could now be a "(argc < 2)" if not for t0012-help.sh (which invokes all built-ins manually with "-h"). Let's leave it for now, eventually we'll consolidate the two.
--- Makefile | 2 +- builtin.h | 1 + builtin/submodule.c | 138 ++++++++++++++++++++++++++++++++++++++++++++ git-submodule.sh | 80 ------------------------- git.c | 1 + 5 files changed, 141 insertions(+), 81 deletions(-) create mode 100644 builtin/submodule.c delete mode 100755 git-submodule.sh
Makefile +1 -1
@@ -622,7 +622,6 @@ SCRIPT_SH += git-merge-resolve.sh SCRIPT_SH += git-mergetool.sh SCRIPT_SH += git-quiltimport.sh SCRIPT_SH += git-request-pull.sh -SCRIPT_SH += git-submodule.sh SCRIPT_SH += git-web--browse.sh SCRIPT_LIB += git-mergetool--lib
@@ -1213,6 +1212,7 @@ BUILTIN_OBJS += builtin/show-ref.o BUILTIN_OBJS += builtin/sparse-checkout.o BUILTIN_OBJS += builtin/stash.o BUILTIN_OBJS += builtin/stripspace.o +BUILTIN_OBJS += builtin/submodule.o BUILTIN_OBJS += builtin/submodule--helper.o BUILTIN_OBJS += builtin/symbolic-ref.o BUILTIN_OBJS += builtin/tag.o
builtin.h +1 -0
@@ -223,6 +223,7 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix);int cmd_status (int argc,const char **argv,const char *prefix);int cmd_stash (int argc,const char **argv,const char *prefix);int cmd_stripspace (int argc,const char **argv,const char *prefix); +int cmd_submodule (int argc,const char **argv,const char *prefix);int cmd_submodule__helper (int argc,const char **argv,const char *prefix);int cmd_switch (int argc,const char **argv,const char *prefix);int cmd_symbolic_ref (int argc,const char **argv,const char *prefix);
builtin/submodule.c new file +138 -0
138 lines not on this page · raw message
git-submodule.sh deleted +0 -80
80 lines not on this page · raw message
git.c +1 -0
@@ -609,6 +609,7 @@ static struct cmd_struct commands[] = { { "stash", cmd_stash, RUN_SETUP | NEED_WORK_TREE }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, { "stripspace", cmd_stripspace }, + { "submodule", cmd_submodule, RUN_SETUP | NEED_WORK_TREE }, { "submodule--helper", cmd_submodule__helper, RUN_SETUP | SUPPORT_SUPER_PREFIX | NO_PARSEOPT }, { "switch", cmd_switch, RUN_SETUP | NEED_WORK_TREE }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP },
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 17/20 git-submodule.sh: use "$quiet", not "$GIT_QUIET"
In reply to Ævar Arnfjörð BjarmasonRemove the use of the "$GIT_QUIET" variable in favor of our own "$quiet", ever since b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) we have not used the "say" function in git-sh-setup.sh, which is the only thing that's affected by using "GIT_QUIET".
We still want to support --quiet for our own use though, but let's use our own variable for that.
This change could have come before the preceding commits which removed cmd_*() functions from this file, but that would have been a much more verbose change. Since we were removing most of the uses of "$GIT_QUIET" this change comes after those.
--- git-submodule.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
git-submodule.sh +4 -3
@@ -30,6 +30,7 @@ GIT_PROTOCOL_FROM_USER=0 export GIT_PROTOCOL_FROM_USER command= +quiet= cached= while test $# != 0 && test -z "$command"
@@ -39,7 +40,7 @@ do command=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --cached) cached=1
@@ -80,10 +81,10 @@ absorbgitdirs) ;; update) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ - ${GIT_QUIET:+--quiet} ${wt_prefix:+--prefix "$wt_prefix"} "$@" + ${quiet:+--quiet} ${wt_prefix:+--prefix "$wt_prefix"} "$@" ;; add | foreach | init | deinit | set-branch | set-url | status | summary | sync) git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \ - ${GIT_QUIET:+--quiet} ${cached:+--cached} "$@" + ${quiet:+--quiet} ${cached:+--cached} "$@" ;; esac
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 13/20 submodule--helper: understand --checkout, --merge and --rebase synonyms
In reply to Ævar Arnfjörð BjarmasonUnderstand --checkout, --merge and --rebase synonyms for --update={checkout,merge,rebase}, as well as the short options that 'git submodule' itself understands.
This removes a difference between the CLI API of "git submodule" and "git submodule--helper", making it easier to make the latter an alias for the former. See 48308681b07 (git submodule update: have a dedicated helper for cloning, 2016-02-29) for the initial addition of --update.
--- builtin/submodule--helper.c | 17 +++++++++++++++++ git-submodule.sh | 14 +++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-)
builtin/submodule--helper.c +17 -0
@@ -2583,6 +2583,7 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; +enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2604,6 +2605,15 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_STRING (0 ,"update" , &opt.update_default,N_ ("string" ),N_ ("rebase, merge, checkout or none" )), +OPT_SET_INT (0 ,"checkout" , &update_type, +N_ ("use the 'checkout' update strategy (default)" ), +SM_UPDATE_CHECKOUT ), +OPT_SET_INT ('m' ,"merge" , &update_type, +N_ ("use the 'merge' update strategy" ), +SM_UPDATE_MERGE ), +OPT_SET_INT ('r' ,"rebase" , &update_type, +N_ ("use the 'rebase' update strategy" ), +SM_UPDATE_MERGE ),OPT_STRING_LIST (0 ,"reference" , &opt.references,N_ ("repo" ),N_ ("reference repository" )), OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2653,6 +2663,13 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; +if (update_type ==SM_UPDATE_CHECKOUT ) + opt.update_default ="checkout" ; +else if (update_type ==SM_UPDATE_MERGE ) + opt.update_default ="merge" ; +else if (update_type ==SM_UPDATE_REBASE ) + opt.update_default ="rebase" ; +if (opt.update_default)if (parse_submodule_update_strategy (opt.update_default, &opt.update_strategy) <0 )
git-submodule.sh +9 -5
@@ -38,7 +38,9 @@ init= require_init= remote= nofetch= -update= +rebase= +merge= +checkout= depth= progress= dissociate=
@@ -83,7 +85,7 @@ cmd_update() force=$1 ;; -r|--rebase) - update="rebase" + rebase=1 ;; --reference) case "$2" in '') usage ;; esac
@@ -97,13 +99,13 @@ cmd_update() dissociate=1 ;; -m|--merge) - update="merge" + merge=1 ;; --recursive) recursive=1 ;; --checkout) - update="checkout" + checkout=1 ;; --recommend-shallow) recommend_shallow="--recommend-shallow"
@@ -164,7 +166,9 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${update:+--update "$update"} \ + ${rebase:+--rebase} \ + ${merge:+--merge} \ + ${checkout:+--checkout} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \ ${depth:+"$depth"} \
Signature · 1 line
2.36.1.1178.gb5b1747c546
RFC PATCH 16/20 git-submodule.sh: dispatch "update" to helper
In reply to Ævar Arnfjörð BjarmasonDispatch the "update" command directly to "git submodule--helper update", rather than doing our own argument parsing in git-submodule.sh. As this is the last cmd_*() function to be removed from git-submodule.sh we can do some larger cleanup of that file as a result.
As noted in a preceding commit the only behavior change here should be the desirable change of better "-h" output, and that this implementation understands the "--verbose" synonym for "-v". Let's update the documentation to reflect the new "--verbose" synonym.
--- Documentation/git-submodule.txt | 5 +- git-submodule.sh | 159 +------------------------------- 2 files changed, 5 insertions(+), 159 deletions(-)
Documentation/git-submodule.txt +3 -2
@@ -14,7 +14,7 @@ SYNOPSIS 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...] 'git submodule' [--quiet] init [--] [<path>...] 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...) -'git submodule' [--quiet] update [-v] [<options>] [--] [<path>...] +'git submodule' [--quiet] update [-v | --verbose] [<options>] [--] [<path>...] 'git submodule' [--quiet] set-branch [<options>] [--] <path> 'git submodule' [--quiet] set-url [--] <path> <newurl> 'git submodule' [--quiet] summary [<options>] [--] [<path>...]
@@ -133,7 +133,7 @@ If you really want to remove a submodule from the repository and commit that use linkgit:git-rm[1] instead. See linkgit:gitsubmodules[7] for removal options. -update [-v] [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--filter <filter spec>] [--] [<path>...]:: +update [-v | --verbose] [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--filter <filter spec>] [--] [<path>...]:: + -- Update the registered submodules to match what the superproject
@@ -271,6 +271,7 @@ OPTIONS Only print error messages. -v:: +--verbose:: Don't be quiet. This option is only valid for the update command. --progress::
git-submodule.sh +2 -157
172 lines not on this page · raw message
Signature · 1 line
2.36.1.1178.gb5b1747c546
Re: [RFC PATCH 00/20] submodule: remove git-submodule.sh, create bare builtin/submodule.c
In reply to Ævar Arnfjörð BjarmasonQuoted 22 lines · Ævar Arnfjörð Bjarmason
Quoted 20 lines
As a result, git-submodule.sh::cmd_update() is now an (almost) one-liner:
cmd_update(){ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update ${wt_prefix:+--prefix "$wt_prefix"}
"$@" }and best of all, "git submodule update" now shows a usage string for its own subcommand instead of a giant usage string for all of "git submodule" :)
Given how many options "git submodule update" accepts, this series takes a gradual approach:
1. Create a variable opts, which holds the literal options we want to pass to "git submodule--helper update". Then, for each option...
2. If "git submodule--helper update" already understands the string option, append it to opts and remove any special handling (1-3/8).
3. Otherwise, if the option makes sense, teach "git submodule--helper update" to understand the option. Goto 2. (4-5/8).
4. Otherwise, if the option makes no sense, drop it (6/8).
5. When we've processed all options, delete all the option parsing codeQuoted 1 line
(7/8) and clean up (8/8).
Quoted 6 lines
That's quite the timing coincidence. I hacked this up yesterday, thinking that the submodule topic had been too quiet for a while, and wondering how hard it was to convert the rest of
git-submodule.sh.It's more than 2x the length of yours, but gets to the point where we can "git rm
git-submodule.sh".
Very cool. I've skimmed through all of the patches, which mostly look good except for ~1-2 things.
Your series shows that there isn't any prohibitively difficult work left to finish the conversion, which is great! The real problem IMO is the potential for mechanical errors given how many lines this touches.
Here's a way of breaking apart the work that makes sense to me:
- Reuse the patches that prepare git-submodule.sh for the conversion, particularly 1-7/20 (create a "case" dispatch statement and its preceding patches).
- Keep my series that prepares "update", since that's the most tedious one to convert. If I don't dispatch to the "case" statement, I don't think it will even conflict with the preparatory series.
Some of your patches make more sense than mine, and I'll incorporate them as necessary :)
- Dispatch subcommands using the "case" dispatch, including "update". We might have to do this slowly if we want things to be easy to eyeball.
- "git rm git-submodule.sh"!
Quoted 5 lines
Quoted 4 lines
Glen Choo (8):
submodule update: remove intermediate parsing submodule update: pass options containing "[no-]" submodule update: pass options with stuck forms
Quoted 8 lines
Yeah, this is the alternate approach I considered and ended up discarding. I.e. to make forward progress with migrating things away from the cmd_*() functions you either have to prepare things in advance and then sweep the rug from under them in one go.
Or, as you're doing here teaching them about the options they're not-really-parsing anymore, but must know about because they're in a loop that ends with a "if unknown option, usage".
Yes, if you took as many steps as I did, your series would be way too long :P
To convert "update", I don't think this many steps is necessary; I prepared it this way primarily to make it easier for everyone to spot how the options changed so that they can give feedback. Some of these can be squashed in my reroll
Quoted 5 lines
Quoted 1 line
submodule--helper update: use one param per type
Same as my 13/20, but I ended up doing it in a more narrow/smaller way. I tried your way and ran into some bug, then figured I'd do it more narrowly instead of debugging it.
Yeah your approach is easier to eyeball, so I'll do this instead.
Quoted 17 lines
Quoted 1 line
submodule update: remove -v, pass --quietHrm, so we don't need it at all then. Well, that's a bit simpler than my 1[45]/20 and 17/20 :)
So yeah, definitely RFC-quality, but I ran into that one test that used -v, and then saw the missing docs etc. But no cheating, so I've left it in :)
I do wonder if we should leave it in anyway, we never documented -v, but we *did* understand it, and if you look at:
git log -p -Gsay --
git-submodule.shWe used to have a lot more code impacted by it, but looking at this again now it would have only been for users of command-lines like:
Quoted 7 lines
git submodule --quiet update -v [...]I.e. where we already set the flag to the non-default quiet, and then used -v to flip it.
I think at this point I've talked myself into "let's just remove it", but maybe...
On hindsight, what I did is definitely cheating ;)
My series also breaks the way we'd handle --quiet in "git submodule", i.e.
git submodule --quiet update
should be quiet, but isn't.
Your approach actually handles --quiet as per the original shell script, which is a good enough reason to do it your way. We can think about removing it later.
Quoted 12 lines
Brief commentary on my patches, details in commit messages:
Ævar Arnfjörð Bjarmason (20):
git-submodule.sh: remove unusedsanitize_submodule_env()git-submodule.sh: remove unused $prefix variablegit-submodule.sh: remove unused --super-prefix logicI removed a bit more dead code here than yours.
git-submodule.sh: normalize parsing of "--branch" git-submodule.sh: normalize parsing of --cached
Quoted 7 lines
This & various other prep commits (hereafter "easy prep") make subsequent one-time conversions of whole cmd_*() easier.
submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
git-submodule.sh: create a "case" dispatch statementeasy prep
This would all make sense in a preparatory series, with the exception of 3/20 git-submodule.sh: remove unused --super-prefix logic.
We have several instances where we invoke submodule--helper directly with --super-prefix, e.g. inside sync_submodule():
if (flags & OPT_RECURSIVE) {
struct child_process cpr = CHILD_PROCESS_INIT;
cpr.git_cmd = 1;
cpr.dir = path;
prepare_submodule_repo_env(&cpr.env_array);
strvec_push(&cpr.args, "--super-prefix"); /* Here */I even have a (as of now private) patch that replaces "update"'s --recursive-prefix with --super-prefix.
This probably wasn't caught in the tests because this only affects how we calculate the submodule 'displayname'.
Quoted 10 lines
submodule--helper: pretend to be "git submodule" in "-h" output
easy prep & bug fix for existing (on master) output bugs.
git-submodule.sh: dispatch "sync" to helper
git-submodule.sh: dispatch directly to helper
git-submodule.sh: dispatch "foreach" to helperThese are easy conversions as the options 1=1 map after the above prep.
Yes, these are pretty easy. I'm worried about the number of lines changed and the potential for mechanical errors, but we can roll these more slowly if necessary.
Quoted 11 lines
submodule--helper: have --require-init imply --init submodule--helper: understand --checkout, --merge and --rebase synonyms git-submodule doc: document the -v" option to "update" submodule--helper: understand -v option for "update"not-so-easy prep for "
cmd_update()"
git-submodule.sh: dispatch "update" to helperFull
cmd_update()migration in one go.
Yeah, and since it's not-so-easy, it probably makes sense to continue to keep my series around. I'll borrow some of these patches if that's ok :)
Quoted 24 lines
git-submodule.sh: use "$quiet", not "$GIT_QUIET""easy prep", but this one is less overall churn if done at the end, but as noted above could/should maybe be dropped entirely.
git-submodule.sh: simplify parsing loopNot really needed, but I wanted to get the code as close to minimal for the next step, to eyeball the resulting sh v.s. C version.
submodule: make it a built-in, remove
git-submodule.shWe now have a
builtin/submodule.c*and* the currentbuiltin/submodule--helper.c, and we even dispatch to "git submodule--helper" viarun_command()!The idea is to be as close as possible to a bug-for-bug implementation of the shellscript, and that reviewers should be confident in being able to trace what commands we invoked before/after, we're invoking the same "git submodule--helper" commands.
Of course we eventually want to get to some full union of
builtin/submodule{,--helper}.c, but that can wait.
Quoted 8 lines
submodule: add a subprocess-less submodule.useBuiltin setting
Wait, a useBuiltin setting to switch between two built-ins? Yeah, maybe it makes little sense, but here we get rid of the
run_command()overhead, and could generally use the built-in to experiment with deeper integration between the two....
Interesting approach. It looks ok to me, but if we break up this series, maybe this will be stale by the time we integrate the rest of the changes?
PATCH v2 1/12 git-submodule.sh: remove unused sanitize_submodule_env()
In reply to Ævar Arnfjörð BjarmasonThe sanitize_submodule_env() function was last used before b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15), let's remove it.
This also allows us to remove clear_local_git_env() from git-sh-setup.sh. That function hasn't been documented in Documentation/git-sh-setup.sh, and since 14111fc4927 (git: submodule honor -c credential.* from command line, 2016-02-29) it had only been used in the sanitize_submodule_env() function being removed here.
--- git-sh-setup.sh | 7 ------- git-submodule.sh | 11 ----------- 2 files changed, 18 deletions(-)
git-sh-setup.sh +0 -7
@@ -285,13 +285,6 @@ get_author_ident_from_commit () { parse_ident_from_commit author AUTHOR } -# Clear repo-local GIT_* environment variables. Useful when switching to -# another repository (e.g. when entering a submodule). See also the env -# list in git_connect() -clear_local_git_env() { - unset $(git rev-parse --local-env-vars) -} - # Generate a virtual base file for a two-file merge. Uses git apply to # remove lines from $1 that are not in $2, leaving only common lines. create_virtual_base() {
git-submodule.sh +0 -11
@@ -56,17 +56,6 @@ isnumber() n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" } -# Sanitize the local git environment for use within a submodule. We -# can't simply use clear_local_git_env since we want to preserve some -# of the settings from GIT_CONFIG_PARAMETERS. -sanitize_submodule_env() -{ - save_config=$GIT_CONFIG_PARAMETERS - clear_local_git_env - GIT_CONFIG_PARAMETERS=$save_config - export GIT_CONFIG_PARAMETERS -} - # # Add a new submodule to the working tree, .gitmodules and the index #
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 2/12 git-submodule.sh: remove unused $prefix var and --super-prefix
In reply to Ævar Arnfjörð BjarmasonRemove 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.
--- builtin/submodule--helper.c | 53 +++++++++++++++---------------------- git-submodule.sh | 6 ++--- 2 files changed, 24 insertions(+), 35 deletions(-)
builtin/submodule--helper.c +22 -31
@@ -3364,35 +3364,32 @@ 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)
@@ -3401,15 +3398,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 ]);
git-submodule.sh +2 -4
@@ -41,7 +41,6 @@ files= remote= nofetch= update= -prefix= custom_name= depth= progress=
@@ -127,7 +126,7 @@ cmd_add() usage fi - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } #
@@ -189,7 +188,7 @@ cmd_init() shift done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" } #
@@ -346,7 +345,6 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \
Signature · 1 line
2.36.1.1239.gfba91521d90
v2 cover submodule: make "git submodule--helper" behave like "git submodule"
In reply to Glen ChooThis series:
* Removes dead code from git-submodule.sh, or dead code where it was the last user.
* Simplifies CLI parsing in git-submodule.sh, where it was doing something overly complex for no reason.
* Brings "git submodule--helper" in line with the CLI interface of "git-submodule.sh", for a follow-up series to remove the latter, as we'll be able to make a new "git submodule" in C dispatch directly to our new "git submodule--helper" code.
* Removes the "-v" option to "git submodule", which has been supported, but was a) never documented b) never did anything anyway, except as a way to negate an earlier "--quiet" option, as "verbose" was always the default.
* The last couple of patches are cleanup that isn't strictly neccesary for the end-goal of "git submodule" in C, but cleans up some more shellscript code.
The "say" function is removed from "git-sh-setup.sh", now that "git-submodule.sh" doesn't use it anymore (which happened before this series) we can replace the couple of remaining uses with "echo", and by having "git-subtree.sh" own the code that used to live in "git-sh-setup.sh".
The approach here was to combine bits of the two RFC series' Glen and I sent out:
- https://lore.kernel.org/git/[email protected]/
- https://lore.kernel.org/git/[email protected]/
My branch for this (and passing CI) are at:
https://github.com/avar/git/tree/avar/submodule-sh-dispatch-to-helper-directly-prep
The rest here is a reply to
https://lore.kernel.org/git/[email protected]/:
Quoted 10 lines · Glen Choo
Quoted 7 lines · Ævar Arnfjörð Bjarmason
Quoted 1 line
[...]
That's quite the timing coincidence. I hacked this up yesterday, thinking that the submodule topic had been too quiet for a while, and wondering how hard it was to convert the rest of
git-submodule.sh.It's more than 2x the length of yours, but gets to the point where we can "git rm
git-submodule.sh".
Quoted 6 lines
Very cool. I've skimmed through all of the patches, which mostly look good except for ~1-2 things.
Your series shows that there isn't any prohibitively difficult work left to finish the conversion, which is great! The real problem IMO is the potential for mechanical errors given how many lines this touches.
Yes, and as I've discovered in some further poking at the follow-up work (not included here) we again lack quite a bit of testing.
Quoted 9 lines
Here's a way of breaking apart the work that makes sense to me:
- Reuse the patches that prepare
git-submodule.shfor the conversion, particularly 1-7/20 (create a "case" dispatch statement and its preceding patches).
- Keep my series that prepares "update", since that's the most tedious one to convert. If I don't dispatch to the "case" statement, I don't think it will even conflict with the preparatory series.
Quoted 5 lines
Some of your patches make more sense than mine, and I'll incorporate them as necessary :)
- Dispatch subcommands using the "case" dispatch, including "update". We might have to do this slowly if we want things to be easy to eyeball.
- "git rmgit-submodule.sh"!
Hopefully there's no stepping on toes here, but I thought I'd send this out now (I went back to the laptop) to avoid the duplicate work, since I'd already attempted combining the two, and this is the result.
Obviously you may have different ideas about it, and I wouldn't at all mind a v3 that goes in a different direction if you think it's needed.
As noted in the CL above I think this is more palatable for an initial iteration, i.e. it's not doing any of the migration work yet, but merely doing small changes to bring git-submodule.sh and "git submodule--helper" in line with one another.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
submodule--helper update: use one param per type
Same as my 13/20, but I ended up doing it in a more narrow/smaller way. I tried your way and ran into some bug, then figured I'd do it more narrowly instead of debugging it.
Yeah your approach is easier to eyeball, so I'll do this instead.
Hopefully you'll like the change I made here, I kept my commit which narrowlry changes it so that we pass --checkout, --merge and --rebase from git-submodule.sh.
Then after that comes a commit extracted from your change where we make "git submodule--helper" use the same interface for passing options to itself.
Both are good changes to make, but I think it makes sense to split them up. One is needed for "git submodule" in C, the other is just janitorial work in the "git submodule--helper" code.
I think it makes sense to do both, but splitting up the concerns makes it a lot easier to review them IMO.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
submodule update: remove -v, pass --quiet[...]
I think at this point I've talked myself into "let's just remove it", but maybe...On hindsight, what I did is definitely cheating ;)
Your removal of "-v" is in this series. I rewrote the commit message to note exactly what we're changing, why it's thought to be OK etc.
Quoted 10 lines
My series also breaks the way we'd handle --quiet in "git submodule", i.e.
git submodule --quiet updateshould be quiet, but isn't.
Your approach actually handles --quiet as per the original shell script, which is a good enough reason to do it your way. We can think about removing it later.
We have some of these unfortunate "top-level" CLI options in other places, e.g. "git commit-graph", it's probably not worth it to remove them, as they're easy enough to support, and have been documented for a long time.
Quoted 35 lines
Quoted 12 lines
Brief commentary on my patches, details in commit messages:
Ævar Arnfjörð Bjarmason (20):
git-submodule.sh: remove unusedsanitize_submodule_env()git-submodule.sh: remove unused $prefix variablegit-submodule.sh: remove unused --super-prefix logicI removed a bit more dead code here than yours.
git-submodule.sh: normalize parsing of "--branch" git-submodule.sh: normalize parsing of --cachedQuoted 7 lines
This & various other prep commits (hereafter "easy prep") make subsequent one-time conversions of whole cmd_*() easier.
submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
git-submodule.sh: create a "case" dispatch statementeasy prep
This would all make sense in a preparatory series, with the exception of 3/20
git-submodule.sh: remove unused --super-prefix logic.We have several instances where we invoke submodule--helper directly with --super-prefix, e.g. inside
sync_submodule():if (flags & OPT_RECURSIVE) { struct child_process cpr = CHILD_PROCESS_INIT; cpr.git_cmd = 1; cpr.dir = path; prepare_submodule_repo_env(&cpr.env_array); strvec_push(&cpr.args, "--super-prefix"); /* Here */
Quoted 5 lines
I even have a (as of now private) patch that replaces "update"'s --recursive-prefix with --super-prefix.
This probably wasn't caught in the tests because this only affects how we calculate the submodule 'displayname'.
This is still in this series as 02/12. I think you've misunderstood that code, it *is* invoking "git submodule--helper" with "--super-prefix", but the option is passed as:
git --super-prefix <path> submodule--helper
And not as:
git submodule--helper --super-prefix <path>
This is thus handled by other code before builtin/submodule--helper.c, and it doesn't need to handle it.
But anyway, this is confusing, so I updated the commit message (seen in the range-diff below)>
Quoted 8 lines
Quoted 8 lines
submodule--helper: pretend to be "git submodule" in "-h" output
easy prep & bug fix for existing (on master) output bugs.
git-submodule.sh: dispatch "sync" to helper
git-submodule.sh: dispatch directly to helper
git-submodule.sh: dispatch "foreach" to helper
Quoted 6 lines
Quoted 2 lines
These are easy conversions as the options 1=1 map after the above prep.
Yes, these are pretty easy. I'm worried about the number of lines changed and the potential for mechanical errors, but we can roll these more slowly if necessary.
All of this is left out here for now. FWIW I don't think it's hard to review due to the line count, yes e.g. the 2nd patch there is ~300 lines changed, but it's just 5 lines removed/added if we omit the mechanical deletion of the now-unused functions.
Maybe it would be better to omit that and do just one "git rm" at the end? FWIW I thought doing it atomically so that we were left with no dead code after each step made it easier to review.
Quoted 6 lines
Quoted 6 lines
submodule--helper: have --require-init imply --init submodule--helper: understand --checkout, --merge and --rebase synonyms git-submodule doc: document the -v" option to "update" submodule--helper: understand -v option for "update"
Quoted 8 lines
Quoted 5 lines
not-so-easy prep for "
cmd_update()"
git-submodule.sh: dispatch "update" to helperFull
cmd_update()migration in one go.Yeah, and since it's not-so-easy, it probably makes sense to continue to keep my series around. I'll borrow some of these patches if that's ok :)
The proposal in *this series* is to leave this aside for now, but generally I wonder what part of it you find not-so-easy.
Personally I find it much harder to carefully review the way you proposed to do it, i.e. to "buffer up" options that we "don't handle", but actually need to sort-of handle, as we'd still like to die if we have unknown options.
Particularly since shellscript quoting etc. is a pain with that sort of thing, as it doesn't have any real list or key-value datastructures.
Whereas getting it to the point where we're clearly just passing options as-is through beforehand, and then simply dropping the wrapper is, I think, much easier to review. You only need to trust or check that e.g. "git submodule--helper update" also supports a "--progress" option or whatever, and/or that we've got coverage for it.
Quoted 11 lines
Quoted 7 lines
[...]
Wait, a useBuiltin setting to switch between two built-ins? Yeah, maybe it makes little sense, but here we get rid of therun_command()overhead, and could generally use the built-in to experiment with deeper integration between the two....
Interesting approach. It looks ok to me, but if we break up this series, maybe this will be stale by the time we integrate the rest of the changes?
Yes, I think it's probably best to drop this idea of a useBuiltin setting in this case entirely.
The reason we did it for "stash", "git add --interactive" etc. is that we were (or are) dispatching to drastically different code, i.e. we had or have an entire all-at-once re-implementation of the command or feature.
Whereas for "git submodule" we've been doing it incrementally already, and complexity-wise I think previous rounds to migrate to "git submodule--helper" were much more likely have subtle breakages than the relatively straightforward migration we've got left.
B.t.w. here is my WIP re-roll of the full thing, on top of these patches:
https://github.com/avar/git/tree/avar/submodule-sh-dispatch-to-helper-directly-2
As covered in amended commits & tests there the v1 RFC (but not the parts re-rolled here, just the later stuff) had some subtle behavior changes. See the new "submodule tests: test usage behavior" commit there & follow-ups to that.
I haven't found any bad bugs yet, but just obscure edge cases in e.g. how we handle "git submodule --" before/after.
Glen Choo (2):
submodule update: remove "-v" option
submodule--helper: eliminate internal "--update" option
Ævar Arnfjörð Bjarmason (10):
git-submodule.sh: remove unused sanitize_submodule_env() git-submodule.sh: remove unused $prefix var and --super-prefix git-submodule.sh: make "$cached" variable a boolean git-submodule.sh: remove unused top-level "--branch" argument
submodule--helper: have --require-init imply --init
submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
submodule--helper: report "submodule" as our name in "-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 | 127 +++++++++++++++++---------------- 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, 112 insertions(+), 140 deletions(-)
Range-diff against v1:
1: 0e9f13822ef ! 1: c5afc72e075 git-submodule.sh: remove unused sanitize_submodule_env()
@@ Metadata
## Commit message ##
git-submodule.sh: remove unused sanitize_submodule_env()
- The sanitize_submodule_env() function was last used in
+ The sanitize_submodule_env() function was last used before
b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15), let's remove it.
2: 8fcd832e58f < -: ----------- git-submodule.sh: remove unused $prefix variable 3: 6c774505ac5 ! 2: e127803d59d git-submodule.sh: remove unused --super-prefix logic
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- git-submodule.sh: remove unused --super-prefix logic
+ git-submodule.sh: remove unused $prefix var and --super-prefix
- The "$prefix" variable has not been set since b3c5f5cb048 (submodule:
- move core cmd_update() logic to C, 2022-03-15), so we'd never pass the
+ 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.
+
## builtin/submodule--helper.c ##
@@ builtin/submodule--helper.c: int cmd_submodule__helper(int argc, const char **ar
die(_("'%s' is not a valid submodule--helper "
"subcommand"), argv[1]);
+
+ ## git-submodule.sh ##
+@@ git-submodule.sh: files=
+ remote=
+ nofetch=
+ update=
+-prefix=
+ custom_name=
+ depth=
+ progress=
+@@ git-submodule.sh: cmd_add()
+ usage
+ fi
+
+- git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
++ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
+ }
+
+ #
+@@ git-submodule.sh: cmd_init()
+ shift
+ done
+
+- git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@"
++ git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@"
+ }
+
+ #
+@@ git-submodule.sh: cmd_update()
+ ${init:+--init} \
+ ${nofetch:+--no-fetch} \
+ ${wt_prefix:+--prefix "$wt_prefix"} \
+- ${prefix:+--recursive-prefix "$prefix"} \
+ ${update:+--update "$update"} \
+ ${reference:+"$reference"} \
+ ${dissociate:+"--dissociate"} \
5: 124c062e3a1 ! 3: d5c8613c654 git-submodule.sh: normalize parsing of --cached
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- git-submodule.sh: normalize parsing of --cached
+ git-submodule.sh: make "$cached" variable a boolean
Remove the assignment of "$1" to the "$cached" variable. As seen in the initial implementation in 70c7ac22de6 (Add git-submodule command, 2007-05-26) we only need to keep track of if we've seen the --cached
- option. In 28f9af5d25e (git-submodule summary: code framework,
- 2008-03-11) "$1" was assigned to it, but there was no reason to do
- so. Let's undo that.
+ option, not save the "--cached" string for later use.
+
+ In 28f9af5d25e (git-submodule summary: code framework, 2008-03-11)
+ "$1" was assigned to it, but since there was no reason to do so let's
+ stop doing it. This trivial change will make it easier to reason about
+ an eventual change that'll remove the cmd_summary() function in favor
+ of dispatching to "git submodule--helper summary" directly.
@@ git-submodule.sh: cmd_summary() {
--files)
files="$1"
@@ git-submodule.sh: do
- GIT_QUIET=1
+ branch="$2"; shift
;;
--cached)
- cached="$1"
4: f27723aa0a2 ! 4: fd328329b68 git-submodule.sh: normalize parsing of "--branch"
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- git-submodule.sh: normalize parsing of "--branch"
+ git-submodule.sh: remove unused top-level "--branch" argument
In 5c08dbbdf1a (git-submodule: fix subcommand parser, 2008-01-15) the "--branch" option was supported as an option to "git submodule"
@@ Commit message
"--cache" added (or rather modified) in 496eeeb19b9 (git-submodule.sh:
avoid "test <cond> -a/-o <cond>", 2014-06-10).
- But there's been a logic error in that check, this looked like it
- should be supporting:
+ But there's been a logic error in that check, which at a glance looked
+ like it should be supporting:
git submodule --branch <branch> (add | set-branch) [<options>]
@@ Commit message
we have "--branch" here already we'll emit usage, even for "add" and "set-branch".
- Since nobody's complained about "--branch <branch>" not being
- supported as argument to "git submodule" itself, i.e. we want to
- support:
+ So in addition to never having documented this form it hasn't worked
+ since b57e8119e6e was released with v2.22.0 it's safe to remove this
+ code. I.e. we don't want to support the form noted above, but only:
- git submodule (add | set-branch) --branch <branch> [<options>]
-
- But not the first form noted above. Let's just remove this code, we've
- never documented "--branch" as a top-level option (unlike "--quiet"),
- so this looks like it was an accident of the implementation, which we
- broke v2.22.0, so we also know it must not have been important to
- anyone.
+ git submodule (add | set-branch) --branch <branch> [<options>]
@@ git-submodule.sh: do
- branch="$2"; shift
- ;;
--cached)
- cached="$1"
+ cached=1
;;
@@ git-submodule.sh: then
fi
12: 57b9df29ea6 ! 5: ef3265a588e submodule--helper: have --require-init imply --init
@@ Commit message
--require-init option imply --init, rather than having "git-submodule.sh" add it implicitly.
+ This change doesn't make any difference now, but eliminates another
+ special-case where "git submodule--helper update"'s behavior was
+ different from "git submodule update". This will make it easier to
+ eventually replace the cmd_update() function in git-submodule.sh.
+
+ We'll still need to keep the distinction between "--init" and
+ "--require-init" in git-submodule.sh. Once cmd_update() gets
+ re-implemented in C we'll be able to variables and other code related
+ to that, but not yet.
+
## builtin/submodule--helper.c ##
-: ----------- > 6: 025694644fc submodule update: remove "-v" option 6: b1ca1183885 ! 7: 63155ab5026 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
@@ Commit message
absorb-git-dir function, 2016-12-12).
Having these two be different will make it more tedious to dispatch to
- "git submodule--helper" directly, so let's get rid of this needless
+ eventually dispatch "git submodule--helper" directly, as we'd need to
+ retain this name mapping. So let's get rid of this needless
inconsistency.
@@ submodule.c: void absorb_git_dir_into_superproject(const char *path,
"submodule--helper",
- "absorb-git-dirs", NULL);
+ "absorbgitdirs", NULL);
- prepare_submodule_repo_env(&cp.env_array);
+ prepare_submodule_repo_env(&cp.env);
if (run_command(&cp))
die(_("could not recurse into submodule '%s'"), path);
7: 9f5cfbb864a < -: ----------- git-submodule.sh: create a "case" dispatch statement 8: 0c1a5063653 ! 8: 99ac52d810f submodule--helper: pretend to be "git submodule" in "-h" output
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- submodule--helper: pretend to be "git submodule" in "-h" output
+ submodule--helper: report "submodule" as our name in "-h" output
- Change the usage output for "git submodule--helper" so that it will
- pretend to be named "git submodule". This will allow us to dispatch
- further into "git submodule--helper" from git-submodule.sh while
- emitting the correct usage output.
+ Change the rest of the usage output for "git submodule--helper" so
+ that it will pretend to be named "git submodule", which it already did
+ e.g. in the case of "status", "deinit" and "update".
+
+ This will allow us to eventually dispatch further into "git
+ submodule--helper" from git-submodule.sh, while emitting the correct
+ usage output.
+
+ This does make the usage output of "git submodule--helper" itself
+ "incorrect", but since nothing user-facing invokes it directly it
+ makes sense to continue to elide that difference entirely. A user
+ isn't served by us exposing this internal implementation detail.
This fixes a bug that's been there ever since "git submodule absorbgitdirs" was added in f6f85861400 (submodule: add absorb-git-dir
@@ Commit message
usage: git submodule absorbgitdirs [<options>] [<path>...] [.. same usage output ...]
- Note that in the case of "status", "deinit" and "update" we were
- already referring to ourselves as "git submodule" in
- builtin/submodule--helper.c.
-
## builtin/submodule--helper.c ##
9: bd0e4a4f8b8 < -: ----------- git-submodule.sh: dispatch "sync" to helper
10: 498a1fd275b < -: ----------- git-submodule.sh: dispatch directly to helper
11: 625320e13b9 < -: ----------- git-submodule.sh: dispatch "foreach" to helper
13: 20db979a094 ! 9: 01c5eee67c7 submodule--helper: understand --checkout, --merge and --rebase synonyms
@@ builtin/submodule--helper.c: static int module_update(int argc, const char **arg
+ SM_UPDATE_MERGE),
+ OPT_SET_INT('r', "rebase", &update_type,
+ N_("use the 'rebase' update strategy"),
-+ SM_UPDATE_MERGE),
++ SM_UPDATE_REBASE),
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
N_("reference repository")),
OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ builtin/submodule--helper.c: static int module_update(int argc, const char **arg
&opt.update_strategy) < 0)
## git-submodule.sh ##
-@@ git-submodule.sh: init=
- require_init=
+@@ git-submodule.sh: require_init=
+ files=
remote=
nofetch=
-update=
+rebase=
+merge=
+checkout=
+ custom_name=
depth=
progress=
- dissociate=
@@ git-submodule.sh: cmd_update()
force=$1
;;
14: 1cb40a5f42e < -: ----------- git-submodule doc: document the -v" option to "update"
15: 0c388eed1d1 < -: ----------- submodule--helper: understand -v option for "update"
16: 08abadda7c3 < -: ----------- git-submodule.sh: dispatch "update" to helper
17: 59a72296967 < -: ----------- git-submodule.sh: use "$quiet", not "$GIT_QUIET"
18: c5796878f0b < -: ----------- git-submodule.sh: simplify parsing loop
19: 1423950de08 < -: ----------- submodule: make it a built-in, remove git-submodule.sh
20: b2aaad5c008 < -: ----------- submodule: add a subprocess-less submodule.useBuiltin setting
-: ----------- > 10: ac00a9599de submodule--helper: eliminate internal "--update" option
-: ----------- > 11: 875acae8550 git-submodule.sh: use "$quiet", not "$GIT_QUIET"
-: ----------- > 12: 31517345ae8 git-sh-setup.sh: remove "say" function, change last usersSignature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 3/12 git-submodule.sh: make "$cached" variable a boolean
Remove the assignment of "$1" to the "$cached" variable. As seen in the initial implementation in 70c7ac22de6 (Add git-submodule command, 2007-05-26) we only need to keep track of if we've seen the --cached option, not save the "--cached" string for later use.
In 28f9af5d25e (git-submodule summary: code framework, 2008-03-11) "$1" was assigned to it, but since there was no reason to do so let's stop doing it. This trivial change will make it easier to reason about an eventual change that'll remove the cmd_summary() function in favor of dispatching to "git submodule--helper summary" directly.
--- git-submodule.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
git-submodule.sh +2 -2
@@ -446,7 +446,7 @@ cmd_summary() { do case "$1" in --cached) - cached="$1" + cached=1 ;; --files) files="$1"
@@ -583,7 +583,7 @@ do branch="$2"; shift ;; --cached) - cached="$1" + cached=1 ;; --) break
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 4/12 git-submodule.sh: remove unused top-level "--branch" argument
In reply to Ævar Arnfjörð BjarmasonIn 5c08dbbdf1a (git-submodule: fix subcommand parser, 2008-01-15) the "--branch" option was supported as an option to "git submodule" itself, i.e. "git submodule --branch" as a side-effect of its implementation.
Then in b57e8119e6e (submodule: teach set-branch subcommand, 2019-02-08) when the "set-branch" subcommand was added the assertion that we shouldn't have "--branch" anywhere except as an argument to "add" and "set-branch" was copy/pasted from the adjacent check for "--cache" added (or rather modified) in 496eeeb19b9 (git-submodule.sh:
avoid "test <cond> -a/-o <cond>", 2014-06-10).
But there's been a logic error in that check, which at a glance looked like it should be supporting:
git submodule --branch <branch> (add | set-branch) [<options>]
But due to "||" in the condition (as opposed to "&&" for "--cache") if we have "--branch" here already we'll emit usage, even for "add" and "set-branch".
So in addition to never having documented this form it hasn't worked since b57e8119e6e was released with v2.22.0 it's safe to remove this code. I.e. we don't want to support the form noted above, but only:
git submodule (add | set-branch) --branch <branch> [<options>]
--- git-submodule.sh | 14 -------------- 1 file changed, 14 deletions(-)
git-submodule.sh +0 -14
@@ -574,14 +574,6 @@ do -q|--quiet) GIT_QUIET=1 ;; - -b|--branch) - case "$2" in - '') - usage - ;; - esac - branch="$2"; shift - ;; --cached) cached=1 ;;
@@ -609,12 +601,6 @@ then fi fi -# "-b branch" is accepted only by "add" and "set-branch" -if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) -then - usage -fi - # "--cached" is accepted only by "status" and "summary" if test -n "$cached" && test "$command" != status && test "$command" != summary then
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 5/12 submodule--helper: have --require-init imply --init
In reply to Ævar Arnfjörð BjarmasonAdjust code added in 0060fd1511b (clone --recurse-submodules: prevent name squatting on Windows, 2019-09-12) to have the internal --require-init option imply --init, rather than having "git-submodule.sh" add it implicitly.
This change doesn't make any difference now, but eliminates another special-case where "git submodule--helper update"'s behavior was different from "git submodule update". This will make it easier to eventually replace the cmd_update() function in git-submodule.sh.
We'll still need to keep the distinction between "--init" and "--require-init" in git-submodule.sh. Once cmd_update() gets re-implemented in C we'll be able to variables and other code related to that, but not yet.
--- builtin/submodule--helper.c | 5 ++++- git-submodule.sh | 1 - 2 files changed, 4 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +4 -1
@@ -2618,7 +2618,7 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"progress" , &opt.progress,N_ ("force cloning progress" )),OPT_BOOL (0 ,"require-init" , &opt.require_init, -N_ ("disallow cloning into non-empty directory" )), +N_ ("disallow cloning into non-empty directory, implies --init" )),OPT_BOOL (0 ,"single-branch" , &opt.single_branch,N_ ("clone only one branch, HEAD or --branch" )), OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
@@ -2642,6 +2642,9 @@ static int module_update(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, module_update_options, git_submodule_helper_usage,0 ); +if (opt.require_init) + opt.init =1 ; +if (filter_options.choice && !opt.init) {usage_with_options (git_submodule_helper_usage, module_update_options);
git-submodule.sh +0 -1
@@ -251,7 +251,6 @@ cmd_update() init=1 ;; --require-init) - init=1 require_init=1 ;; --remote)
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 6/12 submodule update: remove "-v" option
In reply to Ævar Arnfjörð BjarmasonFrom: Glen Choo <[email protected]>
In e84c3cf3dc3 (git-submodule.sh: accept verbose flag in cmd_update to be non-quiet, 2018-08-14) the "git submodule update" sub-command was made to understand "-v", but the option was never documented.
The only in-tree user has been this test added in 3ad0401e9e6 (submodule update: silence underlying merge/rebase with "--quiet", 2020-09-30), it wasn't per-se testing --quiet, but fixing a bug in e84c3cf3dc3: It used to set "GIT_QUIET=0" instead of unsetting it on "-v", and thus we'd end up passing "--quiet" to "git submodule--helper" on "-v", since the "--quiet" option was passed sing the ${parameter:+word} construct.
Furthermore, even if someone had used the "-v" option they'd only be getting the default output. Our default in both git-submodule.sh and "git submodule--helper" has been to be "verbose", so the only way this option could have matter is if it were used as e.g.:
git submodule --quiet update -v [...]
I.e. to undo the effect of a previous "--quiet" on the command-line.
--- git-submodule.sh | 3 --- t/t7406-submodule-update.sh | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
git-submodule.sh +0 -3
@@ -241,9 +241,6 @@ cmd_update() -q|--quiet) GIT_QUIET=1 ;; - -v) - unset GIT_QUIET - ;; --progress) progress=1 ;;
t/t7406-submodule-update.sh +1 -1
@@ -1074,7 +1074,7 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase' git submodule update --rebase --quiet >out 2>err && test_must_be_empty out && test_must_be_empty err && - git submodule update --rebase -v >out 2>err && + git submodule update --rebase >out 2>err && test_file_not_empty out && test_must_be_empty err )
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 9/12 submodule--helper: understand --checkout, --merge and --rebase synonyms
In reply to Ævar Arnfjörð BjarmasonUnderstand --checkout, --merge and --rebase synonyms for --update={checkout,merge,rebase}, as well as the short options that 'git submodule' itself understands.
This removes a difference between the CLI API of "git submodule" and "git submodule--helper", making it easier to make the latter an alias for the former. See 48308681b07 (git submodule update: have a dedicated helper for cloning, 2016-02-29) for the initial addition of --update.
--- builtin/submodule--helper.c | 17 +++++++++++++++++ git-submodule.sh | 14 +++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-)
builtin/submodule--helper.c +17 -0
@@ -2582,6 +2582,7 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; +enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2603,6 +2604,15 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_STRING (0 ,"update" , &opt.update_default,N_ ("string" ),N_ ("rebase, merge, checkout or none" )), +OPT_SET_INT (0 ,"checkout" , &update_type, +N_ ("use the 'checkout' update strategy (default)" ), +SM_UPDATE_CHECKOUT ), +OPT_SET_INT ('m' ,"merge" , &update_type, +N_ ("use the 'merge' update strategy" ), +SM_UPDATE_MERGE ), +OPT_SET_INT ('r' ,"rebase" , &update_type, +N_ ("use the 'rebase' update strategy" ), +SM_UPDATE_REBASE ),OPT_STRING_LIST (0 ,"reference" , &opt.references,N_ ("repo" ),N_ ("reference repository" )), OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2652,6 +2662,13 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; +if (update_type ==SM_UPDATE_CHECKOUT ) + opt.update_default ="checkout" ; +else if (update_type ==SM_UPDATE_MERGE ) + opt.update_default ="merge" ; +else if (update_type ==SM_UPDATE_REBASE ) + opt.update_default ="rebase" ; +if (opt.update_default)if (parse_submodule_update_strategy (opt.update_default, &opt.update_strategy) <0 )
git-submodule.sh +9 -5
@@ -40,7 +40,9 @@ require_init= files= remote= nofetch= -update= +rebase= +merge= +checkout= custom_name= depth= progress=
@@ -260,7 +262,7 @@ cmd_update() force=$1 ;; -r|--rebase) - update="rebase" + rebase=1 ;; --reference) case "$2" in '') usage ;; esac
@@ -274,13 +276,13 @@ cmd_update() dissociate=1 ;; -m|--merge) - update="merge" + merge=1 ;; --recursive) recursive=1 ;; --checkout) - update="checkout" + checkout=1 ;; --recommend-shallow) recommend_shallow="--recommend-shallow"
@@ -341,7 +343,9 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${update:+--update "$update"} \ + ${rebase:+--rebase} \ + ${merge:+--merge} \ + ${checkout:+--checkout} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \ ${depth:+"$depth"} \
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 8/12 submodule--helper: report "submodule" as our name in "-h" output
In reply to Ævar Arnfjörð BjarmasonChange the rest of the usage output for "git submodule--helper" so that it will pretend to be named "git submodule", which it already did e.g. in the case of "status", "deinit" and "update".
This will allow us to eventually dispatch further into "git submodule--helper" from git-submodule.sh, while emitting the correct usage output.
This does make the usage output of "git submodule--helper" itself "incorrect", but since nothing user-facing invokes it directly it makes sense to continue to elide that difference entirely. A user isn't served by us exposing this internal implementation detail.
This fixes a bug that's been there ever since "git submodule absorbgitdirs" was added in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12). Before this we'd emit e.g. this on invalid usage:
$ git submodule absorbgitdirs --blah error: unknown option `blah' usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
Now we'll emit the same, except that the usage line is now referring to the correct command run by the user:
usage: git submodule absorbgitdirs [<options>] [<path>...] [.. same usage output ...]
--- builtin/submodule--helper.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
builtin/submodule--helper.c +16 -16
@@ -286,7 +286,7 @@ static int module_list(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper list [--prefix=<path>] [<path>...]" ), +N_ ("git submodule list [--prefix=<path>] [<path>...]" ),NULL };
@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper foreach [--quiet] [--recursive] [--] <command>" ), +N_ ("git submodule foreach [--quiet] [--recursive] [--] <command>" ),NULL };
@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper init [<options>] [<path>]" ), +N_ ("git submodule init [<options>] [<path>]" ),NULL };
@@ -786,7 +786,7 @@ static int module_name(int argc, const char **argv, const char *prefix)const struct submodule *sub;if (argc !=2 ) -usage (_ ("git submodule--helper name <path>" )); +usage (_ ("git submodule name <path>" )); sub =submodule_from_path (the_repository,null_oid (), argv[1 ]);
@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper summary [<options>] [<commit>] [--] [<path>]" ), +N_ ("git submodule summary [<options>] [<commit>] [--] [<path>]" ),NULL };
@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper sync [--quiet] [--recursive] [<path>]" ), +N_ ("git submodule sync [--quiet] [--recursive] [<path>]" ),NULL };
@@ -1789,7 +1789,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper clone [--prefix=<path>] [--quiet] " +N_ ("git submodule clone [--prefix=<path>] [--quiet] " "[--reference <repository>] [--name <name>] [--depth <depth>] " "[--single-branch] [--filter <filter-spec>] " "--url <url> --path <path>" ),
@@ -2787,7 +2787,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ), +N_ ("git submodule absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -2851,9 +2851,9 @@ static int module_config(int argc, const char **argv, const char *prefix) OPT_END() };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper config <name> [<value>]" ), -N_ ("git submodule--helper config --unset <name>" ), -"git submodule--helper config --check-writeable" , +N_ ("git submodule config <name> [<value>]" ), +N_ ("git submodule config --unset <name>" ), +"git submodule config --check-writeable" ,NULL };
@@ -2892,7 +2892,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-url [--quiet] <path> <newurl>" ), +N_ ("git submodule set-url [--quiet] <path> <newurl>" ),NULL };
@@ -2931,8 +2931,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>" ), -N_ ("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-d|--default) <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ),NULL };
@@ -2973,7 +2973,7 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ), +N_ ("git submodule create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ),NULL };
@@ -3276,7 +3276,7 @@ static int module_add(int argc, const char **argv, const char *prefix) };const char *const usage[] = { -N_ ("git submodule--helper add [<options>] [--] <repository> [<path>]" ), +N_ ("git submodule add [<options>] [--] <repository> [<path>]" ),NULL };
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 7/12 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
In reply to Ævar Arnfjörð BjarmasonRename the "absorb-git-dirs" subcommand to "absorbgitdirs", which is what the "git submodule" command itself has called it since the subcommand was implemented in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12).
Having these two be different will make it more tedious to dispatch to eventually dispatch "git submodule--helper" directly, as we'd need to retain this name mapping. So let's get rid of this needless inconsistency.
--- builtin/submodule--helper.c | 4 ++-- git-submodule.sh | 2 +- submodule.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/submodule--helper.c +2 -2
@@ -2787,7 +2787,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorb-git-dirs [<options>] [<path>...]" ), +N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -3386,7 +3386,7 @@ 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},
git-submodule.sh +1 -1
@@ -552,7 +552,7 @@ cmd_sync() cmd_absorbgitdirs() { - git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" + git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@" } # This loop parses the command line arguments to find the
submodule.c +1 -1
@@ -2374,7 +2374,7 @@ void absorb_git_dir_into_superproject(const char *path, cp.no_stdin =1 ;strvec_pushl (&cp.args,"--super-prefix" , sb.buf,"submodule--helper" , -"absorb-git-dirs" ,NULL ); +"absorbgitdirs" ,NULL );prepare_submodule_repo_env (&cp.env);if (run_command (&cp))die (_ ("could not recurse into submodule '%s'" ), path);
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 11/12 git-submodule.sh: use "$quiet", not "$GIT_QUIET"
In reply to Ævar Arnfjörð BjarmasonRemove the use of the "$GIT_QUIET" variable in favor of our own "$quiet", ever since b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) we have not used the "say" function in git-sh-setup.sh, which is the only thing that's affected by using "GIT_QUIET".
We still want to support --quiet for our own use though, but let's use our own variable for that, but now it's obvious that we only care about passing "--quiet" to "git submodule--helper", and not to change the output of any "say" invocation.
--- git-submodule.sh | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
git-submodule.sh +19 -18
@@ -30,6 +30,7 @@ GIT_PROTOCOL_FROM_USER=0 export GIT_PROTOCOL_FROM_USER command= +quiet= branch= force= reference=
@@ -80,7 +81,7 @@ cmd_add() force=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --progress) progress=1
@@ -128,7 +129,7 @@ cmd_add() usage fi - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${quiet:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } #
@@ -144,7 +145,7 @@ cmd_foreach() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --recursive) recursive=1
@@ -159,7 +160,7 @@ cmd_foreach() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } #
@@ -174,7 +175,7 @@ cmd_init() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --) shift
@@ -190,7 +191,7 @@ cmd_init() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${quiet:+--quiet} -- "$@" } #
@@ -207,7 +208,7 @@ cmd_deinit() force=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --all) deinit_all=t
@@ -226,7 +227,7 @@ cmd_deinit() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${quiet:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" } #
@@ -241,7 +242,7 @@ cmd_update() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --progress) progress=1
@@ -335,7 +336,7 @@ cmd_update() done git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ - ${GIT_QUIET:+--quiet} \ + ${quiet:+--quiet} \ ${force:+--force} \ ${progress:+"--progress"} \ ${remote:+--remote} \
@@ -396,7 +397,7 @@ cmd_set_branch() { shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${quiet:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" } #
@@ -409,7 +410,7 @@ cmd_set_url() { do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --) shift
@@ -425,7 +426,7 @@ cmd_set_url() { shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@" } #
@@ -496,7 +497,7 @@ cmd_status() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --cached) cached=1
@@ -518,7 +519,7 @@ cmd_status() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" } # # Sync remote urls for submodules
@@ -531,7 +532,7 @@ cmd_sync() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 shift ;; --recursive)
@@ -551,7 +552,7 @@ cmd_sync() esac done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } cmd_absorbgitdirs()
@@ -572,7 +573,7 @@ do command=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --cached) cached=1
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 12/12 git-sh-setup.sh: remove "say" function, change last users
In reply to Ævar Arnfjörð BjarmasonRemove the "say" function, with various rewrites of the remaining git-*.sh code to C and the preceding change to have git-submodule.sh stop using the GIT_QUIET variable there were only four uses in git-subtree.sh. Let's have it use an "arg_quiet" variable instead, and move the "say" function over to it.
The only other use was a trivial message in git-instaweb.sh, since it has never supported the --quiet option (or similar) that code added in 0b624b4ceee (instaweb: restart server if already running, 2009-11-22) can simply use "echo" instead.
The remaining in-tree hits from "say" are all for the sibling function defined in t/test-lib.sh. It's safe to remove this function since it has never been documented in Documentation/git-sh-setup.txt.
--- contrib/subtree/git-subtree.sh | 15 ++++++++++++--- git-instaweb.sh | 2 +- git-sh-setup.sh | 9 --------- 3 files changed, 13 insertions(+), 13 deletions(-)
contrib/subtree/git-subtree.sh +12 -3
@@ -50,6 +50,14 @@ m,message= use the given message as the commit message for the merge commit indent=0 +# Usage: say [MSG...] +say () { + if test -z "$arg_quiet" + then + printf '%s\n' "$*" + fi +} + # Usage: debug [MSG...] debug () { if test -n "$arg_debug"
@@ -60,7 +68,7 @@ debug () { # Usage: progress [MSG...] progress () { - if test -z "$GIT_QUIET" + if test -z "$arg_quiet" then if test -z "$arg_debug" then
@@ -146,6 +154,7 @@ main () { eval "$set_args" # Begin "real" flag parsing. + arg_quiet= arg_debug= arg_prefix= arg_split_branch=
@@ -161,7 +170,7 @@ main () { case "$opt" in -q) - GIT_QUIET=1 + arg_quiet=1 ;; -d) arg_debug=1
@@ -252,7 +261,7 @@ main () { dir="$(dirname "$arg_prefix/.")" debug "command: {$arg_command}" - debug "quiet: {$GIT_QUIET}" + debug "quiet: {$arg_quiet}" debug "dir: {$dir}" debug "opts: {$*}" debug
git-instaweb.sh +1 -1
@@ -102,7 +102,7 @@ resolve_full_httpd () { start_httpd () { if test -f "$fqgitdir/pid"; then - say "Instance already running. Restarting..." + echo "Instance already running. Restarting..." stop_httpd fi
git-sh-setup.sh +0 -9
@@ -57,15 +57,6 @@ die_with_status () { exit "$status" } -GIT_QUIET= - -say () { - if test -z "$GIT_QUIET" - then - printf '%s\n' "$*" - fi -} - if test -n "$OPTIONS_SPEC"; then usage() { "$0" -h
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v2 10/12 submodule--helper: eliminate internal "--update" option
In reply to Ævar Arnfjörð BjarmasonFrom: Glen Choo <[email protected]>
Follow-up on the preceding commit which taught "git submodule--helper update" to understand "--merge", "--checkout" and "--rebase" and use those options instead of "--update=(rebase|merge|checkout|none)" when the command invokes itself.
Unlike the preceding change this isn't strictly necessary to eventually change "git-submodule.sh" so that it invokes "git submodule--helper update" directly, but let's remove this inconsistency in the command-line interface. We shouldn't need to carry special synonyms for existing options in "git submodule--helper" when that command can use the primary documented names instead.
But, as seen in the post-image this makes the control flow within "builtin/submodule--helper.c" simpler, we can now write directly to the "update_default" member of "struct update_data" when parsing the options in "module_update()".
--- builtin/submodule--helper.c | 42 ++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 24 deletions(-)
builtin/submodule--helper.c +18 -24
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)static void determine_submodule_update_strategy (struct repository *r,int just_cloned,const char *path, -const char *update, +enum submodule_update_type update,struct submodule_update_strategy *out) {const struct submodule *sub =submodule_from_path (r,null_oid (), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r, key =xstrfmt ("submodule.%s.update" , sub->name);if (update) { -if (parse_submodule_update_strategy (update, out) <0 ) -die (_ ("Invalid update mode '%s' for submodule path '%s'" ), - update, path); + out->type = update; }else if (!repo_config_get_string_tmp (r, key, &val)) {if (parse_submodule_update_strategy (val, out) <0 ) die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,7 @@ struct update_data {const char *prefix;const char *recursive_prefix;const char *displaypath; -const char *update_default; +enum submodule_update_type update_default;struct object_id suboid;struct string_list references;struct submodule_update_strategy update_strategy;
@@ -2406,6 +2404,8 @@ static void ensure_core_worktree(const char *path)static void update_data_to_args (struct update_data *update_data,struct strvec *args) { +enum submodule_update_type ud = update_data->update_default; +strvec_pushl (args,"submodule--helper" ,"update" ,"--recursive" ,NULL );strvec_pushf (args,"--jobs=%d" , update_data->max_jobs);if (update_data->recursive_prefix)
@@ -2429,8 +2429,15 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *strvec_push (args,"--require-init" );if (update_data->depth)strvec_pushf (args,"--depth=%d" , update_data->depth); -if (update_data->update_default) -strvec_pushl (args,"--update" , update_data->update_default,NULL ); +if (ud ==SM_UPDATE_MERGE ) +strvec_push (args,"--merge" ); +else if (ud ==SM_UPDATE_CHECKOUT ) +strvec_push (args,"--checkout" ); +else if (ud ==SM_UPDATE_REBASE ) +strvec_push (args,"--rebase" ); +else if (ud !=SM_UPDATE_UNSPECIFIED ) +BUG ("cannot convert update_default=%d to args" , ud); +if (update_data->references.nr) {struct string_list_item *item;for_each_string_list_item (item, &update_data->references)
@@ -2582,7 +2589,6 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; -enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2601,16 +2607,13 @@ static int module_update(int argc, const char **argv, const char *prefix) N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), -OPT_STRING (0 ,"update" , &opt.update_default, -N_ ("string" ), -N_ ("rebase, merge, checkout or none" )), -OPT_SET_INT (0 ,"checkout" , &update_type, +OPT_SET_INT (0 ,"checkout" , &opt.update_default,N_ ("use the 'checkout' update strategy (default)" ),SM_UPDATE_CHECKOUT ), -OPT_SET_INT ('m' ,"merge" , &update_type, +OPT_SET_INT ('m' ,"merge" , &opt.update_default,N_ ("use the 'merge' update strategy" ),SM_UPDATE_MERGE ), -OPT_SET_INT ('r' ,"rebase" , &update_type, +OPT_SET_INT ('r' ,"rebase" , &opt.update_default,N_ ("use the 'rebase' update strategy" ),SM_UPDATE_REBASE ), OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
@@ -2662,17 +2665,8 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; -if (update_type ==SM_UPDATE_CHECKOUT ) - opt.update_default ="checkout" ; -else if (update_type ==SM_UPDATE_MERGE ) - opt.update_default ="merge" ; -else if (update_type ==SM_UPDATE_REBASE ) - opt.update_default ="rebase" ; -if (opt.update_default) -if (parse_submodule_update_strategy (opt.update_default, - &opt.update_strategy) <0 ) -die (_ ("bad value for update parameter" )); + opt.update_strategy.type = opt.update_default;if (module_list_compute (argc, argv, prefix, &pathspec, &opt.list) <0 ) {list_objects_filter_release (&filter_options);
Signature · 1 line
2.36.1.1239.gfba91521d90
Re: [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule"
In reply to Ævar Arnfjörð BjarmasonThanks! I'm happy to see this happen regardless of whose patches we use :)
Reading the cover letter, I think it probably makes sense for this to supersede gc/submodule-update. I haven't really looked at the changes yet though, but I will soon.
Quoted 15 lines · Ævar Arnfjörð Bjarmason
Quoted 9 lines
Here's a way of breaking apart the work that makes sense to me:
- Reuse the patches that prepare
git-submodule.shfor the conversion, particularly 1-7/20 (create a "case" dispatch statement and its preceding patches).
- Keep my series that prepares "update", since that's the most tedious one to convert. If I don't dispatch to the "case" statement, I don't think it will even conflict with the preparatory series.Quoted 5 lines
Some of your patches make more sense than mine, and I'll incorporate them as necessary :)
- Dispatch subcommands using the "case" dispatch, including "update". We might have to do this slowly if we want things to be easy to eyeball.
- "git rmgit-submodule.sh"!
Quoted 3 lines
Hopefully there's no stepping on toes here, but I thought I'd send this out now (I went back to the laptop) to avoid the duplicate work, since I'd already attempted combining the two, and this is the result.
Fortunately I hadn't resumed work on this yet, so it works out :)
Quoted 49 lines
Quoted 35 lines
Quoted 12 lines
Brief commentary on my patches, details in commit messages:
Ævar Arnfjörð Bjarmason (20):
git-submodule.sh: remove unusedsanitize_submodule_env()git-submodule.sh: remove unused $prefix variablegit-submodule.sh: remove unused --super-prefix logicI removed a bit more dead code here than yours.
git-submodule.sh: normalize parsing of "--branch" git-submodule.sh: normalize parsing of --cachedQuoted 7 lines
This & various other prep commits (hereafter "easy prep") make subsequent one-time conversions of whole cmd_*() easier.
submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
git-submodule.sh: create a "case" dispatch statementeasy prep
This would all make sense in a preparatory series, with the exception of 3/20
git-submodule.sh: remove unused --super-prefix logic.We have several instances where we invoke submodule--helper directly with --super-prefix, e.g. inside
sync_submodule():if (flags & OPT_RECURSIVE) { struct child_process cpr = CHILD_PROCESS_INIT; cpr.git_cmd = 1; cpr.dir = path; prepare_submodule_repo_env(&cpr.env_array); strvec_push(&cpr.args, "--super-prefix"); /* Here */Quoted 5 lines
I even have a (as of now private) patch that replaces "update"'s --recursive-prefix with --super-prefix.
This probably wasn't caught in the tests because this only affects how we calculate the submodule 'displayname'.
This is still in this series as 02/12. I think you've misunderstood that code, it *is* invoking "git submodule--helper" with "--super-prefix", but the option is passed as:
git --super-prefix <path> submodule--helperAnd not as:
Quoted 7 lines
git submodule--helper --super-prefix <path>This is thus handled by other code before
builtin/submodule--helper.c, and it doesn't need to handle it.But anyway, this is confusing, so I updated the commit message (seen in the range-diff below)>
Ah that's right, I forgot that we have to pass it to "git" directly. Thanks.
I wonder why we ever needed this. 89c8626557 (submodule helper: support super prefix, 2016-12-08) doesn't really explain it, so it looks like I'll have to dig around the ML.
Quoted 27 lines
Quoted 6 lines
Quoted 6 lines
submodule--helper: have --require-init imply --init submodule--helper: understand --checkout, --merge and --rebase synonyms git-submodule doc: document the -v" option to "update" submodule--helper: understand -v option for "update"Quoted 8 lines
Quoted 5 lines
not-so-easy prep for "
cmd_update()"
git-submodule.sh: dispatch "update" to helperFull
cmd_update()migration in one go.Yeah, and since it's not-so-easy, it probably makes sense to continue to keep my series around. I'll borrow some of these patches if that's ok :)
The proposal in *this series* is to leave this aside for now, but generally I wonder what part of it you find not-so-easy.
Personally I find it much harder to carefully review the way you proposed to do it, i.e. to "buffer up" options that we "don't handle", but actually need to sort-of handle, as we'd still like to die if we have unknown options.
Particularly since shellscript quoting etc. is a pain with that sort of thing, as it doesn't have any real list or key-value datastructures.
Quoted 5 lines
Whereas getting it to the point where we're clearly just passing options as-is through beforehand, and then simply dropping the wrapper is, I think, much easier to review. You only need to trust or check that e.g. "git submodule--helper update" also supports a "--progress" option or whatever, and/or that we've got coverage for it.
Makes sense. I suppose we don't have to overthink the conversion because we will have to make the leap of faith to C at some point.
Re: [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule"
Quoted 2 lines · Glen Choo
Thanks! I'm happy to see this happen regardless of whose patches we use :)
I didn't set out to keep "my side", but just to see if we could come up with something non-RFC that could be queued/integrated sooner than later, and removing dead code & the smallish changes to unify the interfaces for a subsequent conversion seemed like it would be more palatable.
Thus dropping 1-3/8 of yours, it's the "real" migration (or steps towards it). Then your 4/8 was tangled up in that migration so I took my smaller 12/20 over it.
I then took your 5/8, but combined with my 13/20 as discussed in the CL. I.e. splitting up the external from internal interface change, which we can do in two steps.
Your 6/8 is then taken over my 14-15/20, 7/8 is another thing I dropped as the "real" migration to leave for later, and as discussed (see below) your 8/8 is much smaller than the dead code removal we can do here in 2/12, i.e. we can drop --super-prefix, and a lot of yarn falls out once we pull on that thread...
Most of the patches I dropped were my own :) I.e. the "actual conversion" bits, and then I picked up e.g. the s/absorb-git-dirs/absorbgitdirs/g etc., and other patches in my series that unified the interfaces.
Quoted 3 lines
Reading the cover letter, I think it probably makes sense for this to supersede gc/submodule-update. I haven't really looked at the changes yet though, but I will soon.
I hadn't noticed that Junio had picked your RFC patches up (I didn't check, figuring since it was RFC they wouldn't be...).
Anyway, I'm fine with whatever gets us to the end goal most efficiently.
Quoted 17 lines
Quoted 15 lines · Ævar Arnfjörð Bjarmason
Quoted 14 lines
Here's a way of breaking apart the work that makes sense to me:
- Reuse the patches that prepare
git-submodule.shfor the conversion, particularly 1-7/20 (create a "case" dispatch statement and its preceding patches).
- Keep my series that prepares "update", since that's the most tedious one to convert. If I don't dispatch to the "case" statement, I don't think it will even conflict with the preparatory series.Some of your patches make more sense than mine, and I'll incorporate them as necessary :)
- Dispatch subcommands using the "case" dispatch, including "update". We might have to do this slowly if we want things to be easy to eyeball.
- "git rmgit-submodule.sh"!
Quoted 5 lines
Quoted 3 lines
Hopefully there's no stepping on toes here, but I thought I'd send this out now (I went back to the laptop) to avoid the duplicate work, since I'd already attempted combining the two, and this is the result.
Fortunately I hadn't resumed work on this yet, so it works out :)
Hope it helped :)
Quoted 17 lines
Quoted 9 lines
[...]
This is still in this series as 02/12. I think you've misunderstood that code, it *is* invoking "git submodule--helper" with "--super-prefix", but the option is passed as:git --super-prefix <path> submodule--helperAnd not as:
Quoted 7 lines
git submodule--helper --super-prefix <path>This is thus handled by other code before
builtin/submodule--helper.c, and it doesn't need to handle it.But anyway, this is confusing, so I updated the commit message (seen in the range-diff below)>
Quoted 6 lines
Ah that's right, I forgot that we have to pass it to "git" directly. Thanks.
I wonder why we ever needed this.
89c8626557(submodule helper: support super prefix, 2016-12-08) doesn't really explain it, so it looks like I'll have to dig around the ML.
It was needed, but not after b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) as my 02/12 discusses.
As a quick test try to check out b3c5f5cb048 and apply this change:
-#define SUPPORT_SUPER_PREFIX (1<<0)
+#define SUPPORT_SUPER_PREFIX 0
You'll find that t7406-submodule-update.sh passes, but check out its parent (which is a commit of yours) and it'll fail, as we'll then emit output like:
-Submodule path '../super': checked out 'e1c658656b91df52a4634fbffeaa739807ce3521'
+Submodule path 'super': checked out 'e1c658656b91df52a4634fbffeaa739807ce3521'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.
Quoted 27 lines
Quoted 27 lines
Quoted 6 lines
Quoted 6 lines
submodule--helper: have --require-init imply --init submodule--helper: understand --checkout, --merge and --rebase synonyms git-submodule doc: document the -v" option to "update" submodule--helper: understand -v option for "update"Quoted 8 lines
Quoted 5 lines
not-so-easy prep for "
cmd_update()"
git-submodule.sh: dispatch "update" to helperFull
cmd_update()migration in one go.Yeah, and since it's not-so-easy, it probably makes sense to continue to keep my series around. I'll borrow some of these patches if that's ok :)
The proposal in *this series* is to leave this aside for now, but generally I wonder what part of it you find not-so-easy.
Personally I find it much harder to carefully review the way you proposed to do it, i.e. to "buffer up" options that we "don't handle", but actually need to sort-of handle, as we'd still like to die if we have unknown options.
Particularly since shellscript quoting etc. is a pain with that sort of thing, as it doesn't have any real list or key-value datastructures.
Quoted 8 lines
Quoted 5 lines
Whereas getting it to the point where we're clearly just passing options as-is through beforehand, and then simply dropping the wrapper is, I think, much easier to review. You only need to trust or check that e.g. "git submodule--helper update" also supports a "--progress" option or whatever, and/or that we've got coverage for it.
Makes sense. I suppose we don't have to overthink the conversion because we will have to make the leap of faith to C at some point.
Anyway, that's something we can leave aside for now. I.e. maybe your way of doing it is better, maybe mine is. That's for later.
For now what do you think about focusing on initial smaller changes to get the two command-line interfaces as close to 1=1 as possible, and to remove dead code etc.
I.e. to aim for small changes now to make reviewing the eventual *.sh v.s. *.c code as easy as possible, as the CLI for "submodule" and "submodule--helper" will behave the same at that point, there won't be any dead code etc.
Re: [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule"
Quoted 36 lines · Ævar Arnfjörð Bjarmason
Quoted 17 lines
Quoted 9 lines
[...]
This is still in this series as 02/12. I think you've misunderstood that code, it *is* invoking "git submodule--helper" with "--super-prefix", but the option is passed as:git --super-prefix <path> submodule--helperAnd not as:
Quoted 7 lines
git submodule--helper --super-prefix <path>This is thus handled by other code before
builtin/submodule--helper.c, and it doesn't need to handle it.But anyway, this is confusing, so I updated the commit message (seen in the range-diff below)>
Quoted 6 lines
Ah that's right, I forgot that we have to pass it to "git" directly. Thanks.
I wonder why we ever needed this.
89c8626557(submodule helper: support super prefix, 2016-12-08) doesn't really explain it, so it looks like I'll have to dig around the ML.It was needed, but not after
b3c5f5cb048(submodule: move corecmd_update()logic to C, 2022-03-15) as my 02/12 discusses.As a quick test try to check out
b3c5f5cb048and apply this change:-#define
SUPPORT_SUPER_PREFIX(1<<0)
+#defineSUPPORT_SUPER_PREFIX0You'll find that
t7406-submodule-update.shpasses, but check out its parent (which is a commit of yours) and it'll fail, as we'll then emit output like:
Quoted 7 lines
-Submodule path '../super': checked out 'e1c658656b91df52a4634fbffeaa739807ce3521' +Submodule path 'super': checked out 'e1c658656b91df52a4634fbffeaa739807ce3521'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.
Ah yes you are right, as of b3c5f5cb048 we never pass --super-prefix to "git submodule" any more. Great!
I also remember that when I was reading the patch that became b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15), I noted (internally) that we used prefix to set "--recursive-prefix", which was unusual because prefix is usually mapped to "--super-prefix".
I have a patch to replace "--recursive-prefix" with "--super-prefix", but it doesn't make sense for that patch to be included in this series (it's preparation for something else entirely, and it won't make this series any cleaner.)
Re: [PATCH v2 04/12] git-submodule.sh: remove unused top-level "--branch" argument
In reply to Ævar Arnfjörð BjarmasonQuoted 21 lines · Ævar Arnfjörð Bjarmason
In
5c08dbbdf1a(git-submodule: fix subcommand parser, 2008-01-15) the "--branch" option was supported as an option to "git submodule" itself, i.e. "git submodule --branch" as a side-effect of its implementation.Then in
b57e8119e6e(submodule: teach set-branch subcommand, 2019-02-08) when the "set-branch" subcommand was added the assertion that we shouldn't have "--branch" anywhere except as an argument to "add" and "set-branch" was copy/pasted from the adjacent check for "--cache" added (or rather modified) in496eeeb19b9(git-submodule.sh:
avoid "test <cond> -a/-o <cond>", 2014-06-10).But there's been a logic error in that check, which at a glance looked like it should be supporting:
git submodule --branch <branch> (add | set-branch) [<options>]But due to "||" in the condition (as opposed to "&&" for "--cache") if we have "--branch" here already we'll emit usage, even for "add" and "set-branch".
Quoted 5 lines
So in addition to never having documented this form it hasn't worked since
b57e8119e6ewas released with v2.22.0 it's safe to remove this code. I.e. we don't want to support the form noted above, but only:git submodule (add | set-branch) --branch <branch> [<options>]
Hm, that's suprising. But I guess the good news is that if it's been broken for so long, nobody probably needs this.
Quoted 27 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- git-submodule.sh | 14 -------------- 1 file changed, 14 deletions(-)git-submodule.sh +0
-8@@ -574,14 +574,6 @@ do -q|--quiet) GIT_QUIET=1 ;; - -b|--branch) - case "$2" in - '') - usage - ;; - esac - branch="$2"; shift - ;; --cached) cached=1 ;;@@ -609,12 +601,6 @@ then fi fi
git-submodule.sh then · line 606
Quoted 10 lines
git-submodule.sh +0
-6-# "-b branch" is accepted only by "add" and "set-branch" -if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) -then - usage -fi - # "--cached" is accepted only by "status" and "summary" if test -n "$cached" && test "$command" != status && test "$command" != summary then
Looks good.
Re: [PATCH v2 05/12] submodule--helper: have --require-init imply --init
In reply to Ævar Arnfjörð BjarmasonQuoted 5 lines · Ævar Arnfjörð Bjarmason
[...]
We'll still need to keep the distinction between "--init" and "--require-init" ingit-submodule.sh. Oncecmd_update()gets re-implemented in C we'll be able to variables and other code related to that, but not yet.
Small typo maybe?
re-implemented in C we'll be able to *change* variables and other code related to that, but not yet.
Re: [PATCH v2 06/12] submodule update: remove "-v" option
In reply to Ævar Arnfjörð BjarmasonQuoted 7 lines · Ævar Arnfjörð Bjarmason
The only in-tree user has been this test added in
3ad0401e9e6(submodule update: silence underlying merge/rebase with "--quiet", 2020-09-30), it wasn't per-se testing --quiet, but fixing a bug ine84c3cf3dc3: It used to set "GIT_QUIET=0" instead of unsetting it on "-v", and thus we'd end up passing "--quiet" to "git submodule--helper" on "-v", since the "--quiet" option was passed sing the ${parameter:+word} construct.
Ah, that explains why we have a test for something that seemed so unnecessary. Note to self to dig a little more in the future.
Quoted 11 lines
Furthermore, even if someone had used the "-v" option they'd only be getting the default output. Our default in both
git-submodule.shand "git submodule--helper" has been to be "verbose", so the only way this option could have matter is if it were used as e.g.:git submodule --quiet update -v [...]I.e. to undo the effect of a previous "--quiet" on the command-line.
Signed-off-by Glen Choo <[email protected]>Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>
The additional motivation looks great, and I think it's changed sufficiently that you should be the author instead of me.
Re: [PATCH v2 08/12] submodule--helper: report "submodule" as our name in "-h" output
In reply to Ævar Arnfjörð BjarmasonQuoted 4 lines · Ævar Arnfjörð Bjarmason
Change the rest of the usage output for "git submodule--helper" so that it will pretend to be named "git submodule", which it already did e.g. in the case of "status", "deinit" and "update".
Quoted 8 lines
This will allow us to eventually dispatch further into "git submodule--helper" from
git-submodule.sh, while emitting the correct usage output.This does make the usage output of "git submodule--helper" itself "incorrect", but since nothing user-facing invokes it directly it makes sense to continue to elide that difference entirely. A user isn't served by us exposing this internal implementation detail.
Everything up to here makes sense. I agree that "git submodule--helper" should have been pretending to be "git submodule" wherever possible.
Before now, it probably didn't matter much because it's quite hard to get "git submodule--helper" to print usage without being first intercepted by "git submodule", but we'll need it now. Which brings us to..
Quoted 8 lines
This fixes a bug that's been there ever since "git submodule absorbgitdirs" was added in
f6f85861400(submodule: add absorb-git-dir function, 2016-12-12). Before this we'd emit e.g. this on invalid usage:$ git submodule absorbgitdirs --blah error: unknown option `blah' usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
We actually used to output the internal-only name of the submodule--helper subcommand, i.e.
git submodule--helper absorb-git-dirs
with the dashes.
Quoted 5 lines
Now we'll emit the same, except that the usage line is now referring to the correct command run by the user:
usage: git submodule absorbgitdirs [<options>] [<path>...] [.. same usage output ...]
I initially wondered why "absorbgitdirs" deserved a special shoutout when we are changing several other subcommands in the same patch, but it turns out that this usage string bug probably is "absorbgitdirs"-specific.
"absorbgitdirs" is the only subcommand that doesn't have an options parsing loop that catches invalid options, it's just:
cmd_absorbgitdirs()
{
git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@"
}whereas in other subcommands, invalid usage would be caught by by the options parsing loop and we never invoke "git submodule--helper blah". As a result, "git submodule--helper absorb-git-dirs" is probably the only subcommand that prints its usage string (instead of the generic "git submodule" usage string.)
It might be worth highlighting how absorbgitdirs is special in the commit message, but I don't feel strongly either way.
Re: [PATCH v2 08/12] submodule--helper: report "submodule" as our name in "-h" output
In reply to Ævar Arnfjörð BjarmasonQuoted 118 lines · Ævar Arnfjörð Bjarmason
builtin/submodule--helper.c +15
-15@@ -286,7 +286,7 @@ static int module_list(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper list [--prefix=<path>] [<path>...]" ), +N_ ("git submodule list [--prefix=<path>] [<path>...]" ),NULL };@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper foreach [--quiet] [--recursive] [--] <command>" ), +N_ ("git submodule foreach [--quiet] [--recursive] [--] <command>" ),NULL };@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper init [<options>] [<path>]" ), +N_ ("git submodule init [<options>] [<path>]" ),NULL };@@ -786,7 +786,7 @@ static int module_name(int argc, const char **argv, const char *prefix)const struct submodule *sub;if (argc !=2 ) -usage (_ ("git submodule--helper name <path>" )); +usage (_ ("git submodule name <path>" )); sub =submodule_from_path (the_repository,null_oid (), argv[1 ]);@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper summary [<options>] [<commit>] [--] [<path>]" ), +N_ ("git submodule summary [<options>] [<commit>] [--] [<path>]" ),NULL };@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper sync [--quiet] [--recursive] [<path>]" ), +N_ ("git submodule sync [--quiet] [--recursive] [<path>]" ),NULL };@@ -1789,7 +1789,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper clone [--prefix=<path>] [--quiet] " +N_ ("git submodule clone [--prefix=<path>] [--quiet] " "[--reference <repository>] [--name <name>] [--depth <depth>] " "[--single-branch] [--filter <filter-spec>] " "--url <url> --path <path>" ),@@ -2787,7 +2787,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ), +N_ ("git submodule absorbgitdirs [<options>] [<path>...]" ),NULL };@@ -2851,9 +2851,9 @@ static int module_config(int argc, const char **argv, const char *prefix) OPT_END() };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper config <name> [<value>]" ), -N_ ("git submodule--helper config --unset <name>" ), -"git submodule--helper config --check-writeable" , +N_ ("git submodule config <name> [<value>]" ), +N_ ("git submodule config --unset <name>" ), +"git submodule config --check-writeable" ,NULL };@@ -2892,7 +2892,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-url [--quiet] <path> <newurl>" ), +N_ ("git submodule set-url [--quiet] <path> <newurl>" ),NULL };@@ -2931,8 +2931,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>" ), -N_ ("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-d|--default) <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ),NULL };@@ -2973,7 +2973,7 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ), +N_ ("git submodule create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ),NULL };
builtin/submodule--helper.c static int module_add(int argc, const char **argv, const char *prefix) · line 3281
Quoted 7 lines
builtin/submodule--helper.c +1
-1@@ -3276,7 +3276,7 @@ static int module_add(int argc, const char **argv, const char *prefix) };const char *const usage[] = { -N_ ("git submodule--helper add [<options>] [--] <repository> [<path>]" ), +N_ ("git submodule add [<options>] [--] <repository> [<path>]" ),NULL };
I don't feel positive about pretending to be "git submodule" when the subcommand is internal-only. Such commands are only invoked as "git submodule--helper foo" and we will probably never turn them into external-facing "git submodule foo" [1]. Even if it is internal-only, there is a debugging benefit to emitting a usage string with the correct, non-user facing command name.
I admit it might be a bit confusing to have a mix of usage strings with "submodule--helper" vs "submodule", but as long as we clearly label which commands are user-facing and which aren't, it shouldn't be too hard to maintain, e.g. this might just be a matter of adding comments to the array of commands like:
static struct cmd_struct commands[] = {
/* User facing commands - pretend to be "git submodule" */
{"name", module_name},
{"add", module_add},
[...]
/* Internal-only commands */
{"clone", module_clone},
{"resolve-relative-url-test", resolve_relative_url_test},
[...]
};Notably, even with this patch we still _kind of_ have 'pseudo usage strings' that reference "git submodule--helper". These are just internal-only commands that don't use the parse_options() API, e.g.
if (argc < 3)
die("submodule--helper push-check requires at least 2 arguments");I think it's ok to leave them as-is, provided we also leave the other internal-only commands as-is.
[1] For convenience, here is a list of all of the subcommands changed in this patch and whether they are user-facing/internal-only:
User-facing Internal-only
- foreach - list - init - name - summary - clone - sync - config - absorbgitdirs - create-branch
- set-url
- set-branch
- add
Re: [PATCH v2 08/12] submodule--helper: report "submodule" as our name in "-h" output
Quoted 119 lines · Glen Choo
Quoted 117 lines · Ævar Arnfjörð Bjarmason
builtin/submodule--helper.c +15
-15@@ -286,7 +286,7 @@ static int module_list(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper list [--prefix=<path>] [<path>...]" ), +N_ ("git submodule list [--prefix=<path>] [<path>...]" ),NULL };@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper foreach [--quiet] [--recursive] [--] <command>" ), +N_ ("git submodule foreach [--quiet] [--recursive] [--] <command>" ),NULL };@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper init [<options>] [<path>]" ), +N_ ("git submodule init [<options>] [<path>]" ),NULL };@@ -786,7 +786,7 @@ static int module_name(int argc, const char **argv, const char *prefix)const struct submodule *sub;if (argc !=2 ) -usage (_ ("git submodule--helper name <path>" )); +usage (_ ("git submodule name <path>" )); sub =submodule_from_path (the_repository,null_oid (), argv[1 ]);@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper summary [<options>] [<commit>] [--] [<path>]" ), +N_ ("git submodule summary [<options>] [<commit>] [--] [<path>]" ),NULL };@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper sync [--quiet] [--recursive] [<path>]" ), +N_ ("git submodule sync [--quiet] [--recursive] [<path>]" ),NULL };@@ -1789,7 +1789,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper clone [--prefix=<path>] [--quiet] " +N_ ("git submodule clone [--prefix=<path>] [--quiet] " "[--reference <repository>] [--name <name>] [--depth <depth>] " "[--single-branch] [--filter <filter-spec>] " "--url <url> --path <path>" ),@@ -2787,7 +2787,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ), +N_ ("git submodule absorbgitdirs [<options>] [<path>...]" ),NULL };@@ -2851,9 +2851,9 @@ static int module_config(int argc, const char **argv, const char *prefix) OPT_END() };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper config <name> [<value>]" ), -N_ ("git submodule--helper config --unset <name>" ), -"git submodule--helper config --check-writeable" , +N_ ("git submodule config <name> [<value>]" ), +N_ ("git submodule config --unset <name>" ), +"git submodule config --check-writeable" ,NULL };@@ -2892,7 +2892,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-url [--quiet] <path> <newurl>" ), +N_ ("git submodule set-url [--quiet] <path> <newurl>" ),NULL };@@ -2931,8 +2931,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>" ), -N_ ("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-d|--default) <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ),NULL };@@ -2973,7 +2973,7 @@ static int module_create_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ), +N_ ("git submodule create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>" ),NULL };
Quoted 8 lines
builtin/submodule--helper.c static int module_add(int argc, const char **argv, const char *prefix) · line 3281
Quoted 8 lines
builtin/submodule--helper.c +1
-1@@ -3276,7 +3276,7 @@ static int module_add(int argc, const char **argv, const char *prefix) };const char *const usage[] = { -N_ ("git submodule--helper add [<options>] [--] <repository> [<path>]" ), +N_ ("git submodule add [<options>] [--] <repository> [<path>]" ),NULL };
First, I think this patch is premature, so let's just drop it in a re-roll. We don't *need* to fix this particular edge case or bug now, and can just do it as we do the final migration.
Quoted 6 lines
I don't feel positive about pretending to be "git submodule" when the subcommand is internal-only. Such commands are only invoked as "git submodule--helper foo" and we will probably never turn them into external-facing "git submodule foo" [1]. Even if it is internal-only, there is a debugging benefit to emitting a usage string with the correct, non-user facing command name.
I think we should really be most concerned about the end users here, nobody except git developers are going to want to invoke "submodule--helper" directly, so its help messages should be aimed at helping users.
As you mention in another E-Mail it's currently not a big deal, I *think* that "absorbgitdirs" is the only case where we'll implicitly suggest to a user that they might invoke "git submodule--helper" as we emit the usage info.
But I think for the patches that come after this we should definitely change this, i.e. we don't want an in-between state where we have both of builtin/submodule{,--helper}.c because we haven't merged the two yet, but are now telling users about the inernal-only helper.
Quoted 21 lines
I admit it might be a bit confusing to have a mix of usage strings with "submodule--helper" vs "submodule", but as long as we clearly label which commands are user-facing and which aren't, it shouldn't be too hard to maintain, e.g. this might just be a matter of adding comments to the array of commands like:
static struct cmd_struct commands[] = { /* User facing commands - pretend to be "git submodule" */ {"name", module_name}, {"add", module_add}, [...] /* Internal-only commands */ {"clone", module_clone}, {"resolve-relative-url-test", resolve_relative_url_test}, [...] };Notably, even with this patch we still
_kindof_have 'pseudo usage strings' that reference "git submodule--helper". These are just internal-only commands that don't use theparse_options()API, e.g.
Quoted 5 lines
if (argc < 3) die("submodule--helper push-check requires at least 2 arguments");I think it's ok to leave them as-is, provided we also leave the other internal-only commands as-is.
Yes let's leave them, we'll be converting these to not invoke sub-processes sooner than later anyway.
Quoted 5 lines
[1] For convenience, here is a list of all of the subcommands changed in this patch and whether they are user-facing/internal-only:
User-facing Internal-only
Quoted 8 lines
- foreach - list - init - name - summary - clone - sync - config - absorbgitdirs - create-branch- set-url
- set-branch
- add
But yeah, if/when we change the public-facing usage strings we should be leaving out the "internal-only" commands, thanks. I just did a dumb search/replace.
Re: [PATCH v2 10/12] submodule--helper: eliminate internal "--update" option
In reply to Ævar Arnfjörð BjarmasonQuoted 75 lines · Ævar Arnfjörð Bjarmason
From: Glen Choo <[email protected]>
Follow-up on the preceding commit which taught "git submodule--helper update" to understand "--merge", "--checkout" and "--rebase" and use those options instead of "--update=(rebase|merge|checkout|none)" when the command invokes itself.
Unlike the preceding change this isn't strictly necessary to eventually change "
git-submodule.sh" so that it invokes "git submodule--helper update" directly, but let's remove this inconsistency in the command-line interface. We shouldn't need to carry special synonyms for existing options in "git submodule--helper" when that command can use the primary documented names instead.But, as seen in the post-image this makes the control flow within "
builtin/submodule--helper.c" simpler, we can now write directly to the "update_default" member of "structupdate_data" when parsing the options in "module_update()".Signed-off-by Glen Choo <[email protected]>Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- builtin/submodule--helper.c | 42 ++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 24 deletions(-)builtin/submodule--helper.c +7
-7@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)static void determine_submodule_update_strategy (struct repository *r,int just_cloned,const char *path, -const char *update, +enum submodule_update_type update,struct submodule_update_strategy *out) {const struct submodule *sub =submodule_from_path (r,null_oid (), path);@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r, key =xstrfmt ("submodule.%s.update" , sub->name);if (update) { -if (parse_submodule_update_strategy (update, out) <0 ) -die (_ ("Invalid update mode '%s' for submodule path '%s'" ), - update, path); + out->type = update; }else if (!repo_config_get_string_tmp (r, key, &val)) {if (parse_submodule_update_strategy (val, out) <0 ) die(_("Invalid update mode '%s' configured for submodule path '%s'"),@@ -1882,7 +1880,7 @@ struct update_data {const char *prefix;const char *recursive_prefix;const char *displaypath; -const char *update_default; +enum submodule_update_type update_default;struct object_id suboid;struct string_list references;struct submodule_update_strategy update_strategy;@@ -2406,6 +2404,8 @@ static void ensure_core_worktree(const char *path)static void update_data_to_args (struct update_data *update_data,struct strvec *args) { +enum submodule_update_type ud = update_data->update_default; +strvec_pushl (args,"submodule--helper" ,"update" ,"--recursive" ,NULL );strvec_pushf (args,"--jobs=%d" , update_data->max_jobs);if (update_data->recursive_prefix)@@ -2429,8 +2429,15 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *strvec_push (args,"--require-init" );if (update_data->depth)strvec_pushf (args,"--depth=%d" , update_data->depth); -if (update_data->update_default) -strvec_pushl (args,"--update" , update_data->update_default,NULL ); +if (ud ==SM_UPDATE_MERGE ) +strvec_push (args,"--merge" );
builtin/submodule--helper.c static void update_data_to_args(struct update_data *update_data, struct strvec * · line 2443
Quoted 10 lines
builtin/submodule--helper.c +7
-0+else if (ud ==SM_UPDATE_CHECKOUT ) +strvec_push (args,"--checkout" ); +else if (ud ==SM_UPDATE_REBASE ) +strvec_push (args,"--rebase" ); +else if (ud !=SM_UPDATE_UNSPECIFIED ) +BUG ("cannot convert update_default=%d to args" , ud); +if (update_data->references.nr) {struct string_list_item *item;for_each_string_list_item (item, &update_data->references)
Everything up to here looks familiar ;)
Quoted 34 lines
builtin/submodule--helper.c +3
-9@@ -2582,7 +2589,6 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; -enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),@@ -2601,16 +2607,13 @@ static int module_update(int argc, const char **argv, const char *prefix) N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), -OPT_STRING (0 ,"update" , &opt.update_default, -N_ ("string" ), -N_ ("rebase, merge, checkout or none" )), -OPT_SET_INT (0 ,"checkout" , &update_type, +OPT_SET_INT (0 ,"checkout" , &opt.update_default,N_ ("use the 'checkout' update strategy (default)" ),SM_UPDATE_CHECKOUT ), -OPT_SET_INT ('m' ,"merge" , &update_type, +OPT_SET_INT ('m' ,"merge" , &opt.update_default,N_ ("use the 'merge' update strategy" ),SM_UPDATE_MERGE ), -OPT_SET_INT ('r' ,"rebase" , &update_type, +OPT_SET_INT ('r' ,"rebase" , &opt.update_default,N_ ("use the 'rebase' update strategy" ),SM_UPDATE_REBASE ), OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),@@ -2662,17 +2665,8 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; -if (update_type ==SM_UPDATE_CHECKOUT ) - opt.update_default ="checkout" ;
builtin/submodule--helper.c static int module_update(int argc, const char **argv, const char *prefix) · line 2669
Quoted 10 lines
builtin/submodule--helper.c +1
-8-else if (update_type ==SM_UPDATE_MERGE ) - opt.update_default ="merge" ; -else if (update_type ==SM_UPDATE_REBASE ) - opt.update_default ="rebase" ; -if (opt.update_default) -if (parse_submodule_update_strategy (opt.update_default, - &opt.update_strategy) <0 ) -die (_ ("bad value for update parameter" )); + opt.update_strategy.type = opt.update_default;
Here we're undoing the changes in the previous patch. I guess there's a readability benefit to having them separate, but I think both patches are simple enough that we can combine into one (with you as the author :).)
Re: [PATCH v2 12/12] git-sh-setup.sh: remove "say" function, change last users
In reply to Ævar Arnfjörð BjarmasonQuoted 68 lines · Ævar Arnfjörð Bjarmason
Remove the "say" function, with various rewrites of the remaining git-*.sh code to C and the preceding change to have
git-submodule.shstop using theGIT_QUIETvariable there were only four uses ingit-subtree.sh. Let's have it use an "arg_quiet" variable instead, and move the "say" function over to it.The only other use was a trivial message in
git-instaweb.sh, since it has never supported the --quiet option (or similar) that code added in0b624b4ceee(instaweb: restart server if already running, 2009-11-22) can simply use "echo" instead.The remaining in-tree hits from "say" are all for the sibling function defined in
t/test-lib.sh. It's safe to remove this function since it has never been documented inDocumentation/git-sh-setup.txt.Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- contrib/subtree/git-subtree.sh | 15 ++++++++++++--- git-instaweb.sh | 2 +- git-sh-setup.sh | 9 --------- 3 files changed, 13 insertions(+), 13 deletions(-)contrib/subtree/git-subtree.sh +11
-2@@ -50,6 +50,14 @@ m,message= use the given message as the commit message for the merge commit indent=0 +# Usage: say [MSG...] +say () { + if test -z "$arg_quiet" + then + printf '%s\n' "$*" + fi +} + # Usage: debug [MSG...] debug () { if test -n "$arg_debug"@@ -60,7 +68,7 @@ debug () { # Usage: progress [MSG...] progress () { - if test -z "$GIT_QUIET" + if test -z "$arg_quiet" then if test -z "$arg_debug" then@@ -146,6 +154,7 @@ main () { eval "$set_args" # Begin "real" flag parsing. + arg_quiet= arg_debug= arg_prefix= arg_split_branch=@@ -161,7 +170,7 @@ main () { case "$opt" in -q) - GIT_QUIET=1 + arg_quiet=1 ;; -d) arg_debug=1
contrib/subtree/git-subtree.sh main () { · line 267
Quoted 8 lines
contrib/subtree/git-subtree.sh +1
-1@@ -252,7 +261,7 @@ main () { dir="$(dirname "$arg_prefix/.")" debug "command: {$arg_command}" - debug "quiet: {$GIT_QUIET}" + debug "quiet: {$arg_quiet}" debug "dir: {$dir}" debug "opts: {$*}" debug
Ok, makes sense. I don't know git-subtree.sh well, but this looks consistent with the rest of the file.
Quoted 23 lines
git-instaweb.sh +1
-1@@ -102,7 +102,7 @@ resolve_full_httpd () { start_httpd () { if test -f "$fqgitdir/pid"; then - say "Instance already running. Restarting..." + echo "Instance already running. Restarting..." stop_httpd figit-sh-setup.sh +0
-2@@ -57,15 +57,6 @@ die_with_status () { exit "$status" } -GIT_QUIET= -
git-sh-setup.sh die_with_status () { · line 62
Quoted 10 lines
git-sh-setup.sh +0
-7-say () { - if test -z "$GIT_QUIET" - then - printf '%s\n' "$*" - fi -} - if test -n "$OPTIONS_SPEC"; then usage() { "$0" -h
Makes sense.
Re: [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule"
In reply to Ævar Arnfjörð BjarmasonSuper happy to see this moving forward, thanks!
I'll summarize the discussion to make it easier for others to follow.
Quoted 4 lines · Ævar Arnfjörð Bjarmason
This series:
* Removes dead code from
git-submodule.sh, or dead code where it was the last user.
This is 1-2/12. Not strictly 'necessary', but removing the dead code makes it easier to tell what git-submodule.sh is doing and will make the final review simpler.
These all look good to me.
Quoted 8 lines
* Simplifies CLI parsing in
git-submodule.sh, where it was doing something overly complex for no reason.* Brings "git submodule--helper" in line with the CLI interface of "
git-submodule.sh", for a follow-up series to remove the latter, as we'll be able to make a new "git submodule" in C dispatch directly to our new "git submodule--helper" code.
Quoted 4 lines
* Removes the "-v" option to "git submodule", which has been supported, but was a) never documented b) never did anything anyway, except as a way to negate an earlier "--quiet" option, as "verbose" was always the default.
3-10/12 is the real crux of this series, which removes all of the extra parsing from "git submodule" by making "git submodule--helper" accept the same args. This is great, because it means that "submodule--helper" can just pretend to be "submodule".
One thing that this series _doesn't_ do (but the RFCs do) is to actually take advantage of this fact and remove the options parsing from git-submodule.sh, e.g.
cmd_foo() {
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foo \
${GIT_QUIET:+--quiet} "$@"
}or in the case dispatch in [1]. Like we discussed earlier, I think this is for the better - getting rid of the options parsing is (probably) going to be most error-prone step, so it makes some sense to do that on its own.
We agreed that 8/12 should be moved to that later series, but everything else looks good.
Quoted 9 lines
* The last couple of patches are cleanup that isn't strictly neccesary for the end-goal of "git submodule" in C, but cleans up some more shellscript code.
The "say" function is removed from "
git-sh-setup.sh", now that "git-submodule.sh" doesn't use it anymore (which happened before this series) we can replace the couple of remaining uses with "echo", and by having "git-subtree.sh" own the code that used to live in "git-sh-setup.sh".
This is 11-12/12, which removes "say" and related cruft.
The changes look ok. I'm not experienced with this area of the codebase, but I've verified the findings in the commit messages.
PATCH v3 12/12 git-sh-setup.sh: remove "say" function, change last users
In reply to Ævar Arnfjörð BjarmasonRemove the "say" function, with various rewrites of the remaining git-*.sh code to C and the preceding change to have git-submodule.sh stop using the GIT_QUIET variable there were only four uses in git-subtree.sh. Let's have it use an "arg_quiet" variable instead, and move the "say" function over to it.
The only other use was a trivial message in git-instaweb.sh, since it has never supported the --quiet option (or similar) that code added in 0b624b4ceee (instaweb: restart server if already running, 2009-11-22) can simply use "echo" instead.
The remaining in-tree hits from "say" are all for the sibling function defined in t/test-lib.sh. It's safe to remove this function since it has never been documented in Documentation/git-sh-setup.txt.
--- contrib/subtree/git-subtree.sh | 15 ++++++++++++--- git-instaweb.sh | 2 +- git-sh-setup.sh | 9 --------- 3 files changed, 13 insertions(+), 13 deletions(-)
contrib/subtree/git-subtree.sh +12 -3
@@ -50,6 +50,14 @@ m,message= use the given message as the commit message for the merge commit indent=0 +# Usage: say [MSG...] +say () { + if test -z "$arg_quiet" + then + printf '%s\n' "$*" + fi +} + # Usage: debug [MSG...] debug () { if test -n "$arg_debug"
@@ -60,7 +68,7 @@ debug () { # Usage: progress [MSG...] progress () { - if test -z "$GIT_QUIET" + if test -z "$arg_quiet" then if test -z "$arg_debug" then
@@ -146,6 +154,7 @@ main () { eval "$set_args" # Begin "real" flag parsing. + arg_quiet= arg_debug= arg_prefix= arg_split_branch=
@@ -161,7 +170,7 @@ main () { case "$opt" in -q) - GIT_QUIET=1 + arg_quiet=1 ;; -d) arg_debug=1
@@ -252,7 +261,7 @@ main () { dir="$(dirname "$arg_prefix/.")" debug "command: {$arg_command}" - debug "quiet: {$GIT_QUIET}" + debug "quiet: {$arg_quiet}" debug "dir: {$dir}" debug "opts: {$*}" debug
git-instaweb.sh +1 -1
@@ -102,7 +102,7 @@ resolve_full_httpd () { start_httpd () { if test -f "$fqgitdir/pid"; then - say "Instance already running. Restarting..." + echo "Instance already running. Restarting..." stop_httpd fi
git-sh-setup.sh +0 -9
@@ -57,15 +57,6 @@ die_with_status () { exit "$status" } -GIT_QUIET= - -say () { - if test -z "$GIT_QUIET" - then - printf '%s\n' "$*" - fi -} - if test -n "$OPTIONS_SPEC"; then usage() { "$0" -h
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 1/12 git-submodule.sh: remove unused sanitize_submodule_env()
In reply to Ævar Arnfjörð BjarmasonThe sanitize_submodule_env() function was last used before b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15), let's remove it.
This also allows us to remove clear_local_git_env() from git-sh-setup.sh. That function hasn't been documented in Documentation/git-sh-setup.sh, and since 14111fc4927 (git: submodule honor -c credential.* from command line, 2016-02-29) it had only been used in the sanitize_submodule_env() function being removed here.
--- git-sh-setup.sh | 7 ------- git-submodule.sh | 11 ----------- 2 files changed, 18 deletions(-)
git-sh-setup.sh +0 -7
@@ -285,13 +285,6 @@ get_author_ident_from_commit () { parse_ident_from_commit author AUTHOR } -# Clear repo-local GIT_* environment variables. Useful when switching to -# another repository (e.g. when entering a submodule). See also the env -# list in git_connect() -clear_local_git_env() { - unset $(git rev-parse --local-env-vars) -} - # Generate a virtual base file for a two-file merge. Uses git apply to # remove lines from $1 that are not in $2, leaving only common lines. create_virtual_base() {
git-submodule.sh +0 -11
@@ -56,17 +56,6 @@ isnumber() n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" } -# Sanitize the local git environment for use within a submodule. We -# can't simply use clear_local_git_env since we want to preserve some -# of the settings from GIT_CONFIG_PARAMETERS. -sanitize_submodule_env() -{ - save_config=$GIT_CONFIG_PARAMETERS - clear_local_git_env - GIT_CONFIG_PARAMETERS=$save_config - export GIT_CONFIG_PARAMETERS -} - # # Add a new submodule to the working tree, .gitmodules and the index #
Signature · 1 line
2.36.1.1239.gfba91521d90
v3 cover submodule: make "git submodule--helper" behave like "git submodule"
In reply to Ævar Arnfjörð BjarmasonThese 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.
See
https://lore.kernel.org/git/[email protected]/
for the larger RFC series which does the "git-submodule.sh to built-in" migration. It will need to be rebased on this series, which has evolved since the initial RFC.
Changes since v2:
* Clarify that removing the --super-prefix code is safe in the commit message.
* Typo/grammar etc. fixes.
* I changed the authorship of the "-v" removal from Glen to myself, as requested by Glen.
* I said I'd drop 08/2, but I've kept a much amended version of it. I think the "-h" output fixes make sense, but now we only change the user-exposed commands, not those internal to "git submodule--helper".
* Glen suggested I squash 09-10/12, but instead I've created a helper function in 09/12 that we can keep using, and thus avoid much of the churn. I think splitting up the change we need for "git-submodule.sh" from the internal interface concerns still make sense.
If there's any outstanding feedback that's unadressed that wasn't the intent, so please point out if I've missed anything. Thanks!
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 var and --super-prefix 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 | 125 +++++++++++++++++++-------------- 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, 117 insertions(+), 133 deletions(-)
Range-diff against v2:
1: c5afc72e075 = 1: ed487469d62 git-submodule.sh: remove unused sanitize_submodule_env() 2: e127803d59d ! 2: 082e015781e git-submodule.sh: remove unused $prefix var and --super-prefix
@@ Commit message
"--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.
+
## builtin/submodule--helper.c ##
3: d5c8613c654 ! 3: 3948aa5d782 git-submodule.sh: make "$cached" variable a boolean
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- git-submodule.sh: make "$cached" variable a boolean
+ git-submodule.sh: make the "$cached" variable a boolean
Remove the assignment of "$1" to the "$cached" variable. As seen in
the initial implementation in 70c7ac22de6 (Add git-submodule command,
4: fd328329b68 ! 4: b5967afd59f git-submodule.sh: remove unused top-level "--branch" argument
@@ Commit message
we have "--branch" here already we'll emit usage, even for "add" and "set-branch".
- So in addition to never having documented this form it hasn't worked
- since b57e8119e6e was released with v2.22.0 it's safe to remove this
- code. I.e. we don't want to support the form noted above, but only:
+ So in addition to never having documented this form, it hasn't worked
+ since b57e8119e6e was released with v2.22.0.
+
+ So it's safe to remove this code. I.e. we don't want to support the
+ form noted above, but only:
git submodule (add | set-branch) --branch <branch> [<options>]
5: ef3265a588e ! 5: 64e4aa41d21 submodule--helper: have --require-init imply --init
@@ Commit message
We'll still need to keep the distinction between "--init" and "--require-init" in git-submodule.sh. Once cmd_update() gets
- re-implemented in C we'll be able to variables and other code related
- to that, but not yet.
+ re-implemented in C we'll be able to change variables and other code
+ related to that, but not yet.
6: 025694644fc ! 6: b82faad77bb submodule update: remove "-v" option
@@
## Metadata ##
-Author: Glen Choo <[email protected]>
+Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
submodule update: remove "-v" option
@@ Commit message
"--quiet", 2020-09-30), it wasn't per-se testing --quiet, but fixing a bug in e84c3cf3dc3: It used to set "GIT_QUIET=0" instead of unsetting it on "-v", and thus we'd end up passing "--quiet" to "git
- submodule--helper" on "-v", since the "--quiet" option was passed sing
- the ${parameter:+word} construct.
+ submodule--helper" on "-v", since the "--quiet" option was passed
+ using the ${parameter:+word} construct.
Furthermore, even if someone had used the "-v" option they'd only be getting the default output. Our default in both git-submodule.sh and
@@ Commit message
I.e. to undo the effect of a previous "--quiet" on the command-line.
- Signed-off-by: Glen Choo <[email protected]>
## git-submodule.sh ##
7: 63155ab5026 = 7: ff557f3c81a submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" 8: 99ac52d810f ! 8: bb1310b9abe submodule--helper: report "submodule" as our name in "-h" output
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- submodule--helper: report "submodule" as our name in "-h" output
+ submodule--helper: report "submodule" as our name in some "-h" output
- Change the rest of the usage output for "git submodule--helper" so
- that it will pretend to be named "git submodule", which it already did
- e.g. in the case of "status", "deinit" and "update".
+ Change the user-facing "git submodule--helper" commands so that
+ they'll report their name as being "git submodule". To a user these
+ commands are internal implementation details, and it doesn't make
+ sense to emit usage about an internal helper when "git submodule" is
+ invoked with invalid options.
- This will allow us to eventually dispatch further into "git
- submodule--helper" from git-submodule.sh, while emitting the correct
- usage output.
-
- This does make the usage output of "git submodule--helper" itself
- "incorrect", but since nothing user-facing invokes it directly it
- makes sense to continue to elide that difference entirely. A user
- isn't served by us exposing this internal implementation detail.
-
- This fixes a bug that's been there ever since "git submodule
- absorbgitdirs" was added in f6f85861400 (submodule: add absorb-git-dir
- function, 2016-12-12). Before this we'd emit e.g. this on invalid
- usage:
+ Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah
error: unknown option `blah'
usage: git submodule--helper absorbgitdirs [<options>] [<path>...]
+ [...]
+ And:
+
+ $ git submodule set-url -- --
+ usage: git submodule--helper set-url [--quiet] <path> <newurl>
+ [...]
- Now we'll emit the same, except that the usage line is now referring
- to the correct command run by the user:
+ Now we'll start with "usage: git submodule [...]" in both of those
+ cases. This change does not alter the "list", "name", "clone",
+ "config" and "create-branch" commands, those are internal-only (as an
+ aside; their usage info should probably invoke BUG(...)). This only
+ changes the user-facing commands.
- usage: git submodule absorbgitdirs [<options>] [<path>...]
- [.. same usage output ...]
+ The "status", "deinit" and "update" commands are not included in this
+ change, because their usage information already used "submodule"
+ rather than "submodule--helper".
+
+ I don't think it's currently possible to emit some of this usage
+ information in practice, as git-submodule.sh will catch unknown
+ options, and e.g. it doesn't seem to be possible to get "add" to emit
+ its usage information from "submodule--helper".
+
+ Though that change may be superfluous now, it's also harmless, and
+ will allow us to eventually dispatch further into "git
+ submodule--helper" from git-submodule.sh, while emitting the correct
+ usage output.
## builtin/submodule--helper.c ##
-@@ builtin/submodule--helper.c: static int module_list(int argc, const char **argv, const char *prefix)
- };
-
- const char *const git_submodule_helper_usage[] = {
-- N_("git submodule--helper list [--prefix=<path>] [<path>...]"),
-+ N_("git submodule list [--prefix=<path>] [<path>...]"),
- NULL
- };
-
@@ builtin/submodule--helper.c: static int module_foreach(int argc, const char **argv, const char *prefix)
};
@@ builtin/submodule--helper.c: static int module_init(int argc, const char **argv,
NULL
};
-@@ builtin/submodule--helper.c: static int module_name(int argc, const char **argv, const char *prefix)
- const struct submodule *sub;
-
- if (argc != 2)
-- usage(_("git submodule--helper name <path>"));
-+ usage(_("git submodule name <path>"));
-
- sub = submodule_from_path(the_repository, null_oid(), argv[1]);
-
@@ builtin/submodule--helper.c: static int module_summary(int argc, const char **argv, const char *prefix)
};
@@ builtin/submodule--helper.c: static int module_sync(int argc, const char **argv,
NULL
};
-@@ builtin/submodule--helper.c: static int module_clone(int argc, const char **argv, const char *prefix)
- };
-
- const char *const git_submodule_helper_usage[] = {
-- N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
-+ N_("git submodule clone [--prefix=<path>] [--quiet] "
- "[--reference <repository>] [--name <name>] [--depth <depth>] "
- "[--single-branch] [--filter <filter-spec>] "
- "--url <url> --path <path>"),
@@ builtin/submodule--helper.c: static int absorb_git_dirs(int argc, const char **argv, const char *prefix)
};
@@ builtin/submodule--helper.c: static int absorb_git_dirs(int argc, const char **a
NULL
};
-@@ builtin/submodule--helper.c: static int module_config(int argc, const char **argv, const char *prefix)
- OPT_END()
- };
- const char *const git_submodule_helper_usage[] = {
-- N_("git submodule--helper config <name> [<value>]"),
-- N_("git submodule--helper config --unset <name>"),
-- "git submodule--helper config --check-writeable",
-+ N_("git submodule config <name> [<value>]"),
-+ N_("git submodule config --unset <name>"),
-+ "git submodule config --check-writeable",
- NULL
- };
-
@@ builtin/submodule--helper.c: static int module_set_url(int argc, const char **argv, const char *prefix)
OPT_END()
};
@@ builtin/submodule--helper.c: static int module_set_branch(int argc, const char *
NULL
};
-@@ builtin/submodule--helper.c: static int module_create_branch(int argc, const char **argv, const char *prefix)
- OPT_END()
- };
- const char *const usage[] = {
-- N_("git submodule--helper create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>"),
-+ N_("git submodule create-branch [-f|--force] [--create-reflog] [-q|--quiet] [-t|--track] [-n|--dry-run] <name> <start-oid> <start-name>"),
- NULL
- };
-
@@ builtin/submodule--helper.c: static int module_add(int argc, const char **argv, const char *prefix)
};
9: 80536424daa ! 9: e251fc115e1 submodule--helper: understand --checkout, --merge and --rebase synonyms
@@ Commit message
Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
## builtin/submodule--helper.c ##
+@@ builtin/submodule--helper.c: static void ensure_core_worktree(const char *path)
+ }
+ }
+
++static const char *submodule_update_type_to_label(enum submodule_update_type type)
++{
++ switch (type) {
++ case SM_UPDATE_CHECKOUT:
++ return "checkout";
++ case SM_UPDATE_MERGE:
++ return "merge";
++ case SM_UPDATE_REBASE:
++ return "rebase";
++ case SM_UPDATE_UNSPECIFIED:
++ case SM_UPDATE_NONE:
++ case SM_UPDATE_COMMAND:
++ break;
++ }
++ BUG("unreachable with type %d", type);
++}
++
+ static void update_data_to_args(struct update_data *update_data, struct strvec *args)
+ {
+ strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
@@ builtin/submodule--helper.c: static int module_update(int argc, const char **argv, const char *prefix)
struct update_data opt = UPDATE_DATA_INIT;
struct list_objects_filter_options filter_options;
@@ builtin/submodule--helper.c: static int module_update(int argc, const char **arg
opt.filter_options = &filter_options;
-+ if (update_type == SM_UPDATE_CHECKOUT)
-+ opt.update_default = "checkout";
-+ else if (update_type == SM_UPDATE_MERGE)
-+ opt.update_default = "merge";
-+ else if (update_type == SM_UPDATE_REBASE)
-+ opt.update_default = "rebase";
++ if (update_type != SM_UPDATE_UNSPECIFIED)
++ opt.update_default = submodule_update_type_to_label(update_type);
+
if (opt.update_default)
if (parse_submodule_update_strategy(opt.update_default,
10: 9ce9f78b2d0 ! 10: 66a229227a1 submodule--helper: eliminate internal "--update" option
@@ builtin/submodule--helper.c: struct update_data {
struct object_id suboid;
struct string_list references;
struct submodule_update_strategy update_strategy;
-@@ builtin/submodule--helper.c: static void ensure_core_worktree(const char *path)
+@@ builtin/submodule--helper.c: static const char *submodule_update_type_to_label(enum submodule_update_type typ
static void update_data_to_args(struct update_data *update_data, struct strvec *args)
{
-+ enum submodule_update_type ud = update_data->update_default;
++ enum submodule_update_type update_type = update_data->update_default;
+
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
@@ builtin/submodule--helper.c: static void update_data_to_args(struct update_data
strvec_pushf(args, "--depth=%d", update_data->depth);
- if (update_data->update_default)
- strvec_pushl(args, "--update", update_data->update_default, NULL);
-+ if (ud == SM_UPDATE_MERGE)
-+ strvec_push(args, "--merge");
-+ else if (ud == SM_UPDATE_CHECKOUT)
-+ strvec_push(args, "--checkout");
-+ else if (ud == SM_UPDATE_REBASE)
-+ strvec_push(args, "--rebase");
-+ else if (ud != SM_UPDATE_UNSPECIFIED)
-+ BUG("cannot convert update_default=%d to args", ud);
++ if (update_type != SM_UPDATE_UNSPECIFIED)
++ strvec_pushf(args, "--%s",
++ submodule_update_type_to_label(update_type));
+
if (update_data->references.nr) {
struct string_list_item *item;
@@ builtin/submodule--helper.c: static int module_update(int argc, const char **arg
opt.filter_options = &filter_options;
-- if (update_type == SM_UPDATE_CHECKOUT)
-- opt.update_default = "checkout";
-- else if (update_type == SM_UPDATE_MERGE)
-- opt.update_default = "merge";
-- else if (update_type == SM_UPDATE_REBASE)
-- opt.update_default = "rebase";
+- if (update_type != SM_UPDATE_UNSPECIFIED)
+- opt.update_default = submodule_update_type_to_label(update_type);
-
if (opt.update_default)
- if (parse_submodule_update_strategy(opt.update_default,11: 42b107bc9df ! 11: f8219cd461d git-submodule.sh: use "$quiet", not "$GIT_QUIET"
@@ Commit message
"GIT_QUIET".
We still want to support --quiet for our own use though, but let's use
- our own variable for that, but now it's obvious that we only care
- about passing "--quiet" to "git submodule--helper", and not to change
- the output of any "say" invocation.
+ our own variable for that. Now it's obvious that we only care about
+ passing "--quiet" to "git submodule--helper", and not to change the
+ output of any "say" invocation.
12: 336c6d5dd63 = 12: ecdd8c6ed28 git-sh-setup.sh: remove "say" function, change last users
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 2/12 git-submodule.sh: remove unused $prefix var and --super-prefix
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.
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.
--- builtin/submodule--helper.c | 53 +++++++++++++++---------------------- git-submodule.sh | 6 ++--- 2 files changed, 24 insertions(+), 35 deletions(-)
builtin/submodule--helper.c +22 -31
@@ -3365,35 +3365,32 @@ 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)
@@ -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 ]);
git-submodule.sh +2 -4
@@ -41,7 +41,6 @@ files= remote= nofetch= update= -prefix= custom_name= depth= progress=
@@ -127,7 +126,7 @@ cmd_add() usage fi - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } #
@@ -189,7 +188,7 @@ cmd_init() shift done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" } #
@@ -346,7 +345,6 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 3/12 git-submodule.sh: make the "$cached" variable a boolean
In reply to Ævar Arnfjörð BjarmasonRemove the assignment of "$1" to the "$cached" variable. As seen in the initial implementation in 70c7ac22de6 (Add git-submodule command, 2007-05-26) we only need to keep track of if we've seen the --cached option, not save the "--cached" string for later use.
In 28f9af5d25e (git-submodule summary: code framework, 2008-03-11) "$1" was assigned to it, but since there was no reason to do so let's stop doing it. This trivial change will make it easier to reason about an eventual change that'll remove the cmd_summary() function in favor of dispatching to "git submodule--helper summary" directly.
--- git-submodule.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
git-submodule.sh +2 -2
@@ -446,7 +446,7 @@ cmd_summary() { do case "$1" in --cached) - cached="$1" + cached=1 ;; --files) files="$1"
@@ -583,7 +583,7 @@ do branch="$2"; shift ;; --cached) - cached="$1" + cached=1 ;; --) break
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 4/12 git-submodule.sh: remove unused top-level "--branch" argument
In reply to Ævar Arnfjörð BjarmasonIn 5c08dbbdf1a (git-submodule: fix subcommand parser, 2008-01-15) the "--branch" option was supported as an option to "git submodule" itself, i.e. "git submodule --branch" as a side-effect of its implementation.
Then in b57e8119e6e (submodule: teach set-branch subcommand, 2019-02-08) when the "set-branch" subcommand was added the assertion that we shouldn't have "--branch" anywhere except as an argument to "add" and "set-branch" was copy/pasted from the adjacent check for "--cache" added (or rather modified) in 496eeeb19b9 (git-submodule.sh:
avoid "test <cond> -a/-o <cond>", 2014-06-10).
But there's been a logic error in that check, which at a glance looked like it should be supporting:
git submodule --branch <branch> (add | set-branch) [<options>]
But due to "||" in the condition (as opposed to "&&" for "--cache") if we have "--branch" here already we'll emit usage, even for "add" and "set-branch".
So in addition to never having documented this form, it hasn't worked since b57e8119e6e was released with v2.22.0.
So it's safe to remove this code. I.e. we don't want to support the form noted above, but only:
git submodule (add | set-branch) --branch <branch> [<options>]
--- git-submodule.sh | 14 -------------- 1 file changed, 14 deletions(-)
git-submodule.sh +0 -14
@@ -574,14 +574,6 @@ do -q|--quiet) GIT_QUIET=1 ;; - -b|--branch) - case "$2" in - '') - usage - ;; - esac - branch="$2"; shift - ;; --cached) cached=1 ;;
@@ -609,12 +601,6 @@ then fi fi -# "-b branch" is accepted only by "add" and "set-branch" -if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) -then - usage -fi - # "--cached" is accepted only by "status" and "summary" if test -n "$cached" && test "$command" != status && test "$command" != summary then
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 6/12 submodule update: remove "-v" option
In reply to Ævar Arnfjörð BjarmasonIn e84c3cf3dc3 (git-submodule.sh: accept verbose flag in cmd_update to be non-quiet, 2018-08-14) the "git submodule update" sub-command was made to understand "-v", but the option was never documented.
The only in-tree user has been this test added in 3ad0401e9e6 (submodule update: silence underlying merge/rebase with "--quiet", 2020-09-30), it wasn't per-se testing --quiet, but fixing a bug in e84c3cf3dc3: It used to set "GIT_QUIET=0" instead of unsetting it on "-v", and thus we'd end up passing "--quiet" to "git submodule--helper" on "-v", since the "--quiet" option was passed using the ${parameter:+word} construct.
Furthermore, even if someone had used the "-v" option they'd only be getting the default output. Our default in both git-submodule.sh and "git submodule--helper" has been to be "verbose", so the only way this option could have matter is if it were used as e.g.:
git submodule --quiet update -v [...]
I.e. to undo the effect of a previous "--quiet" on the command-line.
--- git-submodule.sh | 3 --- t/t7406-submodule-update.sh | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
git-submodule.sh +0 -3
@@ -241,9 +241,6 @@ cmd_update() -q|--quiet) GIT_QUIET=1 ;; - -v) - unset GIT_QUIET - ;; --progress) progress=1 ;;
t/t7406-submodule-update.sh +1 -1
@@ -1074,7 +1074,7 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase' git submodule update --rebase --quiet >out 2>err && test_must_be_empty out && test_must_be_empty err && - git submodule update --rebase -v >out 2>err && + git submodule update --rebase >out 2>err && test_file_not_empty out && test_must_be_empty err )
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 5/12 submodule--helper: have --require-init imply --init
In reply to Ævar Arnfjörð BjarmasonAdjust code added in 0060fd1511b (clone --recurse-submodules: prevent name squatting on Windows, 2019-09-12) to have the internal --require-init option imply --init, rather than having "git-submodule.sh" add it implicitly.
This change doesn't make any difference now, but eliminates another special-case where "git submodule--helper update"'s behavior was different from "git submodule update". This will make it easier to eventually replace the cmd_update() function in git-submodule.sh.
We'll still need to keep the distinction between "--init" and "--require-init" in git-submodule.sh. Once cmd_update() gets re-implemented in C we'll be able to change variables and other code related to that, but not yet.
--- builtin/submodule--helper.c | 5 ++++- git-submodule.sh | 1 - 2 files changed, 4 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +4 -1
@@ -2619,7 +2619,7 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"progress" , &opt.progress,N_ ("force cloning progress" )),OPT_BOOL (0 ,"require-init" , &opt.require_init, -N_ ("disallow cloning into non-empty directory" )), +N_ ("disallow cloning into non-empty directory, implies --init" )),OPT_BOOL (0 ,"single-branch" , &opt.single_branch,N_ ("clone only one branch, HEAD or --branch" )), OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
@@ -2643,6 +2643,9 @@ static int module_update(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, module_update_options, git_submodule_helper_usage,0 ); +if (opt.require_init) + opt.init =1 ; +if (filter_options.choice && !opt.init) {usage_with_options (git_submodule_helper_usage, module_update_options);
git-submodule.sh +0 -1
@@ -251,7 +251,6 @@ cmd_update() init=1 ;; --require-init) - init=1 require_init=1 ;; --remote)
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 10/12 submodule--helper: eliminate internal "--update" option
In reply to Ævar Arnfjörð BjarmasonFrom: Glen Choo <[email protected]>
Follow-up on the preceding commit which taught "git submodule--helper update" to understand "--merge", "--checkout" and "--rebase" and use those options instead of "--update=(rebase|merge|checkout|none)" when the command invokes itself.
Unlike the preceding change this isn't strictly necessary to eventually change "git-submodule.sh" so that it invokes "git submodule--helper update" directly, but let's remove this inconsistency in the command-line interface. We shouldn't need to carry special synonyms for existing options in "git submodule--helper" when that command can use the primary documented names instead.
But, as seen in the post-image this makes the control flow within "builtin/submodule--helper.c" simpler, we can now write directly to the "update_default" member of "struct update_data" when parsing the options in "module_update()".
--- builtin/submodule--helper.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
builtin/submodule--helper.c +13 -20
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)static void determine_submodule_update_strategy (struct repository *r,int just_cloned,const char *path, -const char *update, +enum submodule_update_type update,struct submodule_update_strategy *out) {const struct submodule *sub =submodule_from_path (r,null_oid (), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r, key =xstrfmt ("submodule.%s.update" , sub->name);if (update) { -if (parse_submodule_update_strategy (update, out) <0 ) -die (_ ("Invalid update mode '%s' for submodule path '%s'" ), - update, path); + out->type = update; }else if (!repo_config_get_string_tmp (r, key, &val)) {if (parse_submodule_update_strategy (val, out) <0 ) die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,7 @@ struct update_data {const char *prefix;const char *recursive_prefix;const char *displaypath; -const char *update_default; +enum submodule_update_type update_default;struct object_id suboid;struct string_list references;struct submodule_update_strategy update_strategy;
@@ -2424,6 +2422,8 @@ static const char *submodule_update_type_to_label(enum submodule_update_type typstatic void update_data_to_args (struct update_data *update_data,struct strvec *args) { +enum submodule_update_type update_type = update_data->update_default; +strvec_pushl (args,"submodule--helper" ,"update" ,"--recursive" ,NULL );strvec_pushf (args,"--jobs=%d" , update_data->max_jobs);if (update_data->recursive_prefix)
@@ -2447,8 +2447,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *strvec_push (args,"--require-init" );if (update_data->depth)strvec_pushf (args,"--depth=%d" , update_data->depth); -if (update_data->update_default) -strvec_pushl (args,"--update" , update_data->update_default,NULL ); +if (update_type !=SM_UPDATE_UNSPECIFIED ) +strvec_pushf (args,"--%s" , +submodule_update_type_to_label (update_type)); +if (update_data->references.nr) {struct string_list_item *item;for_each_string_list_item (item, &update_data->references)
@@ -2600,7 +2602,6 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; -enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2619,16 +2620,13 @@ static int module_update(int argc, const char **argv, const char *prefix) N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), -OPT_STRING (0 ,"update" , &opt.update_default, -N_ ("string" ), -N_ ("rebase, merge, checkout or none" )), -OPT_SET_INT (0 ,"checkout" , &update_type, +OPT_SET_INT (0 ,"checkout" , &opt.update_default,N_ ("use the 'checkout' update strategy (default)" ),SM_UPDATE_CHECKOUT ), -OPT_SET_INT ('m' ,"merge" , &update_type, +OPT_SET_INT ('m' ,"merge" , &opt.update_default,N_ ("use the 'merge' update strategy" ),SM_UPDATE_MERGE ), -OPT_SET_INT ('r' ,"rebase" , &update_type, +OPT_SET_INT ('r' ,"rebase" , &opt.update_default,N_ ("use the 'rebase' update strategy" ),SM_UPDATE_REBASE ), OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
@@ -2680,13 +2678,8 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; -if (update_type !=SM_UPDATE_UNSPECIFIED ) - opt.update_default =submodule_update_type_to_label (update_type); -if (opt.update_default) -if (parse_submodule_update_strategy (opt.update_default, - &opt.update_strategy) <0 ) -die (_ ("bad value for update parameter" )); + opt.update_strategy.type = opt.update_default;if (module_list_compute (argc, argv, prefix, &pathspec, &opt.list) <0 ) {list_objects_filter_release (&filter_options);
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 9/12 submodule--helper: understand --checkout, --merge and --rebase synonyms
In reply to Ævar Arnfjörð BjarmasonUnderstand --checkout, --merge and --rebase synonyms for --update={checkout,merge,rebase}, as well as the short options that 'git submodule' itself understands.
This removes a difference between the CLI API of "git submodule" and "git submodule--helper", making it easier to make the latter an alias for the former. See 48308681b07 (git submodule update: have a dedicated helper for cloning, 2016-02-29) for the initial addition of --update.
--- builtin/submodule--helper.c | 30 ++++++++++++++++++++++++++++++ git-submodule.sh | 14 +++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-)
builtin/submodule--helper.c +30 -0
@@ -2405,6 +2405,23 @@ static void ensure_core_worktree(const char *path) } } +static const char *submodule_update_type_to_label (enum submodule_update_type type) +{ +switch (type) { +case SM_UPDATE_CHECKOUT : +return "checkout" ; +case SM_UPDATE_MERGE : +return "merge" ; +case SM_UPDATE_REBASE : +return "rebase" ; +case SM_UPDATE_UNSPECIFIED : +case SM_UPDATE_NONE : +case SM_UPDATE_COMMAND : +break ; + } +BUG ("unreachable with type %d" , type); +} +static void update_data_to_args (struct update_data *update_data,struct strvec *args) {strvec_pushl (args,"submodule--helper" ,"update" ,"--recursive" ,NULL );
@@ -2583,6 +2600,7 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; +enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2604,6 +2622,15 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_STRING (0 ,"update" , &opt.update_default,N_ ("string" ),N_ ("rebase, merge, checkout or none" )), +OPT_SET_INT (0 ,"checkout" , &update_type, +N_ ("use the 'checkout' update strategy (default)" ), +SM_UPDATE_CHECKOUT ), +OPT_SET_INT ('m' ,"merge" , &update_type, +N_ ("use the 'merge' update strategy" ), +SM_UPDATE_MERGE ), +OPT_SET_INT ('r' ,"rebase" , &update_type, +N_ ("use the 'rebase' update strategy" ), +SM_UPDATE_REBASE ),OPT_STRING_LIST (0 ,"reference" , &opt.references,N_ ("repo" ),N_ ("reference repository" )), OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2653,6 +2680,9 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; +if (update_type !=SM_UPDATE_UNSPECIFIED ) + opt.update_default =submodule_update_type_to_label (update_type); +if (opt.update_default)if (parse_submodule_update_strategy (opt.update_default, &opt.update_strategy) <0 )
git-submodule.sh +9 -5
@@ -40,7 +40,9 @@ require_init= files= remote= nofetch= -update= +rebase= +merge= +checkout= custom_name= depth= progress=
@@ -260,7 +262,7 @@ cmd_update() force=$1 ;; -r|--rebase) - update="rebase" + rebase=1 ;; --reference) case "$2" in '') usage ;; esac
@@ -274,13 +276,13 @@ cmd_update() dissociate=1 ;; -m|--merge) - update="merge" + merge=1 ;; --recursive) recursive=1 ;; --checkout) - update="checkout" + checkout=1 ;; --recommend-shallow) recommend_shallow="--recommend-shallow"
@@ -341,7 +343,9 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${update:+--update "$update"} \ + ${rebase:+--rebase} \ + ${merge:+--merge} \ + ${checkout:+--checkout} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \ ${depth:+"$depth"} \
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 8/12 submodule--helper: report "submodule" as our name in some "-h" output
In reply to Ævar Arnfjörð BjarmasonChange the user-facing "git submodule--helper" commands so that they'll report their name as being "git submodule". To a user these commands are internal implementation details, and it doesn't make sense to emit usage about an internal helper when "git submodule" is invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah error: unknown option `blah' usage: git submodule--helper absorbgitdirs [<options>] [<path>...] [...] And:
$ git submodule set-url -- -- usage: git submodule--helper set-url [--quiet] <path> <newurl> [...]
Now we'll start with "usage: git submodule [...]" in both of those cases. This change does not alter the "list", "name", "clone", "config" and "create-branch" commands, those are internal-only (as an aside; their usage info should probably invoke BUG(...)). This only changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this change, because their usage information already used "submodule" rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage information in practice, as git-submodule.sh will catch unknown options, and e.g. it doesn't seem to be possible to get "add" to emit its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and will allow us to eventually dispatch further into "git submodule--helper" from git-submodule.sh, while emitting the correct usage output.
--- builtin/submodule--helper.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
builtin/submodule--helper.c +9 -9
@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper foreach [--quiet] [--recursive] [--] <command>" ), +N_ ("git submodule foreach [--quiet] [--recursive] [--] <command>" ),NULL };
@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper init [<options>] [<path>]" ), +N_ ("git submodule init [<options>] [<path>]" ),NULL };
@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper summary [<options>] [<commit>] [--] [<path>]" ), +N_ ("git submodule summary [<options>] [<commit>] [--] [<path>]" ),NULL };
@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper sync [--quiet] [--recursive] [<path>]" ), +N_ ("git submodule sync [--quiet] [--recursive] [<path>]" ),NULL };
@@ -2788,7 +2788,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ), +N_ ("git submodule absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -2893,7 +2893,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-url [--quiet] <path> <newurl>" ), +N_ ("git submodule set-url [--quiet] <path> <newurl>" ),NULL };
@@ -2932,8 +2932,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>" ), -N_ ("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-d|--default) <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ),NULL };
@@ -3277,7 +3277,7 @@ static int module_add(int argc, const char **argv, const char *prefix) };const char *const usage[] = { -N_ ("git submodule--helper add [<options>] [--] <repository> [<path>]" ), +N_ ("git submodule add [<options>] [--] <repository> [<path>]" ),NULL };
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 7/12 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
In reply to Ævar Arnfjörð BjarmasonRename the "absorb-git-dirs" subcommand to "absorbgitdirs", which is what the "git submodule" command itself has called it since the subcommand was implemented in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12).
Having these two be different will make it more tedious to dispatch to eventually dispatch "git submodule--helper" directly, as we'd need to retain this name mapping. So let's get rid of this needless inconsistency.
--- builtin/submodule--helper.c | 4 ++-- git-submodule.sh | 2 +- submodule.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/submodule--helper.c +2 -2
@@ -2788,7 +2788,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorb-git-dirs [<options>] [<path>...]" ), +N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -3387,7 +3387,7 @@ 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},
git-submodule.sh +1 -1
@@ -552,7 +552,7 @@ cmd_sync() cmd_absorbgitdirs() { - git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" + git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@" } # This loop parses the command line arguments to find the
submodule.c +1 -1
@@ -2374,7 +2374,7 @@ void absorb_git_dir_into_superproject(const char *path, cp.no_stdin =1 ;strvec_pushl (&cp.args,"--super-prefix" , sb.buf,"submodule--helper" , -"absorb-git-dirs" ,NULL ); +"absorbgitdirs" ,NULL );prepare_submodule_repo_env (&cp.env);if (run_command (&cp))die (_ ("could not recurse into submodule '%s'" ), path);
Signature · 1 line
2.36.1.1239.gfba91521d90
PATCH v3 11/12 git-submodule.sh: use "$quiet", not "$GIT_QUIET"
In reply to Ævar Arnfjörð BjarmasonRemove the use of the "$GIT_QUIET" variable in favor of our own "$quiet", ever since b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) we have not used the "say" function in git-sh-setup.sh, which is the only thing that's affected by using "GIT_QUIET".
We still want to support --quiet for our own use though, but let's use our own variable for that. Now it's obvious that we only care about passing "--quiet" to "git submodule--helper", and not to change the output of any "say" invocation.
--- git-submodule.sh | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
git-submodule.sh +19 -18
@@ -30,6 +30,7 @@ GIT_PROTOCOL_FROM_USER=0 export GIT_PROTOCOL_FROM_USER command= +quiet= branch= force= reference=
@@ -80,7 +81,7 @@ cmd_add() force=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --progress) progress=1
@@ -128,7 +129,7 @@ cmd_add() usage fi - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${quiet:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } #
@@ -144,7 +145,7 @@ cmd_foreach() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --recursive) recursive=1
@@ -159,7 +160,7 @@ cmd_foreach() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } #
@@ -174,7 +175,7 @@ cmd_init() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --) shift
@@ -190,7 +191,7 @@ cmd_init() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${quiet:+--quiet} -- "$@" } #
@@ -207,7 +208,7 @@ cmd_deinit() force=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --all) deinit_all=t
@@ -226,7 +227,7 @@ cmd_deinit() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${quiet:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" } #
@@ -241,7 +242,7 @@ cmd_update() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --progress) progress=1
@@ -335,7 +336,7 @@ cmd_update() done git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ - ${GIT_QUIET:+--quiet} \ + ${quiet:+--quiet} \ ${force:+--force} \ ${progress:+"--progress"} \ ${remote:+--remote} \
@@ -396,7 +397,7 @@ cmd_set_branch() { shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${quiet:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" } #
@@ -409,7 +410,7 @@ cmd_set_url() { do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --) shift
@@ -425,7 +426,7 @@ cmd_set_url() { shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@" } #
@@ -496,7 +497,7 @@ cmd_status() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --cached) cached=1
@@ -518,7 +519,7 @@ cmd_status() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" } # # Sync remote urls for submodules
@@ -531,7 +532,7 @@ cmd_sync() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 shift ;; --recursive)
@@ -551,7 +552,7 @@ cmd_sync() esac done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } cmd_absorbgitdirs()
@@ -572,7 +573,7 @@ do command=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --cached) cached=1
Signature · 1 line
2.36.1.1239.gfba91521d90
Re: [PATCH v3 08/12] submodule--helper: report "submodule" as our name in some "-h" output
In reply to Ævar Arnfjörð BjarmasonQuoted 24 lines · Ævar Arnfjörð Bjarmason
Change the user-facing "git submodule--helper" commands so that they'll report their name as being "git submodule". To a user these commands are internal implementation details, and it doesn't make sense to emit usage about an internal helper when "git submodule" is invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah error: unknown option `blah' usage: git submodule--helper absorbgitdirs [<options>] [<path>...] [...] And:$ git submodule set-url -- -- usage: git submodule--helper set-url [--quiet] <path> <newurl> [...]Now we'll start with "usage: git submodule [...]" in both of those cases. This change does not alter the "list", "name", "clone", "config" and "create-branch" commands, those are internal-only (as an aside; their usage info should probably invoke BUG(...)). This only changes the user-facing commands.
Quoted 3 lines
The "status", "deinit" and "update" commands are not included in this change, because their usage information already used "submodule" rather than "submodule--helper".
I enumerated over all of the commands just to be sure:
- The commands named here and the changed commands cover all of the uses of the usage_*/parse_options API.
- We still mention "submodule--helper" in two internal facing commands ("is-active" and "push-check"), but those call die() (should be BUG() I assume?) instead of usage_*().
- The other two commands ("resolve-relative-url-test" and "check-name") are internal facing commands that never print usage information.
So this covers all of the cases. Great!
Quoted 9 lines
I don't think it's currently possible to emit some of this usage information in practice, as
git-submodule.shwill catch unknown options, and e.g. it doesn't seem to be possible to get "add" to emit its usage information from "submodule--helper".Though that change may be superfluous now, it's also harmless, and will allow us to eventually dispatch further into "git submodule--helper" from
git-submodule.sh, while emitting the correct usage output.
Makes sense.
Quoted 86 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- builtin/submodule--helper.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)builtin/submodule--helper.c +9
-9@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper foreach [--quiet] [--recursive] [--] <command>" ), +N_ ("git submodule foreach [--quiet] [--recursive] [--] <command>" ),NULL };@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper init [<options>] [<path>]" ), +N_ ("git submodule init [<options>] [<path>]" ),NULL };@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper summary [<options>] [<commit>] [--] [<path>]" ), +N_ ("git submodule summary [<options>] [<commit>] [--] [<path>]" ),NULL };@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper sync [--quiet] [--recursive] [<path>]" ), +N_ ("git submodule sync [--quiet] [--recursive] [<path>]" ),NULL };@@ -2788,7 +2788,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ), +N_ ("git submodule absorbgitdirs [<options>] [<path>...]" ),NULL };@@ -2893,7 +2893,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-url [--quiet] <path> <newurl>" ), +N_ ("git submodule set-url [--quiet] <path> <newurl>" ),NULL };@@ -2932,8 +2932,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>" ), -N_ ("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-d|--default) <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ),NULL };@@ -3277,7 +3277,7 @@ static int module_add(int argc, const char **argv, const char *prefix) };const char *const usage[] = { -N_ ("git submodule--helper add [<options>] [--] <repository> [<path>]" ), +N_ ("git submodule add [<options>] [--] <repository> [<path>]" ),NULL };Signature · 1 line
2.36.1.1239.gfba91521d90
Re: [PATCH v3 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms
In reply to Ævar Arnfjörð BjarmasonAs you noted in your cover letter, this version of 09-10/12 is a lot cleaner and more obviously correct.
Quoted 119 lines · Ævar Arnfjörð Bjarmason
Understand --checkout, --merge and --rebase synonyms for --update={checkout,merge,rebase}, as well as the short options that 'git submodule' itself understands.
This removes a difference between the CLI API of "git submodule" and "git submodule--helper", making it easier to make the latter an alias for the former. See
48308681b07(git submodule update: have a dedicated helper for cloning, 2016-02-29) for the initial addition of --update.Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- builtin/submodule--helper.c | 30 ++++++++++++++++++++++++++++++ git-submodule.sh | 14 +++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-)builtin/submodule--helper.c +30
-0@@ -2405,6 +2405,23 @@ static void ensure_core_worktree(const char *path) } } +static const char *submodule_update_type_to_label (enum submodule_update_type type) +{ +switch (type) { +case SM_UPDATE_CHECKOUT : +return "checkout" ; +case SM_UPDATE_MERGE : +return "merge" ; +case SM_UPDATE_REBASE : +return "rebase" ; +case SM_UPDATE_UNSPECIFIED : +case SM_UPDATE_NONE : +case SM_UPDATE_COMMAND : +break ; + } +BUG ("unreachable with type %d" , type); +} +static void update_data_to_args (struct update_data *update_data,struct strvec *args) {strvec_pushl (args,"submodule--helper" ,"update" ,"--recursive" ,NULL );@@ -2583,6 +2600,7 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; +enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),@@ -2604,6 +2622,15 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_STRING (0 ,"update" , &opt.update_default,N_ ("string" ),N_ ("rebase, merge, checkout or none" )), +OPT_SET_INT (0 ,"checkout" , &update_type, +N_ ("use the 'checkout' update strategy (default)" ), +SM_UPDATE_CHECKOUT ), +OPT_SET_INT ('m' ,"merge" , &update_type, +N_ ("use the 'merge' update strategy" ), +SM_UPDATE_MERGE ), +OPT_SET_INT ('r' ,"rebase" , &update_type, +N_ ("use the 'rebase' update strategy" ), +SM_UPDATE_REBASE ),OPT_STRING_LIST (0 ,"reference" , &opt.references,N_ ("repo" ),N_ ("reference repository" )), OPT_BOOL(0, "dissociate", &opt.dissociate,@@ -2653,6 +2680,9 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; +if (update_type !=SM_UPDATE_UNSPECIFIED ) + opt.update_default =submodule_update_type_to_label (update_type); +if (opt.update_default)if (parse_submodule_update_strategy (opt.update_default, &opt.update_strategy) <0 )git-submodule.sh +6
-4@@ -40,7 +40,9 @@ require_init= files= remote= nofetch= -update= +rebase= +merge= +checkout= custom_name= depth= progress=@@ -260,7 +262,7 @@ cmd_update() force=$1 ;; -r|--rebase) - update="rebase" + rebase=1 ;; --reference) case "$2" in '') usage ;; esac@@ -274,13 +276,13 @@ cmd_update() dissociate=1 ;; -m|--merge) - update="merge" + merge=1 ;; --recursive) recursive=1 ;; --checkout) - update="checkout" + checkout=1 ;; --recommend-shallow) recommend_shallow="--recommend-shallow"
git-submodule.sh cmd_update() · line 351
Quoted 10 lines
git-submodule.sh +3
-1@@ -341,7 +343,9 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${update:+--update "$update"} \ + ${rebase:+--rebase} \ + ${merge:+--merge} \ + ${checkout:+--checkout} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \ ${depth:+"$depth"} \
A small inelegance is that a user could theoretically pass both "--update={checkout,rebase,merge}" and "--{checkout,rebase,merge}", where one option ends of clobbering the other (Is it last one wins?).
Ideally we'd check for this kind of invalid usage and die, but maybe it's not worth the effort since we fix this in the next patch already?
This wouldn't happen if we squashed 09-10/12 together like I initially suggested, but then the patches would no longer be as obviously correct.
Neither seems obviously better than the other, so I'm ok with this either way.
Re: [PATCH v3 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms
Quoted 57 lines · Glen Choo
As you noted in your cover letter, this version of 09-10/12 is a lot cleaner and more obviously correct.
Quoted 37 lines · Ævar Arnfjörð Bjarmason
git-submodule.sh +6
-4@@ -40,7 +40,9 @@ require_init= files= remote= nofetch= -update= +rebase= +merge= +checkout= custom_name= depth= progress=@@ -260,7 +262,7 @@ cmd_update() force=$1 ;; -r|--rebase) - update="rebase" + rebase=1 ;; --reference) case "$2" in '') usage ;; esac@@ -274,13 +276,13 @@ cmd_update() dissociate=1 ;; -m|--merge) - update="merge" + merge=1 ;; --recursive) recursive=1 ;; --checkout) - update="checkout" + checkout=1 ;; --recommend-shallow) recommend_shallow="--recommend-shallow"git-submodule.sh cmd_update() · line 351
Quoted 10 lines
git-submodule.sh +3
-1@@ -341,7 +343,9 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${update:+--update "$update"} \ + ${rebase:+--rebase} \ + ${merge:+--merge} \ + ${checkout:+--checkout} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \ ${depth:+"$depth"} \A small inelegance is that a user could theoretically pass both "--update={checkout,rebase,merge}" and "--{checkout,rebase,merge}", where one option ends of clobbering the other (Is it last one wins?).
Quoted 8 lines
Ideally we'd check for this kind of invalid usage and die, but maybe it's not worth the effort since we fix this in the next patch already?
This wouldn't happen if we squashed 09-10/12 together like I initially suggested, but then the patches would no longer be as obviously correct.
Neither seems obviously better than the other, so I'm ok with this either way.
Scratch that, I got confused. A user can't invoke "git submodule update --update=foo" because that's not allowed by git-submodule.sh.
So this version doesn't actually introduce any user-facing oddity unless they're invoking "git submodule--helper update" (which they really shouldn't, and we introduced it very recently anyway), and I think this makes it better to keep these patches separate instead of squashing them.
Re: [PATCH v3 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix
In reply to Ævar Arnfjörð BjarmasonQuoted 27 lines · Ævar Arnfjörð Bjarmason
Remove the $prefix variable which isn't used anymore, and hasn't been since
b3c5f5cb048(submodule: move corecmd_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
b3c5f5cb048that "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.cas well.Note also that the still-existing code in
builtin/submodule--helper.cto 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 0Doing that will cause
t7406-submodule-update.shto fail with errors such as:
Quoted 7 lines
-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
b3c5f5cb048all 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...
Quoted 8 lines
builtin/submodule--helper.c +0
-4@@ -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 ))
builtin/submodule--helper.c int cmd_submodule__helper(int argc, const char **argv, const char *prefix) · line 3407
Quoted 10 lines
builtin/submodule--helper.c +2
-4-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/[email protected]/
[2] https://lore.kernel.org/git/[email protected]/
Re: [PATCH v3 00/12] submodule: make "git submodule--helper" behave like "git submodule"
In reply to Ævar Arnfjörð BjarmasonQuoted 5 lines · Ævar Arnfjörð Bjarmason
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.shentirely, and make "git submodule" a built-in.
Quoted 7 lines
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.
Thanks for taking this up! I have some lingering confusion over the behavior described in 02/12's commit message, but I am quite convinced that 02/12 is good - the check that it removes is not needed for correctness and it doesn't make much sense as safeguard for developers [1].
Nearly everything else is very obviously correct, and I've double-checked most of the assertions in the commit messages as well. So I'm happy to give this my reviewed-by.
Re: [PATCH v3 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix
In reply to Glen ChooQuoted 100 lines · Glen Choo
Quoted 27 lines · Ævar Arnfjörð Bjarmason
Remove the $prefix variable which isn't used anymore, and hasn't been since
b3c5f5cb048(submodule: move corecmd_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
b3c5f5cb048that "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.cas well.Note also that the still-existing code in
builtin/submodule--helper.cto 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 0Doing that will cause
t7406-submodule-update.shto fail with errors such as:Quoted 7 lines
-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
b3c5f5cb048all 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
b3c5f5cb048nor b3c5f5cb048^ make any use of "--super-prefix" (both use "--recursive-prefix"). And what's most puzzling to me is...Quoted 8 lines
builtin/submodule--helper.c +0
-4@@ -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 ))builtin/submodule--helper.c int cmd_submodule__helper(int argc, const char **argv, const char *prefix) · line 3407
Quoted 10 lines
builtin/submodule--helper.c +2
-4-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 todie(). This isn't even an issue withSUPPORT_SUPER_PREFIXeither - 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_updatewithSUPPORT_SUPER_PREFIX. But because that invokes "git submodule clone", "module_clone" must also be markedSUPPORT_SUPER_PREFIX.Frankly, I'm not sure why we need to check for
SUPPORT_SUPER_PREFIXin the "git submodule--helper" subcommand. I see that it was introduced in89c8626557(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.
Quoted 6 lines
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/[email protected]/
[2] https://lore.kernel.org/git/[email protected]/
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.
Re: [PATCH v3 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix
Quoted 128 lines · Ævar Arnfjörð Bjarmason
Quoted 100 lines · Glen Choo
Quoted 27 lines · Ævar Arnfjörð Bjarmason
Remove the $prefix variable which isn't used anymore, and hasn't been since
b3c5f5cb048(submodule: move corecmd_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
b3c5f5cb048that "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.cas well.Note also that the still-existing code in
builtin/submodule--helper.cto 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 0Doing that will cause
t7406-submodule-update.shto fail with errors such as:Quoted 7 lines
-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
b3c5f5cb048all 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
b3c5f5cb048nor b3c5f5cb048^ make any use of "--super-prefix" (both use "--recursive-prefix"). And what's most puzzling to me is...Quoted 8 lines
builtin/submodule--helper.c +0
-4@@ -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 ))builtin/submodule--helper.c int cmd_submodule__helper(int argc, const char **argv, const char *prefix) · line 3407
Quoted 10 lines
builtin/submodule--helper.c +2
-4-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 todie(). This isn't even an issue withSUPPORT_SUPER_PREFIXeither - 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_updatewithSUPPORT_SUPER_PREFIX. But because that invokes "git submodule clone", "module_clone" must also be markedSUPPORT_SUPER_PREFIX.Frankly, I'm not sure why we need to check for
SUPPORT_SUPER_PREFIXin the "git submodule--helper" subcommand. I see that it was introduced in89c8626557(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.
Quoted 6 lines
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/[email protected]/
[2] https://lore.kernel.org/git/[email protected]/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 corecmd_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 inrun_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: teachupdate_datamore options, 2022-03-15).I.e.
75df9df0f81&b3c5f5cb048should 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.
Quoted 6 lines
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).
v4 cover submodule: make "git submodule--helper" behave like "git submodule"
In reply to Ævar Arnfjörð BjarmasonThese 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/[email protected]/
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 <[email protected]>
## 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 <[email protected]>
- ## 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
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 1/12 git-submodule.sh: remove unused sanitize_submodule_env()
The sanitize_submodule_env() function was last used before b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15), let's remove it.
This also allows us to remove clear_local_git_env() from git-sh-setup.sh. That function hasn't been documented in Documentation/git-sh-setup.sh, and since 14111fc4927 (git: submodule honor -c credential.* from command line, 2016-02-29) it had only been used in the sanitize_submodule_env() function being removed here.
--- git-sh-setup.sh | 7 ------- git-submodule.sh | 11 ----------- 2 files changed, 18 deletions(-)
git-sh-setup.sh +0 -7
@@ -285,13 +285,6 @@ get_author_ident_from_commit () { parse_ident_from_commit author AUTHOR } -# Clear repo-local GIT_* environment variables. Useful when switching to -# another repository (e.g. when entering a submodule). See also the env -# list in git_connect() -clear_local_git_env() { - unset $(git rev-parse --local-env-vars) -} - # Generate a virtual base file for a two-file merge. Uses git apply to # remove lines from $1 that are not in $2, leaving only common lines. create_virtual_base() {
git-submodule.sh +0 -11
@@ -56,17 +56,6 @@ isnumber() n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1" } -# Sanitize the local git environment for use within a submodule. We -# can't simply use clear_local_git_env since we want to preserve some -# of the settings from GIT_CONFIG_PARAMETERS. -sanitize_submodule_env() -{ - save_config=$GIT_CONFIG_PARAMETERS - clear_local_git_env - GIT_CONFIG_PARAMETERS=$save_config - export GIT_CONFIG_PARAMETERS -} - # # Add a new submodule to the working tree, .gitmodules and the index #
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 2/12 git-submodule.sh: remove unused $prefix variable
In reply to Ævar Arnfjörð BjarmasonRemove 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.
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 inc51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24).
--- git-submodule.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
git-submodule.sh +2 -4
@@ -41,7 +41,6 @@ files= remote= nofetch= update= -prefix= custom_name= depth= progress=
@@ -127,7 +126,7 @@ cmd_add() usage fi - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } #
@@ -189,7 +188,7 @@ cmd_init() shift done - git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" } #
@@ -346,7 +345,6 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${prefix:+--recursive-prefix "$prefix"} \ ${update:+--update "$update"} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 3/12 git-submodule.sh: make the "$cached" variable a boolean
In reply to Ævar Arnfjörð BjarmasonRemove the assignment of "$1" to the "$cached" variable. As seen in the initial implementation in 70c7ac22de6 (Add git-submodule command, 2007-05-26) we only need to keep track of if we've seen the --cached option, not save the "--cached" string for later use.
In 28f9af5d25e (git-submodule summary: code framework, 2008-03-11) "$1" was assigned to it, but since there was no reason to do so let's stop doing it. This trivial change will make it easier to reason about an eventual change that'll remove the cmd_summary() function in favor of dispatching to "git submodule--helper summary" directly.
--- git-submodule.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
git-submodule.sh +2 -2
@@ -446,7 +446,7 @@ cmd_summary() { do case "$1" in --cached) - cached="$1" + cached=1 ;; --files) files="$1"
@@ -583,7 +583,7 @@ do branch="$2"; shift ;; --cached) - cached="$1" + cached=1 ;; --) break
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 8/12 submodule--helper: report "submodule" as our name in some "-h" output
In reply to Ævar Arnfjörð BjarmasonChange the user-facing "git submodule--helper" commands so that they'll report their name as being "git submodule". To a user these commands are internal implementation details, and it doesn't make sense to emit usage about an internal helper when "git submodule" is invoked with invalid options.
Before this we'd emit e.g.:
$ git submodule absorbgitdirs --blah error: unknown option `blah' usage: git submodule--helper absorbgitdirs [<options>] [<path>...] [...] And:
$ git submodule set-url -- -- usage: git submodule--helper set-url [--quiet] <path> <newurl> [...]
Now we'll start with "usage: git submodule [...]" in both of those cases. This change does not alter the "list", "name", "clone", "config" and "create-branch" commands, those are internal-only (as an aside; their usage info should probably invoke BUG(...)). This only changes the user-facing commands.
The "status", "deinit" and "update" commands are not included in this change, because their usage information already used "submodule" rather than "submodule--helper".
I don't think it's currently possible to emit some of this usage information in practice, as git-submodule.sh will catch unknown options, and e.g. it doesn't seem to be possible to get "add" to emit its usage information from "submodule--helper".
Though that change may be superfluous now, it's also harmless, and will allow us to eventually dispatch further into "git submodule--helper" from git-submodule.sh, while emitting the correct usage output.
--- builtin/submodule--helper.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
builtin/submodule--helper.c +9 -9
@@ -444,7 +444,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper foreach [--quiet] [--recursive] [--] <command>" ), +N_ ("git submodule foreach [--quiet] [--recursive] [--] <command>" ),NULL };
@@ -582,7 +582,7 @@ static int module_init(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper init [<options>] [<path>]" ), +N_ ("git submodule init [<options>] [<path>]" ),NULL };
@@ -1185,7 +1185,7 @@ static int module_summary(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper summary [<options>] [<commit>] [--] [<path>]" ), +N_ ("git submodule summary [<options>] [<commit>] [--] [<path>]" ),NULL };
@@ -1349,7 +1349,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper sync [--quiet] [--recursive] [<path>]" ), +N_ ("git submodule sync [--quiet] [--recursive] [<path>]" ),NULL };
@@ -2788,7 +2788,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ), +N_ ("git submodule absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -2893,7 +2893,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-url [--quiet] <path> <newurl>" ), +N_ ("git submodule set-url [--quiet] <path> <newurl>" ),NULL };
@@ -2932,8 +2932,8 @@ static int module_set_branch(int argc, const char **argv, const char *prefix) OPT_END() };const char *const usage[] = { -N_ ("git submodule--helper set-branch [-q|--quiet] (-d|--default) <path>" ), -N_ ("git submodule--helper set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-d|--default) <path>" ), +N_ ("git submodule set-branch [-q|--quiet] (-b|--branch) <branch> <path>" ),NULL };
@@ -3277,7 +3277,7 @@ static int module_add(int argc, const char **argv, const char *prefix) };const char *const usage[] = { -N_ ("git submodule--helper add [<options>] [--] <repository> [<path>]" ), +N_ ("git submodule add [<options>] [--] <repository> [<path>]" ),NULL };
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 7/12 submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs"
In reply to Ævar Arnfjörð BjarmasonRename the "absorb-git-dirs" subcommand to "absorbgitdirs", which is what the "git submodule" command itself has called it since the subcommand was implemented in f6f85861400 (submodule: add absorb-git-dir function, 2016-12-12).
Having these two be different will make it more tedious to dispatch to eventually dispatch "git submodule--helper" directly, as we'd need to retain this name mapping. So let's get rid of this needless inconsistency.
--- builtin/submodule--helper.c | 4 ++-- git-submodule.sh | 2 +- submodule.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/submodule--helper.c +2 -2
@@ -2788,7 +2788,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) };const char *const git_submodule_helper_usage[] = { -N_ ("git submodule--helper absorb-git-dirs [<options>] [<path>...]" ), +N_ ("git submodule--helper absorbgitdirs [<options>] [<path>...]" ),NULL };
@@ -3390,7 +3390,7 @@ static struct cmd_struct commands[] = { {"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 +1 -1
@@ -552,7 +552,7 @@ cmd_sync() cmd_absorbgitdirs() { - git submodule--helper absorb-git-dirs --prefix "$wt_prefix" "$@" + git submodule--helper absorbgitdirs --prefix "$wt_prefix" "$@" } # This loop parses the command line arguments to find the
submodule.c +1 -1
@@ -2374,7 +2374,7 @@ void absorb_git_dir_into_superproject(const char *path, cp.no_stdin =1 ;strvec_pushl (&cp.args,"--super-prefix" , sb.buf,"submodule--helper" , -"absorb-git-dirs" ,NULL ); +"absorbgitdirs" ,NULL );prepare_submodule_repo_env (&cp.env);if (run_command (&cp))die (_ ("could not recurse into submodule '%s'" ), path);
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 6/12 submodule update: remove "-v" option
In reply to Ævar Arnfjörð BjarmasonIn e84c3cf3dc3 (git-submodule.sh: accept verbose flag in cmd_update to be non-quiet, 2018-08-14) the "git submodule update" sub-command was made to understand "-v", but the option was never documented.
The only in-tree user has been this test added in 3ad0401e9e6 (submodule update: silence underlying merge/rebase with "--quiet", 2020-09-30), it wasn't per-se testing --quiet, but fixing a bug in e84c3cf3dc3: It used to set "GIT_QUIET=0" instead of unsetting it on "-v", and thus we'd end up passing "--quiet" to "git submodule--helper" on "-v", since the "--quiet" option was passed using the ${parameter:+word} construct.
Furthermore, even if someone had used the "-v" option they'd only be getting the default output. Our default in both git-submodule.sh and "git submodule--helper" has been to be "verbose", so the only way this option could have matter is if it were used as e.g.:
git submodule --quiet update -v [...]
I.e. to undo the effect of a previous "--quiet" on the command-line.
--- git-submodule.sh | 3 --- t/t7406-submodule-update.sh | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
git-submodule.sh +0 -3
@@ -241,9 +241,6 @@ cmd_update() -q|--quiet) GIT_QUIET=1 ;; - -v) - unset GIT_QUIET - ;; --progress) progress=1 ;;
t/t7406-submodule-update.sh +1 -1
@@ -1074,7 +1074,7 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase' git submodule update --rebase --quiet >out 2>err && test_must_be_empty out && test_must_be_empty err && - git submodule update --rebase -v >out 2>err && + git submodule update --rebase >out 2>err && test_file_not_empty out && test_must_be_empty err )
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 12/12 git-sh-setup.sh: remove "say" function, change last users
In reply to Ævar Arnfjörð BjarmasonRemove the "say" function, with various rewrites of the remaining git-*.sh code to C and the preceding change to have git-submodule.sh stop using the GIT_QUIET variable there were only four uses in git-subtree.sh. Let's have it use an "arg_quiet" variable instead, and move the "say" function over to it.
The only other use was a trivial message in git-instaweb.sh, since it has never supported the --quiet option (or similar) that code added in 0b624b4ceee (instaweb: restart server if already running, 2009-11-22) can simply use "echo" instead.
The remaining in-tree hits from "say" are all for the sibling function defined in t/test-lib.sh. It's safe to remove this function since it has never been documented in Documentation/git-sh-setup.txt.
--- contrib/subtree/git-subtree.sh | 15 ++++++++++++--- git-instaweb.sh | 2 +- git-sh-setup.sh | 9 --------- 3 files changed, 13 insertions(+), 13 deletions(-)
contrib/subtree/git-subtree.sh +12 -3
@@ -50,6 +50,14 @@ m,message= use the given message as the commit message for the merge commit indent=0 +# Usage: say [MSG...] +say () { + if test -z "$arg_quiet" + then + printf '%s\n' "$*" + fi +} + # Usage: debug [MSG...] debug () { if test -n "$arg_debug"
@@ -60,7 +68,7 @@ debug () { # Usage: progress [MSG...] progress () { - if test -z "$GIT_QUIET" + if test -z "$arg_quiet" then if test -z "$arg_debug" then
@@ -146,6 +154,7 @@ main () { eval "$set_args" # Begin "real" flag parsing. + arg_quiet= arg_debug= arg_prefix= arg_split_branch=
@@ -161,7 +170,7 @@ main () { case "$opt" in -q) - GIT_QUIET=1 + arg_quiet=1 ;; -d) arg_debug=1
@@ -252,7 +261,7 @@ main () { dir="$(dirname "$arg_prefix/.")" debug "command: {$arg_command}" - debug "quiet: {$GIT_QUIET}" + debug "quiet: {$arg_quiet}" debug "dir: {$dir}" debug "opts: {$*}" debug
git-instaweb.sh +1 -1
@@ -102,7 +102,7 @@ resolve_full_httpd () { start_httpd () { if test -f "$fqgitdir/pid"; then - say "Instance already running. Restarting..." + echo "Instance already running. Restarting..." stop_httpd fi
git-sh-setup.sh +0 -9
@@ -57,15 +57,6 @@ die_with_status () { exit "$status" } -GIT_QUIET= - -say () { - if test -z "$GIT_QUIET" - then - printf '%s\n' "$*" - fi -} - if test -n "$OPTIONS_SPEC"; then usage() { "$0" -h
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 4/12 git-submodule.sh: remove unused top-level "--branch" argument
In reply to Ævar Arnfjörð BjarmasonIn 5c08dbbdf1a (git-submodule: fix subcommand parser, 2008-01-15) the "--branch" option was supported as an option to "git submodule" itself, i.e. "git submodule --branch" as a side-effect of its implementation.
Then in b57e8119e6e (submodule: teach set-branch subcommand, 2019-02-08) when the "set-branch" subcommand was added the assertion that we shouldn't have "--branch" anywhere except as an argument to "add" and "set-branch" was copy/pasted from the adjacent check for "--cache" added (or rather modified) in 496eeeb19b9 (git-submodule.sh:
avoid "test <cond> -a/-o <cond>", 2014-06-10).
But there's been a logic error in that check, which at a glance looked like it should be supporting:
git submodule --branch <branch> (add | set-branch) [<options>]
But due to "||" in the condition (as opposed to "&&" for "--cache") if we have "--branch" here already we'll emit usage, even for "add" and "set-branch".
So in addition to never having documented this form, it hasn't worked since b57e8119e6e was released with v2.22.0.
So it's safe to remove this code. I.e. we don't want to support the form noted above, but only:
git submodule (add | set-branch) --branch <branch> [<options>]
--- git-submodule.sh | 14 -------------- 1 file changed, 14 deletions(-)
git-submodule.sh +0 -14
@@ -574,14 +574,6 @@ do -q|--quiet) GIT_QUIET=1 ;; - -b|--branch) - case "$2" in - '') - usage - ;; - esac - branch="$2"; shift - ;; --cached) cached=1 ;;
@@ -609,12 +601,6 @@ then fi fi -# "-b branch" is accepted only by "add" and "set-branch" -if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) -then - usage -fi - # "--cached" is accepted only by "status" and "summary" if test -n "$cached" && test "$command" != status && test "$command" != summary then
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 5/12 submodule--helper: have --require-init imply --init
In reply to Ævar Arnfjörð BjarmasonAdjust code added in 0060fd1511b (clone --recurse-submodules: prevent name squatting on Windows, 2019-09-12) to have the internal --require-init option imply --init, rather than having "git-submodule.sh" add it implicitly.
This change doesn't make any difference now, but eliminates another special-case where "git submodule--helper update"'s behavior was different from "git submodule update". This will make it easier to eventually replace the cmd_update() function in git-submodule.sh.
We'll still need to keep the distinction between "--init" and "--require-init" in git-submodule.sh. Once cmd_update() gets re-implemented in C we'll be able to change variables and other code related to that, but not yet.
--- builtin/submodule--helper.c | 5 ++++- git-submodule.sh | 1 - 2 files changed, 4 insertions(+), 2 deletions(-)
builtin/submodule--helper.c +4 -1
@@ -2619,7 +2619,7 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_BOOL (0 ,"progress" , &opt.progress,N_ ("force cloning progress" )),OPT_BOOL (0 ,"require-init" , &opt.require_init, -N_ ("disallow cloning into non-empty directory" )), +N_ ("disallow cloning into non-empty directory, implies --init" )),OPT_BOOL (0 ,"single-branch" , &opt.single_branch,N_ ("clone only one branch, HEAD or --branch" )), OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
@@ -2643,6 +2643,9 @@ static int module_update(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv, prefix, module_update_options, git_submodule_helper_usage,0 ); +if (opt.require_init) + opt.init =1 ; +if (filter_options.choice && !opt.init) {usage_with_options (git_submodule_helper_usage, module_update_options);
git-submodule.sh +0 -1
@@ -251,7 +251,6 @@ cmd_update() init=1 ;; --require-init) - init=1 require_init=1 ;; --remote)
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 10/12 submodule--helper: eliminate internal "--update" option
In reply to Ævar Arnfjörð BjarmasonFrom: Glen Choo <[email protected]>
Follow-up on the preceding commit which taught "git submodule--helper update" to understand "--merge", "--checkout" and "--rebase" and use those options instead of "--update=(rebase|merge|checkout|none)" when the command invokes itself.
Unlike the preceding change this isn't strictly necessary to eventually change "git-submodule.sh" so that it invokes "git submodule--helper update" directly, but let's remove this inconsistency in the command-line interface. We shouldn't need to carry special synonyms for existing options in "git submodule--helper" when that command can use the primary documented names instead.
But, as seen in the post-image this makes the control flow within "builtin/submodule--helper.c" simpler, we can now write directly to the "update_default" member of "struct update_data" when parsing the options in "module_update()".
--- builtin/submodule--helper.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
builtin/submodule--helper.c +13 -20
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)static void determine_submodule_update_strategy (struct repository *r,int just_cloned,const char *path, -const char *update, +enum submodule_update_type update,struct submodule_update_strategy *out) {const struct submodule *sub =submodule_from_path (r,null_oid (), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r, key =xstrfmt ("submodule.%s.update" , sub->name);if (update) { -if (parse_submodule_update_strategy (update, out) <0 ) -die (_ ("Invalid update mode '%s' for submodule path '%s'" ), - update, path); + out->type = update; }else if (!repo_config_get_string_tmp (r, key, &val)) {if (parse_submodule_update_strategy (val, out) <0 ) die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,7 @@ struct update_data {const char *prefix;const char *recursive_prefix;const char *displaypath; -const char *update_default; +enum submodule_update_type update_default;struct object_id suboid;struct string_list references;struct submodule_update_strategy update_strategy;
@@ -2424,6 +2422,8 @@ static const char *submodule_update_type_to_label(enum submodule_update_type typstatic void update_data_to_args (struct update_data *update_data,struct strvec *args) { +enum submodule_update_type update_type = update_data->update_default; +strvec_pushl (args,"submodule--helper" ,"update" ,"--recursive" ,NULL );strvec_pushf (args,"--jobs=%d" , update_data->max_jobs);if (update_data->recursive_prefix)
@@ -2447,8 +2447,10 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *strvec_push (args,"--require-init" );if (update_data->depth)strvec_pushf (args,"--depth=%d" , update_data->depth); -if (update_data->update_default) -strvec_pushl (args,"--update" , update_data->update_default,NULL ); +if (update_type !=SM_UPDATE_UNSPECIFIED ) +strvec_pushf (args,"--%s" , +submodule_update_type_to_label (update_type)); +if (update_data->references.nr) {struct string_list_item *item;for_each_string_list_item (item, &update_data->references)
@@ -2600,7 +2602,6 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; -enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2619,16 +2620,13 @@ static int module_update(int argc, const char **argv, const char *prefix) N_("path"), N_("path into the working tree, across nested " "submodule boundaries")), -OPT_STRING (0 ,"update" , &opt.update_default, -N_ ("string" ), -N_ ("rebase, merge, checkout or none" )), -OPT_SET_INT (0 ,"checkout" , &update_type, +OPT_SET_INT (0 ,"checkout" , &opt.update_default,N_ ("use the 'checkout' update strategy (default)" ),SM_UPDATE_CHECKOUT ), -OPT_SET_INT ('m' ,"merge" , &update_type, +OPT_SET_INT ('m' ,"merge" , &opt.update_default,N_ ("use the 'merge' update strategy" ),SM_UPDATE_MERGE ), -OPT_SET_INT ('r' ,"rebase" , &update_type, +OPT_SET_INT ('r' ,"rebase" , &opt.update_default,N_ ("use the 'rebase' update strategy" ),SM_UPDATE_REBASE ), OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
@@ -2680,13 +2678,8 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; -if (update_type !=SM_UPDATE_UNSPECIFIED ) - opt.update_default =submodule_update_type_to_label (update_type); -if (opt.update_default) -if (parse_submodule_update_strategy (opt.update_default, - &opt.update_strategy) <0 ) -die (_ ("bad value for update parameter" )); + opt.update_strategy.type = opt.update_default;if (module_list_compute (argc, argv, prefix, &pathspec, &opt.list) <0 ) {list_objects_filter_release (&filter_options);
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 11/12 git-submodule.sh: use "$quiet", not "$GIT_QUIET"
In reply to Ævar Arnfjörð BjarmasonRemove the use of the "$GIT_QUIET" variable in favor of our own "$quiet", ever since b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) we have not used the "say" function in git-sh-setup.sh, which is the only thing that's affected by using "GIT_QUIET".
We still want to support --quiet for our own use though, but let's use our own variable for that. Now it's obvious that we only care about passing "--quiet" to "git submodule--helper", and not to change the output of any "say" invocation.
--- git-submodule.sh | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
git-submodule.sh +19 -18
@@ -30,6 +30,7 @@ GIT_PROTOCOL_FROM_USER=0 export GIT_PROTOCOL_FROM_USER command= +quiet= branch= force= reference=
@@ -80,7 +81,7 @@ cmd_add() force=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --progress) progress=1
@@ -128,7 +129,7 @@ cmd_add() usage fi - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${quiet:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@" } #
@@ -144,7 +145,7 @@ cmd_foreach() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --recursive) recursive=1
@@ -159,7 +160,7 @@ cmd_foreach() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } #
@@ -174,7 +175,7 @@ cmd_init() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --) shift
@@ -190,7 +191,7 @@ cmd_init() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${quiet:+--quiet} -- "$@" } #
@@ -207,7 +208,7 @@ cmd_deinit() force=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --all) deinit_all=t
@@ -226,7 +227,7 @@ cmd_deinit() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${quiet:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@" } #
@@ -241,7 +242,7 @@ cmd_update() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --progress) progress=1
@@ -335,7 +336,7 @@ cmd_update() done git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \ - ${GIT_QUIET:+--quiet} \ + ${quiet:+--quiet} \ ${force:+--force} \ ${progress:+"--progress"} \ ${remote:+--remote} \
@@ -396,7 +397,7 @@ cmd_set_branch() { shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${quiet:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@" } #
@@ -409,7 +410,7 @@ cmd_set_url() { do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --) shift
@@ -425,7 +426,7 @@ cmd_set_url() { shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${quiet:+--quiet} -- "$@" } #
@@ -496,7 +497,7 @@ cmd_status() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --cached) cached=1
@@ -518,7 +519,7 @@ cmd_status() shift done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${quiet:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@" } # # Sync remote urls for submodules
@@ -531,7 +532,7 @@ cmd_sync() do case "$1" in -q|--quiet) - GIT_QUIET=1 + quiet=1 shift ;; --recursive)
@@ -551,7 +552,7 @@ cmd_sync() esac done - git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@" + git ${wt_prefix:+-C "$wt_prefix"} submodule--helper sync ${quiet:+--quiet} ${recursive:+--recursive} -- "$@" } cmd_absorbgitdirs()
@@ -572,7 +573,7 @@ do command=$1 ;; -q|--quiet) - GIT_QUIET=1 + quiet=1 ;; --cached) cached=1
Signature · 1 line
2.37.0.880.gf07d56b18ba
PATCH v4 9/12 submodule--helper: understand --checkout, --merge and --rebase synonyms
In reply to Ævar Arnfjörð BjarmasonUnderstand --checkout, --merge and --rebase synonyms for --update={checkout,merge,rebase}, as well as the short options that 'git submodule' itself understands.
This removes a difference between the CLI API of "git submodule" and "git submodule--helper", making it easier to make the latter an alias for the former. See 48308681b07 (git submodule update: have a dedicated helper for cloning, 2016-02-29) for the initial addition of --update.
--- builtin/submodule--helper.c | 30 ++++++++++++++++++++++++++++++ git-submodule.sh | 14 +++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-)
builtin/submodule--helper.c +30 -0
@@ -2405,6 +2405,23 @@ static void ensure_core_worktree(const char *path) } } +static const char *submodule_update_type_to_label (enum submodule_update_type type) +{ +switch (type) { +case SM_UPDATE_CHECKOUT : +return "checkout" ; +case SM_UPDATE_MERGE : +return "merge" ; +case SM_UPDATE_REBASE : +return "rebase" ; +case SM_UPDATE_UNSPECIFIED : +case SM_UPDATE_NONE : +case SM_UPDATE_COMMAND : +break ; + } +BUG ("unreachable with type %d" , type); +} +static void update_data_to_args (struct update_data *update_data,struct strvec *args) {strvec_pushl (args,"submodule--helper" ,"update" ,"--recursive" ,NULL );
@@ -2583,6 +2600,7 @@ static int module_update(int argc, const char **argv, const char *prefix)struct update_data opt =UPDATE_DATA_INIT ;struct list_objects_filter_options filter_options;int ret; +enum submodule_update_type update_type =SM_UPDATE_UNSPECIFIED ;struct option module_update_options[] = {OPT__FORCE (&opt.force,N_ ("force checkout updates" ),0 ),
@@ -2604,6 +2622,15 @@ static int module_update(int argc, const char **argv, const char *prefix)OPT_STRING (0 ,"update" , &opt.update_default,N_ ("string" ),N_ ("rebase, merge, checkout or none" )), +OPT_SET_INT (0 ,"checkout" , &update_type, +N_ ("use the 'checkout' update strategy (default)" ), +SM_UPDATE_CHECKOUT ), +OPT_SET_INT ('m' ,"merge" , &update_type, +N_ ("use the 'merge' update strategy" ), +SM_UPDATE_MERGE ), +OPT_SET_INT ('r' ,"rebase" , &update_type, +N_ ("use the 'rebase' update strategy" ), +SM_UPDATE_REBASE ),OPT_STRING_LIST (0 ,"reference" , &opt.references,N_ ("repo" ),N_ ("reference repository" )), OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2653,6 +2680,9 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.filter_options = &filter_options; +if (update_type !=SM_UPDATE_UNSPECIFIED ) + opt.update_default =submodule_update_type_to_label (update_type); +if (opt.update_default)if (parse_submodule_update_strategy (opt.update_default, &opt.update_strategy) <0 )
git-submodule.sh +9 -5
@@ -40,7 +40,9 @@ require_init= files= remote= nofetch= -update= +rebase= +merge= +checkout= custom_name= depth= progress=
@@ -260,7 +262,7 @@ cmd_update() force=$1 ;; -r|--rebase) - update="rebase" + rebase=1 ;; --reference) case "$2" in '') usage ;; esac
@@ -274,13 +276,13 @@ cmd_update() dissociate=1 ;; -m|--merge) - update="merge" + merge=1 ;; --recursive) recursive=1 ;; --checkout) - update="checkout" + checkout=1 ;; --recommend-shallow) recommend_shallow="--recommend-shallow"
@@ -341,7 +343,9 @@ cmd_update() ${init:+--init} \ ${nofetch:+--no-fetch} \ ${wt_prefix:+--prefix "$wt_prefix"} \ - ${update:+--update "$update"} \ + ${rebase:+--rebase} \ + ${merge:+--merge} \ + ${checkout:+--checkout} \ ${reference:+"$reference"} \ ${dissociate:+"--dissociate"} \ ${depth:+"$depth"} \
Signature · 1 line
2.37.0.880.gf07d56b18ba
Re: [PATCH v4 00/12] submodule: make "git submodule--helper" behave like "git submodule"
In reply to Ævar Arnfjörð BjarmasonQuoted 5 lines · Ævar Arnfjörð Bjarmason
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.
Quoted 8 lines
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/[email protected]/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.
Agreed. Since we no longer touch "--super-prefix", I think there aren't any remaining concerns.
In v3, I was slightly concerned that we didn't fully understand the rationale behind "--super-prefix" before changing it, but I still gave that version my Reviewed-by because I'm convinced that the "--super-prefix" check isn't doing anything useful (and can be annoyingly overzealous).