Skip to content

Commit c6ce27a

Browse files
Eric Wonggitster
authored andcommitted
fetch: support hideRefs to speed up connectivity checks
With roughly 800 remotes all fetching into their own refs/remotes/$REMOTE/* island, the connectivity check[1] gets expensive for each fetch on systems which lack sufficient RAM to cache objects. To do a no-op fetch on one $REMOTE out of hundreds, hideRefs now allows the no-op fetch to take ~30 seconds instead of ~20 minutes on a noisy, RAM-constrained machine (localhost, so no network latency): git -c fetch.hideRefs=refs \ -c fetch.hideRefs='!refs/remotes/$REMOTE/' \ fetch $REMOTE [1] `git rev-list --objects --stdin --not --all --quiet --alternate-refs' Signed-off-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dadc8e6 commit c6ce27a

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

Documentation/git-rev-parse.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ respectively, and they must begin with `refs/` when applied to `--glob`
197197
or `--all`. If a trailing '/{asterisk}' is intended, it must be given
198198
explicitly.
199199

200-
--exclude-hidden=[receive|uploadpack]::
201-
Do not include refs that would be hidden by `git-receive-pack` or
202-
`git-upload-pack` by consulting the appropriate `receive.hideRefs` or
203-
`uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see
200+
--exclude-hidden=[fetch|receive|uploadpack]::
201+
Do not include refs that would be hidden by `git-fetch`,
202+
`git-receive-pack` or `git-upload-pack` by consulting the appropriate
203+
`fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs`
204+
configuration along with `transfer.hideRefs` (see
204205
linkgit:git-config[1]). This option affects the next pseudo-ref option
205206
`--all` or `--glob` and is cleared after processing them.
206207

Documentation/rev-list-options.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,11 @@ respectively, and they must begin with `refs/` when applied to `--glob`
195195
or `--all`. If a trailing '/{asterisk}' is intended, it must be given
196196
explicitly.
197197

198-
--exclude-hidden=[receive|uploadpack]::
199-
Do not include refs that would be hidden by `git-receive-pack` or
200-
`git-upload-pack` by consulting the appropriate `receive.hideRefs` or
201-
`uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see
198+
--exclude-hidden=[fetch|receive|uploadpack]::
199+
Do not include refs that would be hidden by `git-fetch`,
200+
`git-receive-pack` or `git-upload-pack` by consulting the appropriate
201+
`fetch.hideRefs`, `receive.hideRefs` or `uploadpack.hideRefs`
202+
configuration along with `transfer.hideRefs` (see
202203
linkgit:git-config[1]). This option affects the next pseudo-ref option
203204
`--all` or `--glob` and is cleared after processing them.
204205

builtin/fetch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
11321132
if (!connectivity_checked) {
11331133
struct check_connected_options opt = CHECK_CONNECTED_INIT;
11341134

1135+
opt.exclude_hidden_refs_section = "fetch";
11351136
rm = ref_map;
11361137
if (check_connected(iterate_ref_map, &rm, &opt)) {
11371138
rc = error(_("%s did not send all necessary objects\n"), url);
@@ -1325,6 +1326,7 @@ static int check_exist_and_connected(struct ref *ref_map)
13251326
}
13261327

13271328
opt.quiet = 1;
1329+
opt.exclude_hidden_refs_section = "fetch";
13281330
return check_connected(iterate_ref_map, &rm, &opt);
13291331
}
13301332

builtin/rev-list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static const char rev_list_usage[] =
3838
" --tags\n"
3939
" --remotes\n"
4040
" --stdin\n"
41-
" --exclude-hidden=[receive|uploadpack]\n"
41+
" --exclude-hidden=[fetch|receive|uploadpack]\n"
4242
" --quiet\n"
4343
" ordering output:\n"
4444
" --topo-order\n"

revision.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,8 @@ void exclude_hidden_refs(struct ref_exclusions *exclusions, const char *section)
15741574
{
15751575
struct exclude_hidden_refs_cb cb;
15761576

1577-
if (strcmp(section, "receive") && strcmp(section, "uploadpack"))
1577+
if (strcmp(section, "fetch") && strcmp(section, "receive") &&
1578+
strcmp(section, "uploadpack"))
15781579
die(_("unsupported section for hidden refs: %s"), section);
15791580

15801581
if (exclusions->hidden_refs_configured)

t/t5510-fetch.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,15 @@ test_expect_success '--no-show-forced-updates' '
11711171
)
11721172
'
11731173

1174+
for section in fetch transfer
1175+
do
1176+
test_expect_success "$section.hideRefs affects connectivity check" '
1177+
GIT_TRACE="$PWD"/trace git -c $section.hideRefs=refs -c \
1178+
$section.hideRefs="!refs/tags/" fetch &&
1179+
grep "git rev-list .*--exclude-hidden=fetch" trace
1180+
'
1181+
done
1182+
11741183
setup_negotiation_tip () {
11751184
SERVER="$1"
11761185
URL="$2"

t/t6018-rev-list-glob.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
187187
compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
188188
'
189189

190-
for section in receive uploadpack
190+
for section in fetch receive uploadpack
191191
do
192192
test_expect_success "rev-parse --exclude-hidden=$section with --all" '
193193
compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags" "--exclude-hidden=$section --all"

t/t6021-rev-list-exclude-hidden.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test_expect_success 'invalid section' '
2222
test_cmp expected err
2323
'
2424

25-
for section in receive uploadpack
25+
for section in fetch receive uploadpack
2626
do
2727
test_expect_success "$section: passed multiple times" '
2828
echo "fatal: --exclude-hidden= passed more than once" >expected &&

0 commit comments

Comments
 (0)