Skip to content

Commit 05c4422

Browse files
bmwillgitster
authored andcommitted
fetch: refactor fetch_refs into two functions
Refactor the fetch_refs function into a function that does the fetching of refs and another function that stores them. This is in preparation for allowing additional processing of the fetched refs before updating the local ref store. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14b8ced commit 05c4422

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

builtin/fetch.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -968,9 +968,21 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
968968
if (ret)
969969
ret = transport_fetch_refs(transport, ref_map);
970970
if (!ret)
971-
ret |= store_updated_refs(transport->url,
972-
transport->remote->name,
973-
ref_map);
971+
/*
972+
* Keep the new pack's ".keep" file around to allow the caller
973+
* time to update refs to reference the new objects.
974+
*/
975+
return 0;
976+
transport_unlock_pack(transport);
977+
return ret;
978+
}
979+
980+
/* Update local refs based on the ref values fetched from a remote */
981+
static int consume_refs(struct transport *transport, struct ref *ref_map)
982+
{
983+
int ret = store_updated_refs(transport->url,
984+
transport->remote->name,
985+
ref_map);
974986
transport_unlock_pack(transport);
975987
return ret;
976988
}
@@ -1116,7 +1128,8 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
11161128
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
11171129
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
11181130
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
1119-
fetch_refs(transport, ref_map);
1131+
if (!fetch_refs(transport, ref_map))
1132+
consume_refs(transport, ref_map);
11201133

11211134
if (gsecondary) {
11221135
transport_disconnect(gsecondary);
@@ -1165,7 +1178,7 @@ static int do_fetch(struct transport *transport,
11651178
transport->url);
11661179
}
11671180
}
1168-
if (fetch_refs(transport, ref_map)) {
1181+
if (fetch_refs(transport, ref_map) || consume_refs(transport, ref_map)) {
11691182
free_refs(ref_map);
11701183
retcode = 1;
11711184
goto cleanup;

0 commit comments

Comments
 (0)