]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: refactor fetch refs to be more extendable
authorPatrick Steinhardt <ps@pks.im>
Wed, 1 Sep 2021 13:09:58 +0000 (15:09 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Sep 2021 19:43:56 +0000 (12:43 -0700)
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>
builtin/fetch.c

index cdf0d0d671500a417daf05269cc3b99c6f6b28c9..ef6f9b3a33e3242d511f05490dbf69083acb4d31 100644 (file)
@@ -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;
 }