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>
This commit is contained in:
Patrick Steinhardt
2024-10-17 06:53:47 +02:00
committed by Taylor Blau
parent 409f04995e
commit 7fa7e14ebe
4 changed files with 50 additions and 37 deletions

View File

@ -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);