git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Glen Choo via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Jonathan Tan" <jonathantanmy@google.com>,
	"Glen Choo" <chooglen@google.com>
Subject: Re: [PATCH 1/4] branch: support more tracking modes when recursing
Date: Wed, 30 Mar 2022 14:13:10 -0700	[thread overview]
Message-ID: <xmqqee2j6t5l.fsf@gitster.g> (raw)
In-Reply-To: <0b682c173c8cfa7f49ba17b2d71049ac702ec747.1648584079.git.gitgitgadget@gmail.com> (Glen Choo via GitGitGadget's message of "Tue, 29 Mar 2022 20:01:16 +0000")

"Glen Choo via GitGitGadget" <gitgitgadget@gmail.com> writes:

> diff --git a/branch.c b/branch.c
> index 6b31df539a5..7377b9f451a 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -233,6 +233,9 @@ static void setup_tracking(const char *new_ref, const char *orig_ref,
>  	struct string_list tracking_srcs = STRING_LIST_INIT_DUP;
>  	int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE;
>  
> +	if (!track)
> +		BUG("asked to set up tracking, but tracking is disallowed");

I am wondering if this wants to be

	if (track == BRANCH_TRACK_NEVER)

instead.  Do we elsewhere rely on the fact that NEVER is assigned 0?

> @@ -534,8 +537,27 @@ static int submodule_create_branch(struct repository *r,
>  		strvec_push(&child.args, "--quiet");
>  	if (reflog)
>  		strvec_push(&child.args, "--create-reflog");
> -	if (track == BRANCH_TRACK_ALWAYS || track == BRANCH_TRACK_EXPLICIT)
> -		strvec_push(&child.args, "--track");
> +
> +	switch (track) {
> +	case BRANCH_TRACK_NEVER:
> +		strvec_push(&child.args, "--no-track");
> +		break;
> +	case BRANCH_TRACK_ALWAYS:
> +	case BRANCH_TRACK_EXPLICIT:
> +		strvec_push(&child.args, "--track=direct");
> +		break;
> +	case BRANCH_TRACK_OVERRIDE:
> +		BUG("BRANCH_TRACK_OVERRIDE cannot be used when creating a branch.");
> +		break;
> +	case BRANCH_TRACK_INHERIT:
> +		strvec_push(&child.args, "--track=inherit");
> +		break;

OK.

> +	case BRANCH_TRACK_UNSPECIFIED:
> +		/* Default for "git checkout". No need to pass --track. */
> +	case BRANCH_TRACK_REMOTE:
> +		/* Default for "git branch". No need to pass --track. */
> +		break;

Is that "no need to pass", or "no need to, and it will be detrimental to, pass"?

IOW, if we are relying on the command spawned via start_command()
interface to read and honor the configured default for themselves,
then passing explicit --track=whatever from this caller will be not
just necessary but is wrong, right?  I am worried about "No need to"
tempting "helpful" developers into doing unnecessary things, just to
be more explicit, for example. 

> @@ -614,7 +636,8 @@ void create_branches_recursively(struct repository *r, const char *name,
>  	 * tedious to determine whether or not tracking was set up in the
>  	 * superproject.
>  	 */
> -	setup_tracking(name, tracking_name, track, quiet);
> +	if (track)
> +		setup_tracking(name, tracking_name, track, quiet);

Here we do rely on the fact that NEVER has the value of 0.  If there
are other instances of code elsewhere that does so, then this one
and the other one at the top of this message are both fine.

Given that we started simple and then gradually added more features,
I would not be surprised if the older code written back when there
were only 0 (no track) and 1 (track) assumed 0 means no.  There is
one in create_branch() where we do

	if (real_ref && track)
		setup_tracking(ref.buf + 11, real_ref, track, quiet);

which also relies on the fact that NEVER is 0.

> -		OPT_SET_INT('t', "track", &track,
> -			    N_("set up tracking mode (see git-pull(1))"),
> -			    BRANCH_TRACK_EXPLICIT),
> +		OPT_CALLBACK_F('t', "track",  &track, "(direct|inherit)",
> +			N_("set branch tracking configuration"),
> +			PARSE_OPT_OPTARG,
> +			parse_opt_tracking_mode),

Hmph, this is quite curious.  How did the whole thing even worked
without this?

Ah, OK, this is in submodule--helper.c and tracking specification in
the top-level were OK.  Just that we forgot to correctly pass it
down when calling down to submodules.  Makes sense.

Thanks.

  reply	other threads:[~2022-03-30 21:13 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 20:01 [PATCH 0/4] branch --recurse-submodules: Bug fixes and clean ups Glen Choo via GitGitGadget
2022-03-29 20:01 ` [PATCH 1/4] branch: support more tracking modes when recursing Glen Choo via GitGitGadget
2022-03-30 21:13   ` Junio C Hamano [this message]
2022-03-30 23:29     ` Glen Choo
2022-03-29 20:01 ` [PATCH 2/4] branch: give submodule updating advice before exit Glen Choo via GitGitGadget
2022-03-30 21:15   ` Junio C Hamano
2022-03-29 20:01 ` [PATCH 3/4] branch --set-upstream-to: be consistent when advising Glen Choo via GitGitGadget
2022-03-30 22:28   ` Ævar Arnfjörð Bjarmason
2022-03-31 16:52     ` Glen Choo
2022-03-29 20:01 ` [PATCH 4/4] branch: remove negative exit code Glen Choo via GitGitGadget
2022-03-31 18:49 ` [PATCH v2 0/4] branch --recurse-submodules: Bug fixes and clean ups Glen Choo via GitGitGadget
2022-03-31 18:49   ` [PATCH v2 1/4] branch: support more tracking modes when recursing Glen Choo via GitGitGadget
2022-03-31 18:49   ` [PATCH v2 2/4] branch: give submodule updating advice before exit Glen Choo via GitGitGadget
2022-03-31 18:50   ` [PATCH v2 3/4] branch --set-upstream-to: be consistent when advising Glen Choo via GitGitGadget
2022-03-31 18:50   ` [PATCH v2 4/4] branch: remove negative exit code Glen Choo via GitGitGadget
2022-03-31 22:39   ` [PATCH v2 0/4] branch --recurse-submodules: Bug fixes and clean ups Junio C Hamano
2022-03-31 22:41     ` [PATCH 1/2] branch: rework comments for future developers Junio C Hamano
2022-03-31 22:41       ` [PATCH 2/2] branch.c: simplify advice-and-die sequence Junio C Hamano
2022-04-01 10:03         ` Ævar Arnfjörð Bjarmason
2022-04-01 16:59     ` [PATCH v2 0/4] branch --recurse-submodules: Bug fixes and clean ups Glen Choo
2022-04-01 20:14       ` Junio C Hamano

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=xmqqee2j6t5l.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=jonathantanmy@google.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).