Skip to content

Commit cfd781e

Browse files
derrickstoleegitster
authored andcommitted
maintenance: use 'git fetch --prefetch'
The 'prefetch' maintenance task previously forced the following refspec for each remote: +refs/heads/*:refs/prefetch/<remote>/* If a user has specified a more strict refspec for the remote, then this prefetch task downloads more objects than necessary. The previous change introduced the '--prefetch' option to 'git fetch' which manipulates the remote's refspec to place all resulting refs into refs/prefetch/, with further partitioning based on the destinations of those refspecs. Update the documentation to be more generic about the destination refs. Do not mention custom refspecs explicitly, as that does not need to be highlighted in this documentation. The important part of placing refs in refs/prefetch/ remains. Reported-by: Tom Saeger <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e03115 commit cfd781e

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

Documentation/git-maintenance.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,8 @@ commit-graph::
9292
prefetch::
9393
The `prefetch` task updates the object directory with the latest
9494
objects from all registered remotes. For each remote, a `git fetch`
95-
command is run. The refmap is custom to avoid updating local or remote
96-
branches (those in `refs/heads` or `refs/remotes`). Instead, the
97-
remote refs are stored in `refs/prefetch/<remote>/`. Also, tags are
98-
not updated.
95+
command is run. The configured refspec is modified to place all
96+
requested refs within `refs/prefetch/`. Also, tags are not updated.
9997
+
10098
This is done to avoid disrupting the remote-tracking branches. The end users
10199
expect these refs to stay unmoved unless they initiate a fetch. With prefetch

builtin/gc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,14 @@ static int fetch_remote(struct remote *remote, void *cbdata)
879879
struct child_process child = CHILD_PROCESS_INIT;
880880

881881
child.git_cmd = 1;
882-
strvec_pushl(&child.args, "fetch", remote->name, "--prune", "--no-tags",
882+
strvec_pushl(&child.args, "fetch", remote->name,
883+
"--prefetch", "--prune", "--no-tags",
883884
"--no-write-fetch-head", "--recurse-submodules=no",
884-
"--refmap=", NULL);
885+
NULL);
885886

886887
if (opts->quiet)
887888
strvec_push(&child.args, "--quiet");
888889

889-
strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote->name);
890-
891890
return !!run_command(&child);
892891
}
893892

t/t7900-maintenance.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ test_expect_success 'prefetch multiple remotes' '
141141
test_commit -C clone1 one &&
142142
test_commit -C clone2 two &&
143143
GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null &&
144-
fetchargs="--prune --no-tags --no-write-fetch-head --recurse-submodules=no --refmap= --quiet" &&
145-
test_subcommand git fetch remote1 $fetchargs +refs/heads/\\*:refs/prefetch/remote1/\\* <run-prefetch.txt &&
146-
test_subcommand git fetch remote2 $fetchargs +refs/heads/\\*:refs/prefetch/remote2/\\* <run-prefetch.txt &&
144+
fetchargs="--prefetch --prune --no-tags --no-write-fetch-head --recurse-submodules=no --quiet" &&
145+
test_subcommand git fetch remote1 $fetchargs <run-prefetch.txt &&
146+
test_subcommand git fetch remote2 $fetchargs <run-prefetch.txt &&
147147
test_path_is_missing .git/refs/remotes &&
148-
git log prefetch/remote1/one &&
149-
git log prefetch/remote2/two &&
148+
git log prefetch/remotes/remote1/one &&
149+
git log prefetch/remotes/remote2/two &&
150150
git fetch --all &&
151-
test_cmp_rev refs/remotes/remote1/one refs/prefetch/remote1/one &&
152-
test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two &&
151+
test_cmp_rev refs/remotes/remote1/one refs/prefetch/remotes/remote1/one &&
152+
test_cmp_rev refs/remotes/remote2/two refs/prefetch/remotes/remote2/two &&
153153
154154
test_cmp_config refs/prefetch/ log.excludedecoration &&
155155
git log --oneline --decorate --all >log &&

0 commit comments

Comments
 (0)