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

Re: [PATCH 04/10] git-submodule.sh: dispatch "foreach" to helper

From
Glen Choo <chooglen@google.com>
Date
Oct 20, 2022, 21:14 UTC
Message-ID
<kl6ly1taxkn4.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<patch-04.10-db6a09ee42a-20221017T115544Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 5 quoted lines
> Dispatch 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.

The commands in the previous patch also unconditionally add "--", so this wasn't clear to me on first read.

It might be clearer to include some extra context, which is that "git submodule foreach" is different because everything after "foreach" should be treated like a single comand to run even if they are passed as separate strings, e.g. from t/t7407-submodule-foreach.sh.21, these two should be equivalent:

  git submodule foreach "echo be --quiet"
vs
  git submodule foreach echo be --quiet

So PARSE_OPT_STOP_AT_NON_OPTION is necessary in order to stop us from intepreting option-like args as args to "git submodule foreach" instead of as part of the command to run. Without PARSE_OPT_STOP_AT_NON_OPTION,

  git submodule foreach echo be --quiet
becomes more like
  git submodule foreach --quiet "echo be"

There could have been a subtle change in behavior, since "git submodule foreach -- --foo" will be parsed as if "--foo" is the command, but PARSE_OPT_STOP_AT_NON_OPTION will happily accept "--foo" as an option. But we could never get into this situation anyway since we used to emit usage on the first option-like arg...

Show 20 quoted lines
> -# 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)
> -			quiet=1
> -			;;
> -		--recursive)
> -			recursive=1
> -			;;
> -		-*)
> -			usage
> -			;;
i.e. here. 
So this patch looks safe.
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 6 of 18 in “submodule: make it a built-in, remove git-submodule.sh”
  1. 00/10 submodule: make it a built-in, remove git-submodule.shÆvar Arnfjörð Bjarmason, Oct 17, 2022
  2. 01/10 git-submodule.sh: create a "case" dispatch statementÆvar Arnfjörð Bjarmason, Oct 17, 2022
  3. 02/10 git-submodule.sh: dispatch "sync" to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  4. Glen ChooOct 20, 2022
  5. 04/10 git-submodule.sh: dispatch "foreach" to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  6. Glen ChooOct 20, 2022
  7. 03/10 git-submodule.sh: dispatch directly to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  8. 06/10 git-submodule.sh: don't support top-level "--cached"Ævar Arnfjörð Bjarmason, Oct 17, 2022
  9. Glen ChooOct 20, 2022
  10. 05/10 git-submodule.sh: dispatch "update" to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  11. Glen ChooOct 20, 2022
  12. 08/10 submodule: support "--" with no other argumentsÆvar Arnfjörð Bjarmason, Oct 17, 2022
  13. 09/10 submodule: support sub-command-less "--recursive" optionÆvar Arnfjörð Bjarmason, Oct 17, 2022
  14. Glen ChooOct 20, 2022
  15. 07/10 submodule: make it a built-in, remove git-submodule.shÆvar Arnfjörð Bjarmason, Oct 17, 2022
  16. Glen ChooOct 20, 2022
  17. 10/10 submodule: don't use a subprocess to invoke "submodule--helper"Ævar Arnfjörð Bjarmason, Oct 17, 2022
  18. Glen ChooOct 20, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.