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().

It is safe to make a refactor by moving the call of do_take_over()
into the function process_connect().

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>
This commit is contained in:
Jiang Xin
2023-10-04 23:21:41 +08:00
committed by Junio C Hamano
parent 1818d8e30e
commit b57524bc91

View File

@ -645,6 +645,7 @@ static int process_connect(struct transport *transport,
struct helper_data *data = transport->data; struct helper_data *data = transport->data;
const char *name; const char *name;
const char *exec; const char *exec;
int ret;
name = for_push ? "git-receive-pack" : "git-upload-pack"; name = for_push ? "git-receive-pack" : "git-upload-pack";
if (for_push) if (for_push)
@ -652,7 +653,10 @@ static int process_connect(struct transport *transport,
else else
exec = data->transport_options.uploadpack; exec = data->transport_options.uploadpack;
return process_connect_service(transport, name, exec); ret = process_connect_service(transport, name, exec);
if (ret)
do_take_over(transport);
return ret;
} }
static int connect_helper(struct transport *transport, const char *name, static int connect_helper(struct transport *transport, const char *name,
@ -682,10 +686,8 @@ static int fetch_refs(struct transport *transport,
get_helper(transport); get_helper(transport);
if (process_connect(transport, 0)) { if (process_connect(transport, 0))
do_take_over(transport);
return transport->vtable->fetch_refs(transport, nr_heads, to_fetch); return transport->vtable->fetch_refs(transport, nr_heads, to_fetch);
}
/* /*
* If we reach here, then the server, the client, and/or the transport * If we reach here, then the server, the client, and/or the transport
@ -1142,10 +1144,8 @@ static int push_refs(struct transport *transport,
{ {
struct helper_data *data = transport->data; struct helper_data *data = transport->data;
if (process_connect(transport, 1)) { if (process_connect(transport, 1))
do_take_over(transport);
return transport->vtable->push_refs(transport, remote_refs, flags); return transport->vtable->push_refs(transport, remote_refs, flags);
}
if (!remote_refs) { if (!remote_refs) {
fprintf(stderr, fprintf(stderr,
@ -1186,11 +1186,9 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
{ {
get_helper(transport); get_helper(transport);
if (process_connect(transport, for_push)) { if (process_connect(transport, for_push))
do_take_over(transport);
return transport->vtable->get_refs_list(transport, for_push, return transport->vtable->get_refs_list(transport, for_push,
transport_options); transport_options);
}
return get_refs_list_using_list(transport, for_push); return get_refs_list_using_list(transport, for_push);
} }
@ -1274,10 +1272,8 @@ static int get_bundle_uri(struct transport *transport)
{ {
get_helper(transport); get_helper(transport);
if (process_connect(transport, 0)) { if (process_connect(transport, 0))
do_take_over(transport);
return transport->vtable->get_bundle_uri(transport); return transport->vtable->get_bundle_uri(transport);
}
return -1; return -1;
} }