summaryrefslogtreecommitdiffstats
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-06-12 22:37:15 +0200
committerJunio C Hamano <gitster@pobox.com>2024-06-12 22:37:15 +0200
commit22cf18fd9ede79bdfe5ac93e09986a64052e5781 (patch)
tree8ab7f912a4b11df3c9397d4a7332510eb3594205 /strbuf.c
parentMerge branch 'cp/reftable-unit-test' (diff)
parentt/: migrate helper/test-{sha1, sha256} to unit-tests/t-hash (diff)
downloadgit-22cf18fd9ede79bdfe5ac93e09986a64052e5781.tar.xz
git-22cf18fd9ede79bdfe5ac93e09986a64052e5781.zip
Merge branch 'gt/t-hash-unit-test'
A pair of test helpers that essentially are unit tests on hash algorithms have been rewritten using the unit-tests framework. * gt/t-hash-unit-test: t/: migrate helper/test-{sha1, sha256} to unit-tests/t-hash strbuf: introduce strbuf_addstrings() to repeatedly add a string
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/strbuf.c b/strbuf.c
index e1076c9891..3d2189a7f6 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -313,6 +313,15 @@ void strbuf_add(struct strbuf *sb, const void *data, size_t len)
strbuf_setlen(sb, sb->len + len);
}
+void strbuf_addstrings(struct strbuf *sb, const char *s, size_t n)
+{
+ size_t len = strlen(s);
+
+ strbuf_grow(sb, st_mult(len, n));
+ for (size_t i = 0; i < n; i++)
+ strbuf_add(sb, s, len);
+}
+
void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
{
strbuf_grow(sb, sb2->len);