diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-10-17 06:53:47 +0200 |
|---|---|---|
| committer | Taylor Blau <me@ttaylorr.com> | 2024-10-17 16:59:55 -0400 |
| commit | 7fa7e14ebee9d82545bb4a8dcc1cac22ef51cfed (patch) | |
| tree | 324fe59913e00241fd7560cbcbd4be39a4efa769 /t/unit-tests/t-reftable-readwrite.c | |
| parent | 409f04995e6ede838576fb795cf45dc6f10ab508 (diff) | |
reftable: stop using `strbuf_addf()`
We're about to introduce our own `reftable_buf` type to replace
`strbuf`. One function we'll have to convert is `strbuf_addf()`, which
is used in a handful of places. This function uses `snprintf()`
internally, which makes porting it a bit more involved:
- It is not available on all platforms.
- Some platforms like Windows have broken implementations.
So by using `snprintf()` we'd also push the burden on downstream users
of the reftable library to make available a properly working version of
it.
Most callsites of `strbuf_addf()` are trivial to convert to not using
it. We do end up using `snprintf()` in our unit tests, but that isn't
much of a problem for downstream users of the reftable library.
While at it, remove a useless call to `strbuf_reset()` in
`t_reftable_stack_auto_compaction_with_locked_tables()`. We don't write
to the buffer before this and initialize it with `STRBUF_INIT`, so there
is no need to reset anything.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 't/unit-tests/t-reftable-readwrite.c')
| -rw-r--r-- | t/unit-tests/t-reftable-readwrite.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c index 27ce84445e..5f59b0ad6a 100644 --- a/t/unit-tests/t-reftable-readwrite.c +++ b/t/unit-tests/t-reftable-readwrite.c @@ -753,12 +753,13 @@ static void t_write_multiple_indices(void) struct reftable_write_options opts = { .block_size = 100, }; - struct strbuf writer_buf = STRBUF_INIT, buf = STRBUF_INIT; + struct strbuf writer_buf = STRBUF_INIT; struct reftable_block_source source = { 0 }; struct reftable_iterator it = { 0 }; const struct reftable_stats *stats; struct reftable_writer *writer; struct reftable_reader *reader; + char buf[128]; int err, i; writer = t_reftable_strbuf_writer(&writer_buf, &opts); @@ -770,9 +771,8 @@ static void t_write_multiple_indices(void) .value.val1 = {i}, }; - strbuf_reset(&buf); - strbuf_addf(&buf, "refs/heads/%04d", i); - ref.refname = buf.buf, + snprintf(buf, sizeof(buf), "refs/heads/%04d", i); + ref.refname = buf; err = reftable_writer_add_ref(writer, &ref); check(!err); @@ -788,9 +788,8 @@ static void t_write_multiple_indices(void) }, }; - strbuf_reset(&buf); - strbuf_addf(&buf, "refs/heads/%04d", i); - log.refname = buf.buf, + snprintf(buf, sizeof(buf), "refs/heads/%04d", i); + log.refname = buf; err = reftable_writer_add_log(writer, &log); check(!err); @@ -824,7 +823,6 @@ static void t_write_multiple_indices(void) reftable_writer_free(writer); reftable_reader_decref(reader); strbuf_release(&writer_buf); - strbuf_release(&buf); } static void t_write_multi_level_index(void) @@ -848,10 +846,10 @@ static void t_write_multi_level_index(void) .value_type = REFTABLE_REF_VAL1, .value.val1 = {i}, }; + char buf[128]; - strbuf_reset(&buf); - strbuf_addf(&buf, "refs/heads/%03" PRIuMAX, (uintmax_t)i); - ref.refname = buf.buf, + snprintf(buf, sizeof(buf), "refs/heads/%03" PRIuMAX, (uintmax_t)i); + ref.refname = buf; err = reftable_writer_add_ref(writer, &ref); check(!err); |
