Skip to content

Commit 1c7d1ab

Browse files
pks-tgitster
authored andcommitted
fetch: merge fetching and consuming refs
The functions `fetch_refs()` and `consume_refs()` must always be called together such that we first obtain all missing objects and then update our local refs to match the remote refs. In a subsequent patch, we'll further require that `fetch_refs()` must always be called before `consume_refs()` such that it can correctly assert that we have all objects after the fetch given that we're about to move the connectivity check. Make this requirement explicit by merging both functions into a single `fetch_and_consume_refs()` function. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 284b2ce commit 1c7d1ab

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

builtin/fetch.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,8 +1291,9 @@ static int check_exist_and_connected(struct ref *ref_map)
12911291
return check_connected(iterate_ref_map, &rm, &opt);
12921292
}
12931293

1294-
static int fetch_refs(struct transport *transport, struct ref *ref_map)
1294+
static int fetch_and_consume_refs(struct transport *transport, struct ref *ref_map)
12951295
{
1296+
int connectivity_checked;
12961297
int ret;
12971298

12981299
/*
@@ -1308,30 +1309,18 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
13081309
goto out;
13091310
}
13101311

1311-
/*
1312-
* Keep the new pack's ".keep" file around to allow the caller
1313-
* time to update refs to reference the new objects.
1314-
*/
1315-
return ret;
1316-
1317-
out:
1318-
transport_unlock_pack(transport);
1319-
return ret;
1320-
}
1321-
1322-
/* Update local refs based on the ref values fetched from a remote */
1323-
static int consume_refs(struct transport *transport, struct ref *ref_map)
1324-
{
1325-
int connectivity_checked = transport->smart_options
1312+
connectivity_checked = transport->smart_options
13261313
? transport->smart_options->connectivity_checked : 0;
1327-
int ret;
1314+
13281315
trace2_region_enter("fetch", "consume_refs", the_repository);
13291316
ret = store_updated_refs(transport->url,
13301317
transport->remote->name,
13311318
connectivity_checked,
13321319
ref_map);
1333-
transport_unlock_pack(transport);
13341320
trace2_region_leave("fetch", "consume_refs", the_repository);
1321+
1322+
out:
1323+
transport_unlock_pack(transport);
13351324
return ret;
13361325
}
13371326

@@ -1520,8 +1509,7 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
15201509
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
15211510
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
15221511
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
1523-
if (!fetch_refs(transport, ref_map))
1524-
consume_refs(transport, ref_map);
1512+
fetch_and_consume_refs(transport, ref_map);
15251513

15261514
if (gsecondary) {
15271515
transport_disconnect(gsecondary);
@@ -1612,7 +1600,7 @@ static int do_fetch(struct transport *transport,
16121600
transport->url);
16131601
}
16141602
}
1615-
if (fetch_refs(transport, ref_map) || consume_refs(transport, ref_map)) {
1603+
if (fetch_and_consume_refs(transport, ref_map)) {
16161604
free_refs(ref_map);
16171605
retcode = 1;
16181606
goto cleanup;

0 commit comments

Comments
 (0)