{"thread":{"id":"9861","subject":"[PATCH 3/5] Cleanup duplicate initialization code in transport_get","startedAt":"2007-09-15T07:23:07Z","lastAt":"2007-09-15T07:23:07Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"53097","messageId":"20070915072307.GC20346@spearce.org","threadId":"9861","inReplyTo":null,"subject":"[PATCH 3/5] Cleanup duplicate initialization code in transport_get","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-09-15T07:23:07Z","receivedAt":"2007-09-15T07:23:07Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We always allocate and return a struct transport* right now as every\nURL is considered to be a native Git transport if it is not rsync,\nhttp/https/ftp or a bundle.  So we can simplify the initialization\nof a new transport object by performing one xcalloc call and filling\nin only the attributes required.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n transport.c |   27 ++++++++++-----------------\n 1 files changed, 10 insertions(+), 17 deletions(-)\n\ndiff --git a/transport.c b/transport.c\nindex 0021190..5eabe8d 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -411,27 +411,26 @@ static int is_file(const char *url)\n struct transport *transport_get(struct remote *remote, const char *url,\n \t\t\t\tint fetch)\n {\n-\tstruct transport *ret = NULL;\n+\tstruct transport *ret = xcalloc(1, sizeof(*ret));\n+\n+\tret->remote = remote;\n+\tret->url = url;\n+\tret->fetch = !!fetch;\n+\n \tif (!prefixcmp(url, \"rsync://\")) {\n-\t\tret = xmalloc(sizeof(*ret));\n-\t\tret->data = NULL;\n \t\tret->ops = &rsync_transport;\n-\t} else if (!prefixcmp(url, \"http://\") || !prefixcmp(url, \"https://\") ||\n-\t\t   !prefixcmp(url, \"ftp://\")) {\n-\t\tret = xmalloc(sizeof(*ret));\n+\t} else if (!prefixcmp(url, \"http://\")\n+\t        || !prefixcmp(url, \"https://\")\n+\t        || !prefixcmp(url, \"ftp://\")) {\n \t\tret->ops = &curl_transport;\n \t\tif (fetch)\n \t\t\tret->data = get_http_walker(url);\n-\t\telse\n-\t\t\tret->data = NULL;\n \t} else if (is_local(url) && is_file(url)) {\n \t\tstruct bundle_transport_data *data = xcalloc(1, sizeof(*data));\n-\t\tret = xmalloc(sizeof(*ret));\n \t\tret->data = data;\n \t\tret->ops = &bundle_transport;\n \t} else {\n \t\tstruct git_transport_data *data = xcalloc(1, sizeof(*data));\n-\t\tret = xcalloc(1, sizeof(*ret));\n \t\tret->data = data;\n \t\tdata->thin = 1;\n \t\tdata->uploadpack = \"git-upload-pack\";\n@@ -443,13 +442,7 @@ struct transport *transport_get(struct remote *remote, const char *url,\n \t\tdata->unpacklimit = -1;\n \t\tret->ops = &git_transport;\n \t}\n-\tif (ret) {\n-\t\tret->remote = remote;\n-\t\tret->url = url;\n-\t\tret->remote_refs = NULL;\n-\t\tret->fetch = !!fetch;\n-\t\tret->pack_lockfile = NULL;\n-\t}\n+\n \treturn ret;\n }\n \n-- \n1.5.3.1.84.gaf82-dirty\n"}]}