list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <>
To: Felipe Contreras <>
Cc: Git <>, Junio C Hamano <>,
	Jonathan Nieder <>,
	Dominik Salvet <>
Subject: Re: [RFC/PATCH] Add fetch.updateHead option
Date: Tue, 24 Nov 2020 02:09:38 -0500	[thread overview]
Message-ID: <X7yxsl9/> (raw)
In-Reply-To: <>

On Fri, Nov 20, 2020 at 07:41:48PM -0600, Felipe Contreras wrote:

> > > +static void update_head(int config, const struct ref *head, const struct remote *remote)
> > > +{
> > > +     struct strbuf ref = STRBUF_INIT, target = STRBUF_INIT;
> > > +     const char *r, *head_name = NULL;
> > > +
> > > +     if (!head || !head->symref || !remote)
> > > +             return;
> >
> > I'd expect us to return early here, as well, if the config is set to
> > "never". I think your function will usually still do the right thing
> > (because we return early before writing), but it makes a pointless
> > lookup of the current origin/HEAD. But see below.
> If the config is set to "never", the function update_head is never
> called, since the boolean need_update_head is never set in the outer
> function.


> I don't like the convolutedness of this approach, but couldn't think
> of anything better.

In general, I think keeping as much logic as possible in update_head()
makes sense, rather than the caller. We don't need to avoid running
update_head() when the config is "never" if it is a true noop in that

Unfortunately, we do still need to make a decision on whether to send a
request for "HEAD" to the other side in some cases, so some logic has to
be there.

But if we don't send such a request, but we _do_ find out about HEAD
somehow (e.g., because the user said "git fetch origin HEAD", which
seems like an obvious thing for someone to try in this case), we
probably should trigger the function.

> > since otherwise it doesn't ask about HEAD in a v2 exchange. What about:
> >
> >   git fetch origin master
> >
> > That won't report on HEAD either, even with your patch, because it hits
> > the part of the conditional before your "else if". What should it do?  I
> > can see an argument for "nothing, we only update head on full configured
> > fetches", but if so we should definitely make that clear in the
> > documentation. I can also see an argument for "always, if we happen to
> > have heard about it" (just like we opportunistically update tracking
> > refs even if they are fetched by name into FETCH_HEAD).
> I don't see the point in complicating the code for those corner-cases.

I would think:

  git pull origin master

isn't that much of a corner case, and people would expect a HEAD update
to trigger (especially if that HEAD is master). That will run "git fetch
origin master" under the hood (and update both FETCH_HEAD and

> And I also don't see how HEAD can be fetched unless we specifically
> ask for it. What would that command look like?

I think it would be nice if any of:

  - git fetch

  - git fetch origin

  - git fetch origin master

  - git fetch origin HEAD

triggered the auto-update, along with their git-pull equivalents. In the
first three, v2 protocol will require mentioning HEAD as a ref-prefix.

> Also, there's two optimizations that apparently went unnoticed:
> 1. In the case of "missing". We could preemptively check if there's
> already an "origin/HEAD" before adding "HEAD" to the prefixes (and
> setting need_update_head). That would probably complicate the code.

Hmm. That might be worth doing, as it does involve extra network traffic
(and the server-side lookup is more complicated, as it looks up all
possible variants of HEAD). But it is only a few bytes. I guess it would
involve saving the value of origin/HEAD between the two calls, but that
doesn't seem all that hard.

But I'd also be OK with just unconditionally asking for HEAD (but as
above, I think it should happen even with a refspec, and anytime we hear
about HEAD we should consider updating the symref).


      reply	other threads:[~2020-11-24  7:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18  9:12 Felipe Contreras
2020-11-18  9:30 ` Ævar Arnfjörð Bjarmason
2020-11-18  9:43   ` Felipe Contreras
2020-11-18 15:53   ` Junio C Hamano
2020-11-18 19:04     ` Felipe Contreras
2020-11-20 23:52 ` Jeff King
2020-11-21  0:28   ` Junio C Hamano
2020-11-21  0:40     ` Jeff King
2020-11-21  1:18       ` Felipe Contreras
2020-11-24  6:58         ` Jeff King
2020-11-21  1:53     ` Felipe Contreras
2020-11-21  1:41   ` Felipe Contreras
2020-11-24  7:09     ` Jeff King [this message]

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:

  List information:

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

  git send-email \
    --in-reply-to=X7yxsl9/ \ \ \ \ \ \ \
    --subject='Re: [RFC/PATCH] Add fetch.updateHead option' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

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 read-only IMAP folder(s) and NNTP newsgroup(s).