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 <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Jun 27, 2018 at 15:30 UTC 05c4422676f6e854aff0277984f4eadcd8912d56
1 file changed +18 -5
builtin/fetch.c
+18 -5
@@ -968,9 +968,21 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
968 if (ret)
969 ret = transport_fetch_refs(transport, ref_map);
970 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);
986 transport_unlock_pack(transport);
987 return ret;
988 }
@@ -1116,7 +1128,8 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
1128 transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
1129 transport_set_option(transport, TRANS_OPT_DEPTH, "0");
1130 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);
1133
1134 if (gsecondary) {
1135 transport_disconnect(gsecondary);
@@ -1165,7 +1178,7 @@ static int do_fetch(struct transport *transport,
1178 transport->url);
1179 }
1180 }
1168 - if (fetch_refs(transport, ref_map)) {
1181 + if (fetch_refs(transport, ref_map) || consume_refs(transport, ref_map)) {
1182 free_refs(ref_map);
1183 retcode = 1;
1184 goto cleanup;