git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 3/5] Cleanup duplicate initialization code in transport_get
Date: Sat, 15 Sep 2007 03:23:07 -0400	[thread overview]
Message-ID: <20070915072307.GC20346@spearce.org> (raw)

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>
---
 transport.c |   27 ++++++++++-----------------
 1 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/transport.c b/transport.c
index 0021190..5eabe8d 100644
--- a/transport.c
+++ b/transport.c
@@ -411,27 +411,26 @@ static int is_file(const char *url)
 struct transport *transport_get(struct remote *remote, const char *url,
 				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://")) {
-		ret = xmalloc(sizeof(*ret));
-		ret->data = NULL;
 		ret->ops = &rsync_transport;
-	} else if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://") ||
-		   !prefixcmp(url, "ftp://")) {
-		ret = xmalloc(sizeof(*ret));
+	} else if (!prefixcmp(url, "http://")
+	        || !prefixcmp(url, "https://")
+	        || !prefixcmp(url, "ftp://")) {
 		ret->ops = &curl_transport;
 		if (fetch)
 			ret->data = get_http_walker(url);
-		else
-			ret->data = NULL;
 	} else if (is_local(url) && is_file(url)) {
 		struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
-		ret = xmalloc(sizeof(*ret));
 		ret->data = data;
 		ret->ops = &bundle_transport;
 	} else {
 		struct git_transport_data *data = xcalloc(1, sizeof(*data));
-		ret = xcalloc(1, sizeof(*ret));
 		ret->data = data;
 		data->thin = 1;
 		data->uploadpack = "git-upload-pack";
@@ -443,13 +442,7 @@ struct transport *transport_get(struct remote *remote, const char *url,
 		data->unpacklimit = -1;
 		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;
 }
 
-- 
1.5.3.1.84.gaf82-dirty

                 reply	other threads:[~2007-09-15  7:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070915072307.GC20346@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).