diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-10-17 06:53:56 +0200 |
|---|---|---|
| committer | Taylor Blau <me@ttaylorr.com> | 2024-10-17 16:59:56 -0400 |
| commit | be4c070a3c9e7c9d6836c724929ff8a365361e1a (patch) | |
| tree | 03cec9016c899456a020c06e98239963a2958238 /t/unit-tests/t-reftable-stack.c | |
| parent | 81eddda540eae43ef481b629d7f4d8023ea40c57 (diff) | |
reftable: convert from `strbuf` to `reftable_buf`
Convert the reftable library to use the `reftable_buf` interface instead
of the `strbuf` interface. This is mostly a mechanical change via sed(1)
with some manual fixes where functions for `strbuf` and `reftable_buf`
differ. The converted code does not yet handle allocation failures. This
will be handled in subsequent commits.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 't/unit-tests/t-reftable-stack.c')
| -rw-r--r-- | t/unit-tests/t-reftable-stack.c | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c index b56ea77431..f49856270d 100644 --- a/t/unit-tests/t-reftable-stack.c +++ b/t/unit-tests/t-reftable-stack.c @@ -16,7 +16,7 @@ https://developers.google.com/open-source/licenses/bsd static void clear_dir(const char *dirname) { - struct strbuf path = STRBUF_INIT; + struct strbuf path = REFTABLE_BUF_INIT; strbuf_addstr(&path, dirname); remove_dir_recursively(&path, 0); strbuf_release(&path); @@ -145,7 +145,7 @@ static int write_test_log(struct reftable_writer *wr, void *arg) static void t_reftable_stack_add_one(void) { char *dir = get_tmp_dir(__LINE__); - struct strbuf scratch = STRBUF_INIT; + struct reftable_buf scratch = REFTABLE_BUF_INIT; int mask = umask(002); struct reftable_write_options opts = { .default_permissions = 0660, @@ -172,17 +172,17 @@ static void t_reftable_stack_add_one(void) check_int(st->readers_len, >, 0); #ifndef GIT_WINDOWS_NATIVE - strbuf_addstr(&scratch, dir); - strbuf_addstr(&scratch, "/tables.list"); + reftable_buf_addstr(&scratch, dir); + reftable_buf_addstr(&scratch, "/tables.list"); err = stat(scratch.buf, &stat_result); check(!err); check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); - strbuf_reset(&scratch); - strbuf_addstr(&scratch, dir); - strbuf_addstr(&scratch, "/"); + reftable_buf_reset(&scratch); + reftable_buf_addstr(&scratch, dir); + reftable_buf_addstr(&scratch, "/"); /* do not try at home; not an external API for reftable. */ - strbuf_addstr(&scratch, st->readers[0]->name); + reftable_buf_addstr(&scratch, st->readers[0]->name); err = stat(scratch.buf, &stat_result); check(!err); check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); @@ -192,7 +192,7 @@ static void t_reftable_stack_add_one(void) reftable_ref_record_release(&dest); reftable_stack_destroy(st); - strbuf_release(&scratch); + reftable_buf_release(&scratch); clear_dir(dir); umask(mask); } @@ -414,7 +414,7 @@ static void t_reftable_stack_auto_compaction_fails_gracefully(void) }; struct reftable_write_options opts = { 0 }; struct reftable_stack *st; - struct strbuf table_path = STRBUF_INIT; + struct reftable_buf table_path = REFTABLE_BUF_INIT; char *dir = get_tmp_dir(__LINE__); int err; @@ -432,10 +432,10 @@ static void t_reftable_stack_auto_compaction_fails_gracefully(void) * Adding a new table to the stack should not be impacted by this, even * though auto-compaction will now fail. */ - strbuf_addstr(&table_path, dir); - strbuf_addstr(&table_path, "/"); - strbuf_addstr(&table_path, st->readers[0]->name); - strbuf_addstr(&table_path, ".lock"); + reftable_buf_addstr(&table_path, dir); + reftable_buf_addstr(&table_path, "/"); + reftable_buf_addstr(&table_path, st->readers[0]->name); + reftable_buf_addstr(&table_path, ".lock"); write_file_buf(table_path.buf, "", 0); ref.update_index = 2; @@ -446,7 +446,7 @@ static void t_reftable_stack_auto_compaction_fails_gracefully(void) check_int(st->stats.failures, ==, 1); reftable_stack_destroy(st); - strbuf_release(&table_path); + reftable_buf_release(&table_path); clear_dir(dir); } @@ -516,7 +516,7 @@ static void t_reftable_stack_add(void) char *dir = get_tmp_dir(__LINE__); struct reftable_ref_record refs[2] = { 0 }; struct reftable_log_record logs[2] = { 0 }; - struct strbuf path = STRBUF_INIT; + struct reftable_buf path = REFTABLE_BUF_INIT; struct stat stat_result; size_t i, N = ARRAY_SIZE(refs); @@ -575,17 +575,17 @@ static void t_reftable_stack_add(void) } #ifndef GIT_WINDOWS_NATIVE - strbuf_addstr(&path, dir); - strbuf_addstr(&path, "/tables.list"); + reftable_buf_addstr(&path, dir); + reftable_buf_addstr(&path, "/tables.list"); err = stat(path.buf, &stat_result); check(!err); check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); - strbuf_reset(&path); - strbuf_addstr(&path, dir); - strbuf_addstr(&path, "/"); + reftable_buf_reset(&path); + reftable_buf_addstr(&path, dir); + reftable_buf_addstr(&path, "/"); /* do not try at home; not an external API for reftable. */ - strbuf_addstr(&path, st->readers[0]->name); + reftable_buf_addstr(&path, st->readers[0]->name); err = stat(path.buf, &stat_result); check(!err); check_int((stat_result.st_mode & 0777), ==, opts.default_permissions); @@ -599,7 +599,7 @@ static void t_reftable_stack_add(void) reftable_ref_record_release(&refs[i]); reftable_log_record_release(&logs[i]); } - strbuf_release(&path); + reftable_buf_release(&path); clear_dir(dir); } @@ -1063,7 +1063,7 @@ static void t_reftable_stack_auto_compaction_with_locked_tables(void) .disable_auto_compact = 1, }; struct reftable_stack *st = NULL; - struct strbuf buf = STRBUF_INIT; + struct reftable_buf buf = REFTABLE_BUF_INIT; char *dir = get_tmp_dir(__LINE__); int err; @@ -1078,10 +1078,10 @@ static void t_reftable_stack_auto_compaction_with_locked_tables(void) * size, we expect that auto-compaction will want to compact all of the * tables. Locking any of the tables will keep it from doing so. */ - strbuf_addstr(&buf, dir); - strbuf_addstr(&buf, "/"); - strbuf_addstr(&buf, st->readers[2]->name); - strbuf_addstr(&buf, ".lock"); + reftable_buf_addstr(&buf, dir); + reftable_buf_addstr(&buf, "/"); + reftable_buf_addstr(&buf, st->readers[2]->name); + reftable_buf_addstr(&buf, ".lock"); write_file_buf(buf.buf, "", 0); /* @@ -1096,7 +1096,7 @@ static void t_reftable_stack_auto_compaction_with_locked_tables(void) check_int(st->merged->readers_len, ==, 4); reftable_stack_destroy(st); - strbuf_release(&buf); + reftable_buf_release(&buf); clear_dir(dir); } @@ -1153,7 +1153,7 @@ static void t_reftable_stack_compaction_with_locked_tables(void) .disable_auto_compact = 1, }; struct reftable_stack *st = NULL; - struct strbuf buf = STRBUF_INIT; + struct reftable_buf buf = REFTABLE_BUF_INIT; char *dir = get_tmp_dir(__LINE__); int err; @@ -1164,10 +1164,10 @@ static void t_reftable_stack_compaction_with_locked_tables(void) check_int(st->merged->readers_len, ==, 3); /* Lock one of the tables that we're about to compact. */ - strbuf_addstr(&buf, dir); - strbuf_addstr(&buf, "/"); - strbuf_addstr(&buf, st->readers[1]->name); - strbuf_addstr(&buf, ".lock"); + reftable_buf_addstr(&buf, dir); + reftable_buf_addstr(&buf, "/"); + reftable_buf_addstr(&buf, st->readers[1]->name); + reftable_buf_addstr(&buf, ".lock"); write_file_buf(buf.buf, "", 0); /* @@ -1180,7 +1180,7 @@ static void t_reftable_stack_compaction_with_locked_tables(void) check_int(st->merged->readers_len, ==, 3); reftable_stack_destroy(st); - strbuf_release(&buf); + reftable_buf_release(&buf); clear_dir(dir); } @@ -1306,7 +1306,7 @@ static void t_reftable_stack_reload_with_missing_table(void) struct reftable_stack *st = NULL; struct reftable_ref_record rec = { 0 }; struct reftable_iterator it = { 0 }; - struct strbuf table_path = STRBUF_INIT, content = STRBUF_INIT; + struct reftable_buf table_path = REFTABLE_BUF_INIT, content = REFTABLE_BUF_INIT; char *dir = get_tmp_dir(__LINE__); int err; @@ -1324,13 +1324,13 @@ static void t_reftable_stack_reload_with_missing_table(void) * our old readers. This should trigger a partial reload of the stack, * where we try to reuse our old readers. */ - strbuf_addstr(&content, st->readers[0]->name); - strbuf_addstr(&content, "\n"); - strbuf_addstr(&content, st->readers[1]->name); - strbuf_addstr(&content, "\n"); - strbuf_addstr(&content, "garbage\n"); - strbuf_addstr(&table_path, st->list_file); - strbuf_addstr(&table_path, ".lock"); + reftable_buf_addstr(&content, st->readers[0]->name); + reftable_buf_addstr(&content, "\n"); + reftable_buf_addstr(&content, st->readers[1]->name); + reftable_buf_addstr(&content, "\n"); + reftable_buf_addstr(&content, "garbage\n"); + reftable_buf_addstr(&table_path, st->list_file); + reftable_buf_addstr(&table_path, ".lock"); write_file_buf(table_path.buf, content.buf, content.len); err = rename(table_path.buf, st->list_file); check(!err); @@ -1355,8 +1355,8 @@ static void t_reftable_stack_reload_with_missing_table(void) reftable_ref_record_release(&rec); reftable_iterator_destroy(&it); reftable_stack_destroy(st); - strbuf_release(&table_path); - strbuf_release(&content); + reftable_buf_release(&table_path); + reftable_buf_release(&content); clear_dir(dir); } |
