Skip to content

Commit dde72f9

Browse files
Denton-Lgitster
authored andcommitted
transport: extract common fetch_pack() call
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 04cc91a commit dde72f9

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

transport.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,24 +369,15 @@ static int fetch_refs_via_pack(struct transport *transport,
369369
refs_tmp = handshake(transport, 0, NULL, must_list_refs);
370370
}
371371

372-
switch (data->version) {
373-
case protocol_v2:
374-
refs = fetch_pack(&args, data->fd,
375-
refs_tmp ? refs_tmp : transport->remote_refs,
376-
to_fetch, nr_heads, &data->shallow,
377-
&transport->pack_lockfile, data->version);
378-
break;
379-
case protocol_v1:
380-
case protocol_v0:
381-
die_if_server_options(transport);
382-
refs = fetch_pack(&args, data->fd,
383-
refs_tmp ? refs_tmp : transport->remote_refs,
384-
to_fetch, nr_heads, &data->shallow,
385-
&transport->pack_lockfile, data->version);
386-
break;
387-
case protocol_unknown_version:
372+
if (data->version == protocol_unknown_version)
388373
BUG("unknown protocol version");
389-
}
374+
else if (data->version <= protocol_v1)
375+
die_if_server_options(transport);
376+
377+
refs = fetch_pack(&args, data->fd,
378+
refs_tmp ? refs_tmp : transport->remote_refs,
379+
to_fetch, nr_heads, &data->shallow,
380+
&transport->pack_lockfile, data->version);
390381

391382
close(data->fd[0]);
392383
close(data->fd[1]);

0 commit comments

Comments
 (0)