git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fetch: add --no-update-remote-refs

From
Jeff King <peff@peff.net>
Date
Jan 17, 2020, 19:20 UTC
Message-ID
<20200117192016.GB11358@coredump.intra.peff.net>
In-Reply-To
<pull.532.git.1579274939431.gitgitgadget@gmail.com>
On Fri, Jan 17, 2020 at 03:28:59PM +0000, Derrick Stolee via GitGitGadget wrote:
Show 27 quoted lines
> To prevent long blocking time during a 'git fetch' call, a user
> may want to set up a schedule for background 'git fetch' processes.
> However, these runs will update the refs/remotes branches, and
> hence the user will not notice when remote refs are updated during
> their foreground fetches. In fact, they may _want_ those refs to
> stay put so they can work with the refs from their last foreground
> fetch call.
> 
> Add a --[no-]update-remote-refs option to 'git fetch' which defaults
> to the existing behavior of updating the remote refs. This allows
> a user to run
> 
>   git fetch <remote> --no-update-remote-refs +refs/heads/*:refs/hidden/*
> 
> to populate a custom ref space and download a pack of the new
> reachable objects. This kind of call allows a few things to happen:
> 
> 1. We download a new pack if refs have updated.
> 2. Since the refs/hidden branches exist, GC will not remove the
>    newly-downloaded data.
> 3. With fetch.writeCommitGraph enabled, the refs/hidden refs are
>    used to update the commit-graph file.
> 
> To avoid the refs/hidden directory from filling without bound, the
> --prune option can be included. When providing a refspec like this,
> the --prune option does not delete remote refs and instead only
> deletes refs in the target refspace.

So refs/hidden is basically a parallel namespace that is exactly identical to refs/remotes/origin? It seems like a very roundabout way of solving the problem. Which, AFAICT, is just that you want "git fetch" to print out the set of updates since the last manual fetch. I suppose this also doesn't update what people see when they refer to "origin/master" until they run such a fetch.

I don't know. Part of me wants to say this is overly complicated. If you want to see the difference in refs between two states, then we should have some tool for showing that (even if it's git-fetch) without having to have this weird parallel ref structure. OTOH, I guess any such tool would need to save the ref state, which is equivalent to having all these parallel refs.

Show 6 quoted lines
> +--no-update-remote-refs::
> +	By default, git updates the `refs/remotes/` refspace with the refs
> +	advertised by the remotes during a `git fetch` command. With this
> +	option, those refs will be ignored. If the `--prune` option is
> +	specified and the default refpsec is used, then a ref that does not
> +	appear in the remote will still be deleted from refs/remotes.

That "by default" isn't exactly how it works. It's not updating the advertised refs, but rather applying the configured refspec opportunistically when we are actually fetching one of those refs. The idea being that the remote tracking refs should always reflect our latest notion of what's on the remote. This is due to f269048754 (fetch: opportunistically update tracking refs, 2013-05-11).

So I think a cleaner implementation would be to prevent that ref mapping from kicking in in the first place, rather than hacking it into update_local_ref() as you have here. And it would avoid making assumptions that "refs/remotes" is the only thing we'd see in such a configured refspec. E.g., I have a configured refspec for gitster.git with refs/notes/amlog:refs/notes/amlog, and that _would_ still update even with your new option.

But I think there's already a way to do that: the --refmap option added by c5558f80c3 (fetch: allow explicit --refmap to override configuration, 2014-05-29). Using an empty refmap like:

  git fetch --refmap= <remote> refs/heads/*:refs/hidden/*

should do what you want. It suppresses the use of the configured refspecs, so we don't find any opportunistic mappings to make.

-Peff
Previous: Derrick StoleeNext: Derrick Stolee
Message 6 of 13 in “fetch: add --no-update-remote-refs”
  1. fetch: add --no-update-remote-refsDerrick Stolee via GitGitGadget, Jan 17, 2020
  2. Eric SunshineJan 17, 2020
  3. Junio C HamanoJan 17, 2020
  4. Jeff KingJan 17, 2020
  5. Derrick StoleeJan 20, 2020
  6. Jeff KingJan 17, 2020
  7. Derrick StoleeJan 21, 2020
  8. fetch: document and test --refmap=""Derrick Stolee via GitGitGadget, Jan 21, 2020
  9. Jeff KingJan 21, 2020
  10. Derrick StoleeJan 21, 2020
  11. Jeff KingJan 21, 2020
  12. Junio C HamanoJan 21, 2020
  13. Junio C HamanoJan 21, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.