Cleanup duplicate initialization code in transport_get
We always allocate and return a struct transport* right now as every URL is considered to be a native Git transport if it is not rsync, http/https/ftp or a bundle. So we can simplify the initialization of a new transport object by performing one xcalloc call and filling in only the attributes required. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b6abb48a15
commit
8eb554ae62
27
transport.c
27
transport.c
@ -411,27 +411,26 @@ static int is_file(const char *url)
|
|||||||
struct transport *transport_get(struct remote *remote, const char *url,
|
struct transport *transport_get(struct remote *remote, const char *url,
|
||||||
int fetch)
|
int fetch)
|
||||||
{
|
{
|
||||||
struct transport *ret = NULL;
|
struct transport *ret = xcalloc(1, sizeof(*ret));
|
||||||
|
|
||||||
|
ret->remote = remote;
|
||||||
|
ret->url = url;
|
||||||
|
ret->fetch = !!fetch;
|
||||||
|
|
||||||
if (!prefixcmp(url, "rsync://")) {
|
if (!prefixcmp(url, "rsync://")) {
|
||||||
ret = xmalloc(sizeof(*ret));
|
|
||||||
ret->data = NULL;
|
|
||||||
ret->ops = &rsync_transport;
|
ret->ops = &rsync_transport;
|
||||||
} else if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://") ||
|
} else if (!prefixcmp(url, "http://")
|
||||||
!prefixcmp(url, "ftp://")) {
|
|| !prefixcmp(url, "https://")
|
||||||
ret = xmalloc(sizeof(*ret));
|
|| !prefixcmp(url, "ftp://")) {
|
||||||
ret->ops = &curl_transport;
|
ret->ops = &curl_transport;
|
||||||
if (fetch)
|
if (fetch)
|
||||||
ret->data = get_http_walker(url);
|
ret->data = get_http_walker(url);
|
||||||
else
|
|
||||||
ret->data = NULL;
|
|
||||||
} else if (is_local(url) && is_file(url)) {
|
} else if (is_local(url) && is_file(url)) {
|
||||||
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
|
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
|
||||||
ret = xmalloc(sizeof(*ret));
|
|
||||||
ret->data = data;
|
ret->data = data;
|
||||||
ret->ops = &bundle_transport;
|
ret->ops = &bundle_transport;
|
||||||
} else {
|
} else {
|
||||||
struct git_transport_data *data = xcalloc(1, sizeof(*data));
|
struct git_transport_data *data = xcalloc(1, sizeof(*data));
|
||||||
ret = xcalloc(1, sizeof(*ret));
|
|
||||||
ret->data = data;
|
ret->data = data;
|
||||||
data->thin = 1;
|
data->thin = 1;
|
||||||
data->uploadpack = "git-upload-pack";
|
data->uploadpack = "git-upload-pack";
|
||||||
@ -443,13 +442,7 @@ struct transport *transport_get(struct remote *remote, const char *url,
|
|||||||
data->unpacklimit = -1;
|
data->unpacklimit = -1;
|
||||||
ret->ops = &git_transport;
|
ret->ops = &git_transport;
|
||||||
}
|
}
|
||||||
if (ret) {
|
|
||||||
ret->remote = remote;
|
|
||||||
ret->url = url;
|
|
||||||
ret->remote_refs = NULL;
|
|
||||||
ret->fetch = !!fetch;
|
|
||||||
ret->pack_lockfile = NULL;
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user