From: Harald Nordgren Date: Sun, 25 Oct 2026 17:27:05 GMT Subject: Re: [PATCH v10 3/5] fetch: infer branches to fetch from a refmap-only remote Message-ID: In-Reply-To: > > Configuring remote..refmap without remote..fetch used to > > make a refspec-less "git fetch " fail with "--refmap option is > > only meaningful with command-line refspec(s)", since a refmap only > > says where to put fetched refs, not what to fetch. > > This makes this commit sound like a fixup of [1/5], but I think it's > actually one of the main goals of the series! Can we flip the > justification around to say something like "we want to allow refmaps > to do XYZ […] Incidentally, we also make sense of the case when refmap > is configured without fetch" ? That would make the purpose clearer to > me, at least. Good idea. > > Make that case infer what to fetch: the local branches whose > > @{upstream} is already on that remote. This lets a remote be > > configured to fetch only the branches actually in use, without > > listing them by hand in remote..fetch, and without needing to > > touch the command line every time. > > > > Signed-off-by: Harald Nordgren > > --- > > Documentation/config/remote.adoc | 5 +- > > Documentation/fetch-options.adoc | 6 +- > > builtin/fetch.c | 75 +++++++++++++++---- > > remote.c | 24 +++++++ > > remote.h | 4 ++ > > t/meson.build | 1 + > > t/t5586-fetch-refmap.sh | 119 +++++++++++++++++++++++++++++++ > > 7 files changed, 219 insertions(+), 15 deletions(-) > > create mode 100755 t/t5586-fetch-refmap.sh > > > > diff --git a/Documentation/config/remote.adoc b/Documentation/config/remote.adoc > > index 103eada406..7c52e443a5 100644 > > --- a/Documentation/config/remote.adoc > > +++ b/Documentation/config/remote.adoc > > @@ -36,7 +36,10 @@ remote..fetch:: > > remote..refmap:: > > 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]. > > + store. If `remote..fetch` is not set either, a refspec-less > > + fetch infers what to fetch from local branches built on this > > + remote, instead of fetching every branch it has. See the > > + `--refmap` entry in linkgit:git-fetch[1]. > > > > remote..push:: > > The default set of "refspec" for linkgit:git-push[1]. See > > diff --git a/Documentation/fetch-options.adoc b/Documentation/fetch-options.adoc > > index c2101a7b39..90b9e13ac2 100644 > > --- a/Documentation/fetch-options.adoc > > +++ b/Documentation/fetch-options.adoc > > @@ -245,8 +245,10 @@ endif::git-pull[] > > command-line arguments. See section on "Configured Remote-tracking > > Branches" for details. > > + > > -`remote..refmap` provides the default value for this option, the > > -same way `remote..fetch` provides the default refspecs to fetch. > > +When a refmap is active (from `--refmap` or `remote..refmap`) but > > +nothing to fetch is specified on the command line, nor is there a > > +`remote..fetch`, branches from the remote that are used as the > > "remote-tracking branches" ?? Yes, the next version will say "remote-tracking branches from this remote that are also configured as the @{upstream} of a local branch are fetched". > > +`@{upstream}` of our local branches are fetched. > > The clause here is complicated ':D I found "infer what to fetch from > local branches built on this remote" to be a bit clearer, but we > definitely still need to get to the point, which is that > remote-tracking branches from this remote that are also configured as > upstreams of local branches are fetched. > > Now, I wonder a bit: the doc says "when a refmap is active" we do that > "fetch remote-tracking branches that are upstream of local branches" > [all scoped to the current remote]---but it doesn't really say how the > refmap affects that? I mean, I imagine it's used for mapping (duh), > but I don't know if it also narrows the scope, or if the scope is > deliberately all remote-tracking branches that meet the requirements, > or…? > > IOW, it seems to beg the question "why does the presence of a refmap > control this if it has no effect on the set of selected branches," and > I think the answer is partly "because we designed it that way" and > possibly found in the mails leading up to this point, but we might > want to try to connect the dots for folks? Idk. I'll take a look at improving this part. > > > > `-t`:: > > `--tags`:: > > diff --git a/builtin/fetch.c b/builtin/fetch.c > > index 136a59154a..0fc1fb66d5 100644 > > --- a/builtin/fetch.c > > +++ b/builtin/fetch.c > > @@ -524,6 +524,8 @@ static struct ref *get_ref_map(struct remote *remote, > > */ > > struct refspec *effective_refmap = > > refmap.nr ? &refmap : remote ? &remote->refmap : NULL; > > + struct refspec inferred_rs; > > + int infer_from_refmap = 0; > > > > /* opportunistically-updated references: */ > > struct ref *orefs = NULL, **oref_tail = &orefs; > > @@ -531,15 +533,32 @@ static struct ref *get_ref_map(struct remote *remote, > > struct hashmap existing_refs; > > int existing_refs_populated = 0; > > > > + refspec_init_fetch(&inferred_rs, the_hash_algo); > > + > > filter_prefetch_refspec(rs); > > if (remote) > > filter_prefetch_refspec(&remote->fetch); > > > > + if (!rs->nr && remote && !remote->fetch.nr && > > + effective_refmap && effective_refmap->nr) { > > + struct string_list tracked = STRING_LIST_INIT_DUP; > > + struct string_list_item *item; > > + > > + branches_tracking_remote(the_repository, remote, &tracked); > > + for_each_string_list_item(item, &tracked) > > + refspec_append(&inferred_rs, item->string); > > + string_list_clear(&tracked, 0); > > Interesting choice of string_list again ;) do we need the sorting > behavior? (In fact, since it could come from an "ordered" config, > perhaps we should use that order?) A strvec seems more appropriate > then… Agreed, the next version uses a strvec here too. Nothing is sorted anymore: the branches come in refname order, and each branch's merge entries in config order. > > + > > + rs = &inferred_rs; > > + infer_from_refmap = 1; > > + } > > + > > if (rs->nr) { > > struct refspec *fetch_refspec; > > > > for (i = 0; i < rs->nr; i++) { > > - get_fetch_map(remote_refs, &rs->items[i], &tail, 0); > > + get_fetch_map(remote_refs, &rs->items[i], &tail, > > + infer_from_refmap); > > if (rs->items[i].dst && rs->items[i].dst[0]) > > *autotags = 1; > > } > > @@ -574,6 +593,8 @@ static struct ref *get_ref_map(struct remote *remote, > > > > for (i = 0; i < fetch_refspec->nr; i++) > > get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1); > > + } else if (infer_from_refmap) { > > + /* Already fully handled above. */ > > } else if (refmap.nr) { > > die("--refmap option is only meaningful with command-line refspec(s)"); > > } else { > > @@ -669,6 +690,7 @@ static struct ref *get_ref_map(struct remote *remote, > > if (existing_refs_populated) > > hashmap_clear_and_free(&existing_refs, struct refname_hash_entry, ent); > > > > + refspec_clear(&inferred_rs); > > return ref_map; > > } > > > > @@ -1978,13 +2000,47 @@ static int do_fetch(struct transport *transport, > > > > if (rs->nr) { > > refspec_ref_prefixes(rs, &transport_ls_refs_options.ref_prefixes); > > + } else if (transport->remote->fetch.nr) { > > + struct string_list tracked = STRING_LIST_INIT_DUP; > > + struct string_list_item *item; > > + > > + refspec_ref_prefixes(&transport->remote->fetch, > > + &transport_ls_refs_options.ref_prefixes); > > + /* > > + * See remote.c's handling of remote..followRemoteHEAD > > + * for the analogous, still-unresolved case. > > Is this a "we haven't resolved what to do" case, or a "some remote (or > something) hasn't resolved" case? I'm not sure what I should be > looking at here. > > Oh, I see. It's a duplicate of comment and code from the > else{effective_refmap->nr} block below. Hrm… probably it would be nice > not to duplicate that? I can't spot any differences between the code > blocks. Yes, good idea! Harald