summaryrefslogtreecommitdiff
path: root/http-push.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-19 17:24:33 -0400
committerJunio C Hamano <gitster@pobox.com>2014-06-19 15:20:54 -0700
commit283101869bea8feb5d58f6ea1b568e9b197526d3 (patch)
tree3aba65688e4a5a11a3d0a60d2fa60930fd398898 /http-push.c
parent95244ae3dd49b3eed4dbfe09299b9d8847622218 (diff)
downloadgit-283101869bea8feb5d58f6ea1b568e9b197526d3.tar.gz
use xstrfmt to replace xmalloc + sprintf
This is one line shorter, and makes sure the length in the malloc and sprintf steps match. These conversions are very straightforward; we can drop the malloc entirely, and replace the sprintf with xstrfmt. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'http-push.c')
-rw-r--r--http-push.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/http-push.c b/http-push.c
index 95650a0241..390f74c97b 100644
--- a/http-push.c
+++ b/http-push.c
@@ -854,8 +854,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
struct xml_ctx ctx;
char *escaped;
- url = xmalloc(strlen(repo->url) + strlen(path) + 1);
- sprintf(url, "%s%s", repo->url, path);
+ url = xstrfmt("%s%s", repo->url, path);
/* Make sure leading directories exist for the remote ref */
ep = strchr(url + strlen(repo->url) + 1, '/');
@@ -1115,7 +1114,7 @@ static void remote_ls(const char *path, int flags,
void (*userFunc)(struct remote_ls_ctx *ls),
void *userData)
{
- char *url = xmalloc(strlen(repo->url) + strlen(path) + 1);
+ char *url = xstrfmt("%s%s", repo->url, path);
struct active_request_slot *slot;
struct slot_results results;
struct strbuf in_buffer = STRBUF_INIT;
@@ -1131,8 +1130,6 @@ static void remote_ls(const char *path, int flags,
ls.userData = userData;
ls.userFunc = userFunc;
- sprintf(url, "%s%s", repo->url, path);
-
strbuf_addf(&out_buffer.buf, PROPFIND_ALL_REQUEST);
dav_headers = curl_slist_append(dav_headers, "Depth: 1");
@@ -1534,10 +1531,9 @@ static void update_remote_info_refs(struct remote_lock *lock)
static int remote_exists(const char *path)
{
- char *url = xmalloc(strlen(repo->url) + strlen(path) + 1);
+ char *url = xstrfmt("%s%s", repo->url, path);
int ret;
- sprintf(url, "%s%s", repo->url, path);
switch (http_get_strbuf(url, NULL, NULL)) {
case HTTP_OK:
@@ -1557,12 +1553,9 @@ static int remote_exists(const char *path)
static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
{
- char *url;
+ char *url = xstrfmt("%s%s", repo->url, path);
struct strbuf buffer = STRBUF_INIT;
- url = xmalloc(strlen(repo->url) + strlen(path) + 1);
- sprintf(url, "%s%s", repo->url, path);
-
if (http_get_strbuf(url, &buffer, NULL) != HTTP_OK)
die("Couldn't get %s for remote symref\n%s", url,
curl_errorstr);
@@ -1671,8 +1664,7 @@ static int delete_remote_branch(const char *pattern, int force)
fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name);
if (dry_run)
return 0;
- url = xmalloc(strlen(repo->url) + strlen(remote_ref->name) + 1);
- sprintf(url, "%s%s", repo->url, remote_ref->name);
+ url = xstrfmt("%s%s", repo->url, remote_ref->name);
slot = get_active_slot();
slot->results = &results;
curl_setup_http_get(slot->curl, url, DAV_DELETE);