http-push: use strbuf instead of fwrite_buffer
The http-push code defines an fwrite_buffer function for use as a curl callback; it just writes to a strbuf. There's no reason we need to use it ourselves, as we know we have a strbuf. This lets us format directly into it, rather than dealing with an extra temporary buffer (which required manual length computation). While we're here, let's also remove the literal tabs from the source in favor of "\t", which is more visually obvious. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 24, 2015 at 17:07 UTC
7d0581a9abe733d8880113370c4d956b50f5bd9f
1 file changed
+5
-16
http-push.c
+5
-16
@@ -1459,8 +1459,6 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
1459
{
1460
struct strbuf *buf = (struct strbuf *)ls->userData;
1461
struct object *o;
1462
- int len;
1463
- char *ref_info;
1462
struct ref *ref;
1463
1464
ref = alloc_ref(ls->dentry_name);
@@ -1484,23 +1482,14 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
1482
return;
1483
}
1484
1487
- len = strlen(ls->dentry_name) + 42;
1488
- ref_info = xcalloc(len + 1, 1);
1489
- sprintf(ref_info, "%s %s\n",
1490
- sha1_to_hex(ref->old_sha1), ls->dentry_name);
1491
- fwrite_buffer(ref_info, 1, len, buf);
1492
- free(ref_info);
1485
+ strbuf_addf(buf, "%s\t%s\n",
1486
+ sha1_to_hex(ref->old_sha1), ls->dentry_name);
1487
1488
if (o->type == OBJ_TAG) {
1489
o = deref_tag(o, ls->dentry_name, 0);
1496
- if (o) {
1497
- len = strlen(ls->dentry_name) + 45;
1498
- ref_info = xcalloc(len + 1, 1);
1499
- sprintf(ref_info, "%s %s^{}\n",
1500
- sha1_to_hex(o->sha1), ls->dentry_name);
1501
- fwrite_buffer(ref_info, 1, len, buf);
1502
- free(ref_info);
1503
- }
1490
+ if (o)
1491
+ strbuf_addf(buf, "%s\t%s^{}\n",
1492
+ sha1_to_hex(o->sha1), ls->dentry_name);
1493
}
1494
free(ref);
1495
}