]> git.ipfire.org Git - thirdparty/git.git/commitdiff
transport: extract common fetch_pack() call
authorDenton Liu <liu.denton@gmail.com>
Tue, 19 May 2020 10:53:56 +0000 (06:53 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2020 22:40:26 +0000 (15:40 -0700)
In the switch statement, the difference between the `protocol_v2` and
`protocol_v{1,0}` arms is a preparatory call to die_if_server_options() in
the latter. The fetch_pack() call is identical in both arms. However,
since this fetch_pack() call has so many parameters, it is not
immediately obvious that the call is identical in both cases.

Extract the common fetch_pack() call out of the switch statement so that
code duplication is reduced and the logic is more clear for future
readers. While we're at it, rewrite the switch statement as an if-else
tower for increased clarity.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
transport.c

index 15f5ba4e8f22c69959357bc8a7fe073678fe8862..431a93caef710f754307dbf2d69a1d8c3a9e0ae4 100644 (file)
@@ -369,24 +369,15 @@ static int fetch_refs_via_pack(struct transport *transport,
                refs_tmp = handshake(transport, 0, NULL, must_list_refs);
        }
 
-       switch (data->version) {
-       case protocol_v2:
-               refs = fetch_pack(&args, data->fd,
-                                 refs_tmp ? refs_tmp : transport->remote_refs,
-                                 to_fetch, nr_heads, &data->shallow,
-                                 &transport->pack_lockfile, data->version);
-               break;
-       case protocol_v1:
-       case protocol_v0:
-               die_if_server_options(transport);
-               refs = fetch_pack(&args, data->fd,
-                                 refs_tmp ? refs_tmp : transport->remote_refs,
-                                 to_fetch, nr_heads, &data->shallow,
-                                 &transport->pack_lockfile, data->version);
-               break;
-       case protocol_unknown_version:
+       if (data->version == protocol_unknown_version)
                BUG("unknown protocol version");
-       }
+       else if (data->version <= protocol_v1)
+               die_if_server_options(transport);
+
+       refs = fetch_pack(&args, data->fd,
+                         refs_tmp ? refs_tmp : transport->remote_refs,
+                         to_fetch, nr_heads, &data->shallow,
+                         &transport->pack_lockfile, data->version);
 
        close(data->fd[0]);
        close(data->fd[1]);