Skip to content

Commit e0c9861

Browse files
Merge pull request #228: "gvfs-helper prefetch" during "git fetch"
This is a follow-up to #227. 1. When a new flag is added to our Git config, we can run `gvfs-helper prefetch` inside of our `git fetch` calls. This will help ensure we have updated commits and trees even if the background prefetches have fallen behind (or are not running). 2. With a new `--no-update-remote-refs` we can avoid updating the `refs/remotes` namespace. This will allow us to run `git fetch --all --no-update-remote-refs +refs/heads/*:refs/hidden/*` and we will get the new refs into a local folder (that doesn't appear anywhere). The most important thing is that users will still see when their remote refs update.
2 parents a2c9b01 + 7f8481b commit e0c9861

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

Documentation/config/core.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ core.gvfs::
659659
is first accessed and brought down to the client. Git.exe can't
660660
currently tell the first access vs subsequent accesses so this
661661
flag just blocks them from occurring at all.
662+
GVFS_PREFETCH_DURING_FETCH::
663+
Bit value 128
664+
While performing a `git fetch` command, use the gvfs-helper to
665+
perform a "prefetch" of commits and trees.
662666
--
663667

664668
core.useGvfsHelper::

Documentation/fetch-options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ endif::git-pull[]
250250
'git-pull' the --ff-only option will still check for forced updates
251251
before attempting a fast-forward update. See linkgit:git-config[1].
252252

253+
--no-update-remote-refs::
254+
By default, git updates the `refs/remotes/` refspace with the refs
255+
advertised by the remotes during a `git fetch` command. With this
256+
option, those refs will be ignored.
257+
253258
-4::
254259
--ipv4::
255260
Use IPv4 addresses only, ignoring IPv6 addresses.

builtin/fetch.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "branch.h"
2828
#include "promisor-remote.h"
2929
#include "commit-graph.h"
30+
#include "gvfs.h"
31+
#include "gvfs-helper-client.h"
3032

3133
#define FORCED_UPDATES_DELAY_WARNING_IN_MS (10 * 1000)
3234

@@ -77,6 +79,7 @@ static struct refspec refmap = REFSPEC_INIT_FETCH;
7779
static struct list_objects_filter_options filter_options;
7880
static struct string_list server_options = STRING_LIST_INIT_DUP;
7981
static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP;
82+
static int update_remote_refs = 1;
8083

8184
static int git_fetch_config(const char *k, const char *v, void *cb)
8285
{
@@ -198,6 +201,8 @@ static struct option builtin_fetch_options[] = {
198201
N_("run 'gc --auto' after fetching")),
199202
OPT_BOOL(0, "show-forced-updates", &fetch_show_forced_updates,
200203
N_("check for forced-updates on all updated branches")),
204+
OPT_BOOL(0, "update-remote-refs", &update_remote_refs,
205+
N_("update the refs/remotes/ refspace")),
201206
OPT_END()
202207
};
203208

@@ -743,6 +748,9 @@ static int update_local_ref(struct ref *ref,
743748
const char *pretty_ref = prettify_refname(ref->name);
744749
int fast_forward = 0;
745750

751+
if (!update_remote_refs && starts_with(ref->name, "refs/remotes/"))
752+
return 0;
753+
746754
type = oid_object_info(the_repository, &ref->new_oid, NULL);
747755
if (type < 0)
748756
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
@@ -1824,6 +1832,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
18241832

18251833
fetch_if_missing = 0;
18261834

1835+
if (core_gvfs & GVFS_PREFETCH_DURING_FETCH)
1836+
gh_client__prefetch(0, NULL);
1837+
18271838
if (remote) {
18281839
if (filter_options.choice || has_promisor_remote())
18291840
fetch_one_setup_partial(remote);

gvfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT (1 << 3)
1818
#define GVFS_FETCH_SKIP_REACHABILITY_AND_UPLOADPACK (1 << 4)
1919
#define GVFS_BLOCK_FILTERS_AND_EOL_CONVERSIONS (1 << 6)
20+
#define GVFS_PREFETCH_DURING_FETCH (1 << 7)
2021

2122
void gvfs_load_config_value(const char *value);
2223
int gvfs_config_is_set(int mask);

0 commit comments

Comments
 (0)