Skip to content

Commit caff8b7

Browse files
pks-tgitster
authored andcommitted
fetch: avoid second connectivity check if we already have all objects
When fetching refs, we are doing two connectivity checks: - The first one is done such that we can skip fetching refs in the case where we already have all objects referenced by the updated set of refs. - The second one verifies that we have all objects after we have fetched objects. We always execute both connectivity checks, but this is wasteful in case the first connectivity check already notices that we have all objects locally available. Skip the second connectivity check in case we already had all objects available. This gives us a nice speedup when doing a mirror-fetch in a repository with about 2.3M refs where the fetching repo already has all objects: Benchmark #1: HEAD~: git-fetch Time (mean ± σ): 30.025 s ± 0.081 s [User: 27.070 s, System: 4.933 s] Range (min … max): 29.900 s … 30.111 s 5 runs Benchmark #2: HEAD: git-fetch Time (mean ± σ): 25.574 s ± 0.177 s [User: 22.855 s, System: 4.683 s] Range (min … max): 25.399 s … 25.765 s 5 runs Summary 'HEAD: git-fetch' ran 1.17 ± 0.01 times faster than 'HEAD~: git-fetch' Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c7d1ab commit caff8b7

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

builtin/fetch.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ static int check_exist_and_connected(struct ref *ref_map)
12931293

12941294
static int fetch_and_consume_refs(struct transport *transport, struct ref *ref_map)
12951295
{
1296-
int connectivity_checked;
1296+
int connectivity_checked = 1;
12971297
int ret;
12981298

12991299
/*
@@ -1307,11 +1307,10 @@ static int fetch_and_consume_refs(struct transport *transport, struct ref *ref_m
13071307
trace2_region_leave("fetch", "fetch_refs", the_repository);
13081308
if (ret)
13091309
goto out;
1310+
connectivity_checked = transport->smart_options ?
1311+
transport->smart_options->connectivity_checked : 0;
13101312
}
13111313

1312-
connectivity_checked = transport->smart_options
1313-
? transport->smart_options->connectivity_checked : 0;
1314-
13151314
trace2_region_enter("fetch", "consume_refs", the_repository);
13161315
ret = store_updated_refs(transport->url,
13171316
transport->remote->name,

0 commit comments

Comments
 (0)