git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glen Choo <chooglen@google.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Atharva Raykar <raykar.ath@gmail.com>
Subject: Re: [PATCH v3 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix
Date: Fri, 24 Jun 2022 09:48:36 -0700	[thread overview]
Message-ID: <kl6ledzehusb.fsf@chooglen-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <220624.86h74ahygt.gmgdl@evledraar.gmail.com>

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

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

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

- 29a5e9e1ffe and its parent teach init_submodule() how to use the
  "--recursive-prefix" flag as a substitute for "--super-prefix".
  "--recursive-prefix" is used exclusively by "git submodule update" and
  does exactly the same thing as "--super-prefix".

  Those commits pass "--recursive-prefix" to
  do_get_submodule_displaypath(), which is an escape hatch to
  get_submodule_displaypath() (which always uses "--super-prefix").

- 75df9df0f81 introduced a regression because we now pass
  update_data.prefix to get_submodule_displaypath() instead of prefix,
  and update_data.prefix was never set (oops, that's my mistake). This
  was rectified in its child (b3c5f5cb048), where we start to set
  update_data.prefix when the two subcommands were combined.

  As a sidenote, in 75df9df0f81's diff, we see that recursive_prefix is
  used in conjunction with get_submodule_displaypath(), which means that
  we could theoretically use *both* "--recursive-prefix" AND
  "--super-prefix" at the same time. We don't do that though, because
  "--super-prefix" was never used by "git submodule update".

  (This prefixed_path stuff is going away when I convert
  "--recursive-prefix" to "--super-prefix", so don't feel the need to
  clean it up).

  reply	other threads:[~2022-06-24 16:48 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10  0:26 [PATCH 0/8] [RFC] submodule update: parse all options in C Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 1/8] submodule update: remove intermediate parsing Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 2/8] submodule update: pass options containing "[no-]" Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 3/8] submodule update: pass options with stuck forms Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 4/8] submodule update: pass --require-init and --init Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 5/8] submodule--helper update: use one param per type Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 6/8] submodule update: remove -v, pass --quiet Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 7/8] submodule update: stop parsing options in .sh Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 8/8] submodule update: remove never-used expansion Glen Choo via GitGitGadget
2022-06-10  2:01 ` [RFC PATCH 00/20] submodule: remove git-submodule.sh, create bare builtin/submodule.c Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 01/20] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 02/20] git-submodule.sh: remove unused $prefix variable Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 03/20] git-submodule.sh: remove unused --super-prefix logic Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 04/20] git-submodule.sh: normalize parsing of "--branch" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 05/20] git-submodule.sh: normalize parsing of --cached Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 06/20] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 07/20] git-submodule.sh: create a "case" dispatch statement Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 08/20] submodule--helper: pretend to be "git submodule" in "-h" output Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 09/20] git-submodule.sh: dispatch "sync" to helper Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 10/20] git-submodule.sh: dispatch directly " Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 11/20] git-submodule.sh: dispatch "foreach" " Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 12/20] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 13/20] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 14/20] git-submodule doc: document the -v" option to "update" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 15/20] submodule--helper: understand -v option for "update" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 16/20] git-submodule.sh: dispatch "update" to helper Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 17/20] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 18/20] git-submodule.sh: simplify parsing loop Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 19/20] submodule: make it a built-in, remove git-submodule.sh Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 20/20] submodule: add a subprocess-less submodule.useBuiltin setting Ævar Arnfjörð Bjarmason
2022-06-13 19:07   ` [RFC PATCH 00/20] submodule: remove git-submodule.sh, create bare builtin/submodule.c Glen Choo
2022-06-13 22:38     ` [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule" Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 01/12] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 03/12] git-submodule.sh: make "$cached" variable a boolean Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 04/12] git-submodule.sh: remove unused top-level "--branch" argument Ævar Arnfjörð Bjarmason
2022-06-15  0:10         ` Glen Choo
2022-06-13 22:38       ` [PATCH v2 05/12] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-15  0:19         ` Glen Choo
2022-06-13 22:38       ` [PATCH v2 06/12] submodule update: remove "-v" option Ævar Arnfjörð Bjarmason
2022-06-15  0:29         ` Glen Choo
2022-06-13 22:38       ` [PATCH v2 07/12] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 08/12] submodule--helper: report "submodule" as our name in "-h" output Ævar Arnfjörð Bjarmason
2022-06-15  3:34         ` Glen Choo
2022-06-15  4:01         ` Glen Choo
2022-06-15  9:42           ` Ævar Arnfjörð Bjarmason
2022-06-13 22:39       ` [PATCH v2 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-13 22:39       ` [PATCH v2 10/12] submodule--helper: eliminate internal "--update" option Ævar Arnfjörð Bjarmason
2022-06-15 16:52         ` Glen Choo
2022-06-13 22:39       ` [PATCH v2 11/12] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-13 22:39       ` [PATCH v2 12/12] git-sh-setup.sh: remove "say" function, change last users Ævar Arnfjörð Bjarmason
2022-06-15 16:58         ` Glen Choo
2022-06-13 23:09       ` [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule" Glen Choo
2022-06-13 23:31         ` Ævar Arnfjörð Bjarmason
2022-06-15  0:00           ` Glen Choo
2022-06-15 18:42       ` Glen Choo
2022-06-22 14:27       ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2022-06-22 14:27         ` [PATCH v3 01/12] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-22 14:27         ` [PATCH v3 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix Ævar Arnfjörð Bjarmason
2022-06-22 23:43           ` Glen Choo
2022-06-24 15:07             ` Ævar Arnfjörð Bjarmason
2022-06-24 16:48               ` Glen Choo [this message]
2022-06-22 14:27         ` [PATCH v3 03/12] git-submodule.sh: make the "$cached" variable a boolean Ævar Arnfjörð Bjarmason
2022-06-22 14:27         ` [PATCH v3 04/12] git-submodule.sh: remove unused top-level "--branch" argument Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 05/12] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 06/12] submodule update: remove "-v" option Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 07/12] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 08/12] submodule--helper: report "submodule" as our name in some "-h" output Ævar Arnfjörð Bjarmason
2022-06-22 18:28           ` Glen Choo
2022-06-22 14:28         ` [PATCH v3 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-22 18:57           ` Glen Choo
2022-06-22 19:04             ` Glen Choo
2022-06-22 14:28         ` [PATCH v3 10/12] submodule--helper: eliminate internal "--update" option Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 11/12] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 12/12] git-sh-setup.sh: remove "say" function, change last users Ævar Arnfjörð Bjarmason
2022-06-24  3:39         ` [PATCH v3 00/12] submodule: make "git submodule--helper" behave like "git submodule" Glen Choo
2022-06-28 10:05         ` [PATCH v4 " Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 01/12] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 02/12] git-submodule.sh: remove unused $prefix variable Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 03/12] git-submodule.sh: make the "$cached" variable a boolean Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 04/12] git-submodule.sh: remove unused top-level "--branch" argument Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 05/12] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 06/12] submodule update: remove "-v" option Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 07/12] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 08/12] submodule--helper: report "submodule" as our name in some "-h" output Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 10/12] submodule--helper: eliminate internal "--update" option Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 11/12] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 12/12] git-sh-setup.sh: remove "say" function, change last users Ævar Arnfjörð Bjarmason
2022-06-28 16:52           ` [PATCH v4 00/12] submodule: make "git submodule--helper" behave like "git submodule" Glen Choo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=kl6ledzehusb.fsf@chooglen-macbookpro.roam.corp.google.com \
    --to=chooglen@google.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=raykar.ath@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).