fetch: refactor fetch refs to be more extendable
Refactor `fetch_refs()` code to make it more extendable by explicitly handling error cases. The refactored code should behave the same. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Sep 1, 2021 at 15:09 UTC
284b2ce8fcb100e7194b9cca6d9b99bca7da39b6
1 file changed
+17
-7
builtin/fetch.c
+17
-7
@@ -1293,18 +1293,28 @@ static int check_exist_and_connected(struct ref *ref_map)
1293
1294
static int fetch_refs(struct transport *transport, struct ref *ref_map)
1295
{
1296
- int ret = check_exist_and_connected(ref_map);
1296
+ int ret;
1297
+
1298
+ /*
1299
+ * We don't need to perform a fetch in case we can already satisfy all
1300
+ * refs.
1301
+ */
1302
+ ret = check_exist_and_connected(ref_map);
1303
if (ret) {
1304
trace2_region_enter("fetch", "fetch_refs", the_repository);
1305
ret = transport_fetch_refs(transport, ref_map);
1306
trace2_region_leave("fetch", "fetch_refs", the_repository);
1307
+ if (ret)
1308
+ goto out;
1309
}
1302
- if (!ret)
1303
- /*
1304
- * Keep the new pack's ".keep" file around to allow the caller
1305
- * time to update refs to reference the new objects.
1306
- */
1307
- return 0;
1310
+
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
}