Re: [RFC/PATCH] Add fetch.updateHead option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

True.

> 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
case.

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
refs/remotes/origin/master).

> 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).

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux