diff options
Diffstat (limited to 'reftable/stack.c')
| -rw-r--r-- | reftable/stack.c | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/reftable/stack.c b/reftable/stack.c index d7bc1187df..6ba48ddce5 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -31,13 +31,13 @@ static void reftable_addition_close(struct reftable_addition *add); static int reftable_stack_reload_maybe_reuse(struct reftable_stack *st, int reuse_open); -static void stack_filename(struct strbuf *dest, struct reftable_stack *st, +static void stack_filename(struct reftable_buf *dest, struct reftable_stack *st, const char *name) { - strbuf_reset(dest); - strbuf_addstr(dest, st->reftable_dir); - strbuf_addstr(dest, "/"); - strbuf_addstr(dest, name); + reftable_buf_reset(dest); + reftable_buf_addstr(dest, st->reftable_dir); + reftable_buf_addstr(dest, "/"); + reftable_buf_addstr(dest, name); } static ssize_t reftable_fd_write(void *arg, const void *data, size_t sz) @@ -56,7 +56,7 @@ static int reftable_fd_flush(void *arg) int reftable_new_stack(struct reftable_stack **dest, const char *dir, const struct reftable_write_options *_opts) { - struct strbuf list_file_name = STRBUF_INIT; + struct reftable_buf list_file_name = REFTABLE_BUF_INIT; struct reftable_write_options opts = { 0 }; struct reftable_stack *p; int err; @@ -74,11 +74,11 @@ int reftable_new_stack(struct reftable_stack **dest, const char *dir, *dest = NULL; - strbuf_reset(&list_file_name); - strbuf_addstr(&list_file_name, dir); - strbuf_addstr(&list_file_name, "/tables.list"); + reftable_buf_reset(&list_file_name); + reftable_buf_addstr(&list_file_name, dir); + reftable_buf_addstr(&list_file_name, "/tables.list"); - p->list_file = strbuf_detach(&list_file_name, NULL); + p->list_file = reftable_buf_detach(&list_file_name); p->list_fd = -1; p->opts = opts; p->reftable_dir = reftable_strdup(dir); @@ -208,10 +208,10 @@ void reftable_stack_destroy(struct reftable_stack *st) if (st->readers) { int i = 0; - struct strbuf filename = STRBUF_INIT; + struct reftable_buf filename = REFTABLE_BUF_INIT; for (i = 0; i < st->readers_len; i++) { const char *name = reader_name(st->readers[i]); - strbuf_reset(&filename); + reftable_buf_reset(&filename); if (names && !has_name(names, name)) { stack_filename(&filename, st, name); } @@ -222,7 +222,7 @@ void reftable_stack_destroy(struct reftable_stack *st) unlink(filename.buf); } } - strbuf_release(&filename); + reftable_buf_release(&filename); st->readers_len = 0; REFTABLE_FREE_AND_NULL(st->readers); } @@ -260,7 +260,7 @@ static int reftable_stack_reload_once(struct reftable_stack *st, size_t reused_len = 0, reused_alloc = 0, names_len; size_t new_readers_len = 0; struct reftable_merged_table *new_merged = NULL; - struct strbuf table_path = STRBUF_INIT; + struct reftable_buf table_path = REFTABLE_BUF_INIT; int err = 0; size_t i; @@ -374,7 +374,7 @@ done: reftable_free(new_readers); reftable_free(reused); reftable_free(cur); - strbuf_release(&table_path); + reftable_buf_release(&table_path); return err; } @@ -623,14 +623,14 @@ int reftable_stack_add(struct reftable_stack *st, return 0; } -static void format_name(struct strbuf *dest, uint64_t min, uint64_t max) +static void format_name(struct reftable_buf *dest, uint64_t min, uint64_t max) { char buf[100]; uint32_t rnd = (uint32_t)git_rand(); snprintf(buf, sizeof(buf), "0x%012" PRIx64 "-0x%012" PRIx64 "-%08x", min, max, rnd); - strbuf_reset(dest); - strbuf_addstr(dest, buf); + reftable_buf_reset(dest); + reftable_buf_addstr(dest, buf); } struct reftable_addition { @@ -648,7 +648,7 @@ static int reftable_stack_init_addition(struct reftable_addition *add, struct reftable_stack *st, unsigned int flags) { - struct strbuf lock_file_name = STRBUF_INIT; + struct reftable_buf lock_file_name = REFTABLE_BUF_INIT; int err; add->stack = st; @@ -690,13 +690,13 @@ static int reftable_stack_init_addition(struct reftable_addition *add, done: if (err) reftable_addition_close(add); - strbuf_release(&lock_file_name); + reftable_buf_release(&lock_file_name); return err; } static void reftable_addition_close(struct reftable_addition *add) { - struct strbuf nm = STRBUF_INIT; + struct reftable_buf nm = REFTABLE_BUF_INIT; size_t i; for (i = 0; i < add->new_tables_len; i++) { @@ -711,7 +711,7 @@ static void reftable_addition_close(struct reftable_addition *add) add->new_tables_cap = 0; rollback_lock_file(&add->tables_list_lock); - strbuf_release(&nm); + reftable_buf_release(&nm); } void reftable_addition_destroy(struct reftable_addition *add) @@ -725,7 +725,7 @@ void reftable_addition_destroy(struct reftable_addition *add) int reftable_addition_commit(struct reftable_addition *add) { - struct strbuf table_list = STRBUF_INIT; + struct reftable_buf table_list = REFTABLE_BUF_INIT; int lock_file_fd = get_lock_file_fd(&add->tables_list_lock); int err = 0; size_t i; @@ -734,16 +734,16 @@ int reftable_addition_commit(struct reftable_addition *add) goto done; for (i = 0; i < add->stack->merged->readers_len; i++) { - strbuf_addstr(&table_list, add->stack->readers[i]->name); - strbuf_addstr(&table_list, "\n"); + reftable_buf_addstr(&table_list, add->stack->readers[i]->name); + reftable_buf_addstr(&table_list, "\n"); } for (i = 0; i < add->new_tables_len; i++) { - strbuf_addstr(&table_list, add->new_tables[i]); - strbuf_addstr(&table_list, "\n"); + reftable_buf_addstr(&table_list, add->new_tables[i]); + reftable_buf_addstr(&table_list, "\n"); } err = write_in_full(lock_file_fd, table_list.buf, table_list.len); - strbuf_release(&table_list); + reftable_buf_release(&table_list); if (err < 0) { err = REFTABLE_IO_ERROR; goto done; @@ -837,19 +837,19 @@ int reftable_addition_add(struct reftable_addition *add, void *arg), void *arg) { - struct strbuf temp_tab_file_name = STRBUF_INIT; - struct strbuf tab_file_name = STRBUF_INIT; - struct strbuf next_name = STRBUF_INIT; + struct reftable_buf temp_tab_file_name = REFTABLE_BUF_INIT; + struct reftable_buf tab_file_name = REFTABLE_BUF_INIT; + struct reftable_buf next_name = REFTABLE_BUF_INIT; struct reftable_writer *wr = NULL; struct tempfile *tab_file = NULL; int err = 0; int tab_fd; - strbuf_reset(&next_name); + reftable_buf_reset(&next_name); format_name(&next_name, add->next_update_index, add->next_update_index); stack_filename(&temp_tab_file_name, add->stack, next_name.buf); - strbuf_addstr(&temp_tab_file_name, ".temp.XXXXXX"); + reftable_buf_addstr(&temp_tab_file_name, ".temp.XXXXXX"); tab_file = mks_tempfile(temp_tab_file_name.buf); if (!tab_file) { @@ -894,7 +894,7 @@ int reftable_addition_add(struct reftable_addition *add, } format_name(&next_name, wr->min_update_index, wr->max_update_index); - strbuf_addstr(&next_name, ".ref"); + reftable_buf_addstr(&next_name, ".ref"); stack_filename(&tab_file_name, add->stack, next_name.buf); /* @@ -913,13 +913,13 @@ int reftable_addition_add(struct reftable_addition *add, err = REFTABLE_OUT_OF_MEMORY_ERROR; goto done; } - add->new_tables[add->new_tables_len++] = strbuf_detach(&next_name, NULL); + add->new_tables[add->new_tables_len++] = reftable_buf_detach(&next_name); done: delete_tempfile(&tab_file); - strbuf_release(&temp_tab_file_name); - strbuf_release(&tab_file_name); - strbuf_release(&next_name); + reftable_buf_release(&temp_tab_file_name); + reftable_buf_release(&tab_file_name); + reftable_buf_release(&next_name); reftable_writer_free(wr); return err; } @@ -938,8 +938,8 @@ static int stack_compact_locked(struct reftable_stack *st, struct reftable_log_expiry_config *config, struct tempfile **tab_file_out) { - struct strbuf next_name = STRBUF_INIT; - struct strbuf tab_file_path = STRBUF_INIT; + struct reftable_buf next_name = REFTABLE_BUF_INIT; + struct reftable_buf tab_file_path = REFTABLE_BUF_INIT; struct reftable_writer *wr = NULL; struct tempfile *tab_file; int tab_fd, err = 0; @@ -948,7 +948,7 @@ static int stack_compact_locked(struct reftable_stack *st, reftable_reader_min_update_index(st->readers[first]), reftable_reader_max_update_index(st->readers[last])); stack_filename(&tab_file_path, st, next_name.buf); - strbuf_addstr(&tab_file_path, ".temp.XXXXXX"); + reftable_buf_addstr(&tab_file_path, ".temp.XXXXXX"); tab_file = mks_tempfile(tab_file_path.buf); if (!tab_file) { @@ -986,8 +986,8 @@ static int stack_compact_locked(struct reftable_stack *st, done: delete_tempfile(&tab_file); reftable_writer_free(wr); - strbuf_release(&next_name); - strbuf_release(&tab_file_path); + reftable_buf_release(&next_name); + reftable_buf_release(&tab_file_path); return err; } @@ -1111,10 +1111,10 @@ static int stack_compact_range(struct reftable_stack *st, struct reftable_log_expiry_config *expiry, unsigned int flags) { - struct strbuf tables_list_buf = STRBUF_INIT; - struct strbuf new_table_name = STRBUF_INIT; - struct strbuf new_table_path = STRBUF_INIT; - struct strbuf table_name = STRBUF_INIT; + struct reftable_buf tables_list_buf = REFTABLE_BUF_INIT; + struct reftable_buf new_table_name = REFTABLE_BUF_INIT; + struct reftable_buf new_table_path = REFTABLE_BUF_INIT; + struct reftable_buf table_name = REFTABLE_BUF_INIT; struct lock_file tables_list_lock = LOCK_INIT; struct lock_file *table_locks = NULL; struct tempfile *new_table = NULL; @@ -1372,7 +1372,7 @@ static int stack_compact_range(struct reftable_stack *st, if (!is_empty_table) { format_name(&new_table_name, st->readers[first]->min_update_index, st->readers[last]->max_update_index); - strbuf_addstr(&new_table_name, ".ref"); + reftable_buf_addstr(&new_table_name, ".ref"); stack_filename(&new_table_path, st, new_table_name.buf); err = rename_tempfile(&new_table, new_table_path.buf); @@ -1388,16 +1388,16 @@ static int stack_compact_range(struct reftable_stack *st, * simply skip writing it. */ for (i = 0; i < first_to_replace; i++) { - strbuf_addstr(&tables_list_buf, names[i]); - strbuf_addstr(&tables_list_buf, "\n"); + reftable_buf_addstr(&tables_list_buf, names[i]); + reftable_buf_addstr(&tables_list_buf, "\n"); } if (!is_empty_table) { - strbuf_addstr(&tables_list_buf, new_table_name.buf); - strbuf_addstr(&tables_list_buf, "\n"); + reftable_buf_addstr(&tables_list_buf, new_table_name.buf); + reftable_buf_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"); + reftable_buf_addstr(&tables_list_buf, names[i]); + reftable_buf_addstr(&tables_list_buf, "\n"); } err = write_in_full(get_lock_file_fd(&tables_list_lock), @@ -1449,10 +1449,10 @@ done: reftable_free(table_locks); delete_tempfile(&new_table); - strbuf_release(&new_table_name); - strbuf_release(&new_table_path); - strbuf_release(&tables_list_buf); - strbuf_release(&table_name); + reftable_buf_release(&new_table_name); + reftable_buf_release(&new_table_path); + reftable_buf_release(&tables_list_buf); + reftable_buf_release(&table_name); free_names(names); if (err == REFTABLE_LOCK_ERROR) @@ -1666,7 +1666,7 @@ static void remove_maybe_stale_table(struct reftable_stack *st, uint64_t max, uint64_t update_idx = 0; struct reftable_block_source src = { NULL }; struct reftable_reader *rd = NULL; - struct strbuf table_path = STRBUF_INIT; + struct reftable_buf table_path = REFTABLE_BUF_INIT; stack_filename(&table_path, st, name); err = reftable_block_source_from_file(&src, table_path.buf); @@ -1684,7 +1684,7 @@ static void remove_maybe_stale_table(struct reftable_stack *st, uint64_t max, unlink(table_path.buf); } done: - strbuf_release(&table_path); + reftable_buf_release(&table_path); } static int reftable_stack_clean_locked(struct reftable_stack *st) |
