diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-08-08 14:21:42 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-08-08 14:21:42 -0700 |
commit | 48aa37ed4266e75340abd3232860d6d14a30c774 (patch) | |
tree | 3e60b02a98d98b64b604da514f345561fed293c6 | |
parent | Merge branch 'lf/recv-sideband-cleanup' into maint (diff) | |
parent | strbuf: avoid calling strbuf_grow() twice in strbuf_addbuf() (diff) | |
download | tgif-48aa37ed4266e75340abd3232860d6d14a30c774.tar.xz |
Merge branch 'rs/use-strbuf-addbuf' into maint
Code cleanup.
* rs/use-strbuf-addbuf:
strbuf: avoid calling strbuf_grow() twice in strbuf_addbuf()
use strbuf_addbuf() for appending a strbuf to another
-rw-r--r-- | dir.c | 2 | ||||
-rw-r--r-- | path.c | 2 | ||||
-rw-r--r-- | strbuf.c | 7 | ||||
-rw-r--r-- | strbuf.h | 6 | ||||
-rw-r--r-- | wt-status.c | 2 |
5 files changed, 11 insertions, 8 deletions
@@ -2364,7 +2364,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra varint_len = encode_varint(untracked->ident.len, varbuf); strbuf_add(out, varbuf, varint_len); - strbuf_add(out, untracked->ident.buf, untracked->ident.len); + strbuf_addbuf(out, &untracked->ident); strbuf_add(out, ouc, ouc_size(len)); free(ouc); @@ -483,7 +483,7 @@ static void do_submodule_path(struct strbuf *buf, const char *path, strbuf_addstr(buf, git_dir); } strbuf_addch(buf, '/'); - strbuf_addstr(&git_submodule_dir, buf->buf); + strbuf_addbuf(&git_submodule_dir, buf); strbuf_vaddf(buf, fmt, args); @@ -197,6 +197,13 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len) strbuf_setlen(sb, sb->len + len); } +void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) +{ + strbuf_grow(sb, sb2->len); + memcpy(sb->buf + sb->len, sb2->buf, sb2->len); + strbuf_setlen(sb, sb->len + sb2->len); +} + void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len) { strbuf_grow(sb, len); @@ -263,11 +263,7 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s) /** * Copy the contents of another buffer at the end of the current one. */ -static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) -{ - strbuf_grow(sb, sb2->len); - strbuf_add(sb, sb2->buf, sb2->len); -} +extern void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2); /** * Copy part of the buffer from a given position till a given length to the diff --git a/wt-status.c b/wt-status.c index 4ce4e35ac3..617a284304 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1062,7 +1062,7 @@ static void abbrev_sha1_in_line(struct strbuf *line) strbuf_addf(split[1], "%s ", abbrev); strbuf_reset(line); for (i = 0; split[i]; i++) - strbuf_addf(line, "%s", split[i]->buf); + strbuf_addbuf(line, split[i]); } } strbuf_list_free(split); |