transport-helper: call do_take_over() in process_connect

The existing pattern among all callers of process_connect() seems to be if (process_connect(...)) { do_take_over(); ... dispatch to the underlying method ... } ... otherwise implement the fallback ... where the return value from process_connect() is the return value of the call it makes to process_connect_service(). Move the call of do_take_over() inside process_connect(), so that calling the process_connect() function is more concise and will not miss do_take_over(). Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jiang Xin committed Jan 21, 2024 at 21:15 UTC 176cd68634c4641cc45030dc7f287be47d1809d1
1 file changed +9 -13
transport-helper.c
+9 -13
@@ -646,6 +646,7 @@ static int process_connect(struct transport *transport,
646 struct helper_data *data = transport->data;
647 const char *name;
648 const char *exec;
649 + int ret;
650
651 name = for_push ? "git-receive-pack" : "git-upload-pack";
652 if (for_push)
@@ -653,7 +654,10 @@ static int process_connect(struct transport *transport,
654 else
655 exec = data->transport_options.uploadpack;
656
656 - return process_connect_service(transport, name, exec);
657 + ret = process_connect_service(transport, name, exec);
658 + if (ret)
659 + do_take_over(transport);
660 + return ret;
661 }
662
663 static int connect_helper(struct transport *transport, const char *name,
@@ -685,10 +689,8 @@ static int fetch_refs(struct transport *transport,
689
690 get_helper(transport);
691
688 - if (process_connect(transport, 0)) {
689 - do_take_over(transport);
692 + if (process_connect(transport, 0))
693 return transport->vtable->fetch_refs(transport, nr_heads, to_fetch);
691 - }
694
695 /*
696 * If we reach here, then the server, the client, and/or the transport
@@ -1145,10 +1147,8 @@ static int push_refs(struct transport *transport,
1147 {
1148 struct helper_data *data = transport->data;
1149
1148 - if (process_connect(transport, 1)) {
1149 - do_take_over(transport);
1150 + if (process_connect(transport, 1))
1151 return transport->vtable->push_refs(transport, remote_refs, flags);
1151 - }
1152
1153 if (!remote_refs) {
1154 fprintf(stderr,
@@ -1189,11 +1189,9 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
1189 {
1190 get_helper(transport);
1191
1192 - if (process_connect(transport, for_push)) {
1193 - do_take_over(transport);
1192 + if (process_connect(transport, for_push))
1193 return transport->vtable->get_refs_list(transport, for_push,
1194 transport_options);
1196 - }
1195
1196 return get_refs_list_using_list(transport, for_push);
1197 }
@@ -1277,10 +1275,8 @@ static int get_bundle_uri(struct transport *transport)
1275 {
1276 get_helper(transport);
1277
1280 - if (process_connect(transport, 0)) {
1281 - do_take_over(transport);
1278 + if (process_connect(transport, 0))
1279 return transport->vtable->get_bundle_uri(transport);
1283 - }
1280
1281 return -1;
1282 }