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>
Shawn O. Pearce committed
Sep 15, 2007 at 03:23 UTC
8eb554ae628d2504922912fb5f046741da4654fc
1 file changed
+10
-17
transport.c
+10
-17
@@ -411,27 +411,26 @@ static int is_file(const char *url)
411
struct transport *transport_get(struct remote *remote, const char *url,
412
int fetch)
413
{
414
- struct transport *ret = NULL;
414
+ struct transport *ret = xcalloc(1, sizeof(*ret));
415
+
416
+ ret->remote = remote;
417
+ ret->url = url;
418
+ ret->fetch = !!fetch;
419
+
420
if (!prefixcmp(url, "rsync://")) {
416
- ret = xmalloc(sizeof(*ret));
417
- ret->data = NULL;
421
ret->ops = &rsync_transport;
419
- } else if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://") ||
420
- !prefixcmp(url, "ftp://")) {
421
- ret = xmalloc(sizeof(*ret));
422
+ } else if (!prefixcmp(url, "http://")
423
+ || !prefixcmp(url, "https://")
424
+ || !prefixcmp(url, "ftp://")) {
425
ret->ops = &curl_transport;
426
if (fetch)
427
ret->data = get_http_walker(url);
425
- else
426
- ret->data = NULL;
428
} else if (is_local(url) && is_file(url)) {
429
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
429
- ret = xmalloc(sizeof(*ret));
430
ret->data = data;
431
ret->ops = &bundle_transport;
432
} else {
433
struct git_transport_data *data = xcalloc(1, sizeof(*data));
434
- ret = xcalloc(1, sizeof(*ret));
434
ret->data = data;
435
data->thin = 1;
436
data->uploadpack = "git-upload-pack";
@@ -443,13 +442,7 @@ struct transport *transport_get(struct remote *remote, const char *url,
442
data->unpacklimit = -1;
443
ret->ops = &git_transport;
444
}
446
- if (ret) {
447
- ret->remote = remote;
448
- ret->url = url;
449
- ret->remote_refs = NULL;
450
- ret->fetch = !!fetch;
451
- ret->pack_lockfile = NULL;
452
- }
445
+
446
return ret;
447
}
448