summaryrefslogtreecommitdiff
path: root/refs
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-07-24 21:50:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-07-24 21:50:47 (GMT)
commit9cb10ca9df2f95e97b5a75d7fea3087972c298ae (patch)
tree0b288477e15e44c5501880b32b74befd24c778da /refs
parent8fa8a4f1ec088ab937d1c460f3eb1701e51b8ffc (diff)
parent80a6c2073b4d90be3e1be21f86afe7a47d1ac7bc (diff)
downloadgit-9cb10ca9df2f95e97b5a75d7fea3087972c298ae.zip
git-9cb10ca9df2f95e97b5a75d7fea3087972c298ae.tar.gz
git-9cb10ca9df2f95e97b5a75d7fea3087972c298ae.tar.bz2
Merge branch 'bp/log-ref-write-fd-with-strbuf'
Code clean-up. * bp/log-ref-write-fd-with-strbuf: convert log_ref_write_fd() to use strbuf
Diffstat (limited to 'refs')
-rw-r--r--refs/files-backend.c29
-rw-r--r--refs/refs-internal.h7
2 files changed, 13 insertions, 23 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index a9a066d..054306d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1582,26 +1582,17 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
const struct object_id *new_oid,
const char *committer, const char *msg)
{
- int msglen, written;
- unsigned maxlen, len;
- char *logrec;
-
- msglen = msg ? strlen(msg) : 0;
- maxlen = strlen(committer) + msglen + 100;
- logrec = xmalloc(maxlen);
- len = xsnprintf(logrec, maxlen, "%s %s %s\n",
- oid_to_hex(old_oid),
- oid_to_hex(new_oid),
- committer);
- if (msglen)
- len += copy_reflog_msg(logrec + len - 1, msg) - 1;
-
- written = len <= maxlen ? write_in_full(fd, logrec, len) : -1;
- free(logrec);
- if (written < 0)
- return -1;
+ struct strbuf sb = STRBUF_INIT;
+ int ret = 0;
- return 0;
+ strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
+ if (msg && *msg)
+ copy_reflog_msg(&sb, msg);
+ strbuf_addch(&sb, '\n');
+ if (write_in_full(fd, sb.buf, sb.len) < 0)
+ ret = -1;
+ strbuf_release(&sb);
+ return ret;
}
static int files_log_ref_write(struct files_ref_store *refs,
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 54bde50..04425d6 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -93,11 +93,10 @@ enum peel_status {
enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
/*
- * Copy the reflog message msg to buf, which has been allocated sufficiently
- * large, while cleaning up the whitespaces. Especially, convert LF to space,
- * because reflog file is one line per entry.
+ * Copy the reflog message msg to sb while cleaning up the whitespaces.
+ * Especially, convert LF to space, because reflog file is one line per entry.
*/
-int copy_reflog_msg(char *buf, const char *msg);
+void copy_reflog_msg(struct strbuf *sb, const char *msg);
/**
* Information needed for a single ref update. Set new_oid to the new