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 /reftable/stack.c | |
| parent | 409f04995e6ede838576fb795cf45dc6f10ab508 (diff) | |
| download | git-7fa7e14ebee9d82545bb4a8dcc1cac22ef51cfed.tar.gz | |
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 'reftable/stack.c')
| -rw-r--r-- | reftable/stack.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/reftable/stack.c b/reftable/stack.c index 7e617c2591..d7bc1187df 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -1387,12 +1387,18 @@ static int stack_compact_range(struct reftable_stack *st, * have just written. In case the compacted table became empty we * simply skip writing it. */ - for (i = 0; i < first_to_replace; i++) - strbuf_addf(&tables_list_buf, "%s\n", names[i]); - if (!is_empty_table) - strbuf_addf(&tables_list_buf, "%s\n", new_table_name.buf); - for (i = last_to_replace + 1; names[i]; i++) - strbuf_addf(&tables_list_buf, "%s\n", names[i]); + for (i = 0; i < first_to_replace; i++) { + strbuf_addstr(&tables_list_buf, names[i]); + strbuf_addstr(&tables_list_buf, "\n"); + } + if (!is_empty_table) { + strbuf_addstr(&tables_list_buf, new_table_name.buf); + strbuf_addstr(&tables_list_buf, "\n"); + } + for (i = last_to_replace + 1; names[i]; i++) { + strbuf_addstr(&tables_list_buf, names[i]); + strbuf_addstr(&tables_list_buf, "\n"); + } err = write_in_full(get_lock_file_fd(&tables_list_lock), tables_list_buf.buf, tables_list_buf.len); |
