All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Phillip Wood <phillip.wood123@gmail.com>,
	 "D. Ben Knoble" <ben.knoble@gmail.com>,
	 Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH v3 1/4] fetch: add remote.<name>.refmap
Date: Fri, 25 Sep 2026 15:38:39 -0700	[thread overview]
Message-ID: <xmqq5wztt0r4.fsf@gitster.g> (raw)
In-Reply-To: <b04c00b974ce488ea1eb82556040fb54c05dad5a.1790333402.git.gitgitgadget@gmail.com> (Harald Nordgren via GitGitGadget's message of "Fri, 25 Sep 2026 10:49:59 +0000")

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> Add a per-remote config variable, remote.<name>.refmap, that provides
> the default value for --refmap the same way remote.<name>.fetch
> already provides the default refspecs to fetch. It only takes effect
> when there is something explicit to fetch, on the command line or via

This ...

> remote.<name>.fetch, matching how --refmap itself already behaves.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>

> +remote.<name>.refmap::
> +	The default value of the `--refmap` option for linkgit:git-fetch[1].
> +	Only takes effect when the fetch names what to fetch explicitly,
> +	either on the command line or via `remote.<name>.fetch`. See the
> +	`--refmap` entry in linkgit:git-fetch[1].

... and this made me a bit puzzled.  It may be a philosophical
difference, but I've always viewed --refmap=<src>:<dst> to "take
effect" whenever they are given, regardless of 0, 1, or more
explicit things to fetch.  It is just when you have zero explicit
things to fetch, 0 things are mapped via the refmap mechanism and 0
things are fetched.

In other words, what does not "take effect" when 0 things are given
explicitly to fetch is not the effect of refmap alone, but the
entire 'git fetch' operation itself.

    The default value of the `--refmap` option for linkgit:git-fetch[1].
    Used to map remote refs being fetched to remote-tracking refs to
    store.  See the `--refmap` entry in linkgit:git-fetch[1].

> @@ -244,6 +244,9 @@ endif::git-pull[]
>  	refspecs and rely entirely on the refspecs supplied as
>  	command-line arguments. See section on "Configured Remote-tracking
>  	Branches" for details.
> ++
> +`remote.<name>.refmap` provides the default value for this option, the
> +same way `remote.<name>.fetch` provides the default refspecs to fetch.

This is perfect.

> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 533fdfe7d8..7651b41139 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -509,6 +509,8 @@ static struct ref *get_ref_map(struct remote *remote,
>  	struct ref *rm;
>  	struct ref *ref_map = NULL;
>  	struct ref **tail = &ref_map;
> +	struct refspec *effective_refmap =
> +		refmap.nr ? &refmap : remote ? &remote->refmap : NULL;
>  
>  	/* opportunistically-updated references: */
>  	struct ref *orefs = NULL, **oref_tail = &orefs;
> @@ -552,14 +554,14 @@ static struct ref *get_ref_map(struct remote *remote,
>  		 * by ref_remove_duplicates() in favor of one of these
>  		 * opportunistic entries with FETCH_HEAD_IGNORE.
>  		 */
> -		if (refmap.nr)
> -			fetch_refspec = &refmap;
> +		if (effective_refmap && effective_refmap->nr)
> +			fetch_refspec = effective_refmap;
>  		else
>  			fetch_refspec = &remote->fetch;
>  
>  		for (i = 0; i < fetch_refspec->nr; i++)
>  			get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1);
> -	} else if (refmap.nr) {
> +	} else if (effective_refmap && effective_refmap->nr) {
>  		die("--refmap option is only meaningful with command-line refspec(s)");
>  	} else {
>  		/* Use the defaults */

Looking good.  One of these days, we probably should reduce our
reliance on the file-scope static "global variables" but that is
clearly outside the scope of this topic.  Perhaps once the dust
settles after this topic stabilizes.  I wonder if most of them can
be added as members to "struct fetch_config" and then we can pass
one instance of such struct around in the call chain, or if it
needs a lot more involved changes.

  reply	other threads:[~2026-09-25 22:38 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19 14:47 [PATCH] fetch: add config to avoid fetching every branch in shallow repo Harald Nordgren via GitGitGadget
2026-09-21 13:28 ` Phillip Wood
2026-09-21 21:45   ` Harald Nordgren
2026-09-22 13:00     ` Harald Nordgren
2026-09-22 14:53       ` Phillip Wood
2026-09-22 15:37         ` Harald Nordgren
2026-09-23 15:14           ` Phillip Wood
2026-09-22 17:11   ` Junio C Hamano
2026-09-22 21:40     ` Harald Nordgren
2026-09-23 15:19     ` Phillip Wood
2026-09-23 15:34       ` Junio C Hamano
2026-09-23 16:55         ` D. Ben Knoble
2026-09-23 19:50           ` Junio C Hamano
2026-09-24 17:10             ` D. Ben Knoble
2026-09-24 18:02               ` Junio C Hamano
2026-09-23 20:35 ` [PATCH v2] fetch: avoid fetching every branch of a new remote in a " Harald Nordgren via GitGitGadget
2026-09-23 21:38   ` Junio C Hamano
2026-09-25 10:49 ` [PATCH v3 0/4] " Harald Nordgren via GitGitGadget
2026-09-25 10:49   ` [PATCH v3 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-09-25 22:38     ` Junio C Hamano [this message]
2026-09-25 10:50   ` [PATCH v3 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-09-25 23:26     ` Junio C Hamano
2026-09-25 10:50   ` [PATCH v3 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-09-25 10:50   ` [PATCH v3 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-09-29  9:19 ` [PATCH v4 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Harald Nordgren via GitGitGadget
2026-09-29  9:19   ` [PATCH v4 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-09-29  9:19   ` [PATCH v4 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-09-29  9:27     ` Harald Nordgren
2026-09-29 20:17     ` Junio C Hamano
2026-09-29  9:19   ` [PATCH v4 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-09-29  9:19   ` [PATCH v4 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-09-29 19:36   ` [PATCH v4 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Junio C Hamano
2026-10-02  7:13 ` [PATCH v5 " Harald Nordgren via GitGitGadget
2026-10-02  7:13   ` [PATCH v5 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-10-02  7:13   ` [PATCH v5 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-10-02  7:13   ` [PATCH v5 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-10-02 16:28     ` Junio C Hamano
2026-10-02  7:13   ` [PATCH v5 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-10-04  8:31 ` [PATCH v6 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Harald Nordgren via GitGitGadget
2026-10-04  8:31   ` [PATCH v6 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-10-04  8:31   ` [PATCH v6 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-10-04  8:31   ` [PATCH v6 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-10-04  8:31   ` [PATCH v6 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget
2026-10-04 17:17   ` [PATCH v6 0/4] fetch: avoid fetching every branch of a new remote in a shallow repo Junio C Hamano
2026-10-04 19:51     ` Harald Nordgren
2026-10-05 12:17       ` Junio C Hamano
2026-10-05 18:09         ` Harald Nordgren
2026-10-07 21:56 ` [PATCH v7 " Harald Nordgren via GitGitGadget
2026-10-07 21:56   ` [PATCH v7 1/4] fetch: add remote.<name>.refmap Harald Nordgren via GitGitGadget
2026-10-07 21:56   ` [PATCH v7 2/4] fetch: infer branches to fetch from a refmap-only remote Harald Nordgren via GitGitGadget
2026-10-08 16:59     ` Junio C Hamano
2026-10-09  7:05       ` Harald Nordgren
2026-10-09  8:09       ` Harald Nordgren
2026-10-07 21:56   ` [PATCH v7 3/4] remote: add "git remote add --limited-fetch" Harald Nordgren via GitGitGadget
2026-10-07 21:56   ` [PATCH v7 4/4] remote: default to --limited-fetch in a shallow repository Harald Nordgren via GitGitGadget

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=xmqq5wztt0r4.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=ben.knoble@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=haraldnordgren@gmail.com \
    --cc=phillip.wood123@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.