From: Junio C Hamano Date: Tue, 24 Jul 2018 21:50:47 +0000 (-0700) Subject: Merge branch 'bp/log-ref-write-fd-with-strbuf' X-Git-Tag: v2.19.0-rc0~127 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/9cb10ca9df2f95e97b5a75d7fea3087972c298ae?hp=-c 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 --- 9cb10ca9df2f95e97b5a75d7fea3087972c298ae diff --combined refs.c index 3b4508a97a,50fe5c5d2c..08fb5a9914 --- a/refs.c +++ b/refs.c @@@ -9,7 -9,6 +9,7 @@@ #include "iterator.h" #include "refs.h" #include "refs/refs-internal.h" +#include "object-store.h" #include "object.h" #include "tag.h" #include "submodule.h" @@@ -787,25 -786,21 +787,21 @@@ int delete_ref(const char *msg, const c old_oid, flags); } - int copy_reflog_msg(char *buf, const char *msg) + void copy_reflog_msg(struct strbuf *sb, const char *msg) { - char *cp = buf; char c; int wasspace = 1; - *cp++ = '\t'; + strbuf_addch(sb, '\t'); while ((c = *msg++)) { if (wasspace && isspace(c)) continue; wasspace = isspace(c); if (wasspace) c = ' '; - *cp++ = c; + strbuf_addch(sb, c); } - while (buf < cp && isspace(cp[-1])) - cp--; - *cp++ = '\n'; - return cp - buf; + strbuf_rtrim(sb); } int should_autocreate_reflog(const char *refname) diff --combined refs/refs-internal.h index 54bde5089a,17a526078f..04425d6d1e --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@@ -1,8 -1,6 +1,8 @@@ #ifndef REFS_REFS_INTERNAL_H #define REFS_REFS_INTERNAL_H +#include "iterator.h" + /* * Data structures and functions for the internal use of the refs * module. Code outside of the refs module should use only the public @@@ -93,11 -91,10 +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