diff mbox series

[v3,5/7] fetch: refactor fetch refs to be more extendable

Message ID d64888e072c3be2d25372b9743cf1bd3baefc9f4.1630501732.git.ps@pks.im (mailing list archive)
State Accepted
Commit 284b2ce8fcb100e7194b9cca6d9b99bca7da39b6
Headers show
Series Speed up mirror-fetches with many refs | expand

Commit Message

Patrick Steinhardt Sept. 1, 2021, 1:09 p.m. UTC
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>
---
 builtin/fetch.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/builtin/fetch.c b/builtin/fetch.c
index f67fe543ad..bafeb3d44b 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -1293,18 +1293,28 @@  static int check_exist_and_connected(struct ref *ref_map)
 
 static int fetch_refs(struct transport *transport, struct ref *ref_map)
 {
-	int ret = check_exist_and_connected(ref_map);
+	int ret;
+
+	/*
+	 * We don't need to perform a fetch in case we can already satisfy all
+	 * refs.
+	 */
+	ret = check_exist_and_connected(ref_map);
 	if (ret) {
 		trace2_region_enter("fetch", "fetch_refs", the_repository);
 		ret = transport_fetch_refs(transport, ref_map);
 		trace2_region_leave("fetch", "fetch_refs", the_repository);
+		if (ret)
+			goto out;
 	}
-	if (!ret)
-		/*
-		 * Keep the new pack's ".keep" file around to allow the caller
-		 * time to update refs to reference the new objects.
-		 */
-		return 0;
+
+	/*
+	 * Keep the new pack's ".keep" file around to allow the caller
+	 * time to update refs to reference the new objects.
+	 */
+	return ret;
+
+out:
 	transport_unlock_pack(transport);
 	return ret;
 }