diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-10-17 06:53:56 +0200 |
---|---|---|
committer | Taylor Blau <me@ttaylorr.com> | 2024-10-17 22:59:56 +0200 |
commit | be4c070a3c9e7c9d6836c724929ff8a365361e1a (patch) | |
tree | 03cec9016c899456a020c06e98239963a2958238 /reftable | |
parent | reftable/basics: provide new `reftable_buf` interface (diff) | |
download | git-be4c070a3c9e7c9d6836c724929ff8a365361e1a.tar.xz git-be4c070a3c9e7c9d6836c724929ff8a365361e1a.zip |
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 'reftable')
-rw-r--r-- | reftable/basics.c | 2 | ||||
-rw-r--r-- | reftable/basics.h | 7 | ||||
-rw-r--r-- | reftable/block.c | 34 | ||||
-rw-r--r-- | reftable/block.h | 14 | ||||
-rw-r--r-- | reftable/blocksource.c | 6 | ||||
-rw-r--r-- | reftable/blocksource.h | 3 | ||||
-rw-r--r-- | reftable/iter.c | 6 | ||||
-rw-r--r-- | reftable/iter.h | 8 | ||||
-rw-r--r-- | reftable/reader.c | 16 | ||||
-rw-r--r-- | reftable/record.c | 80 | ||||
-rw-r--r-- | reftable/record.h | 21 | ||||
-rw-r--r-- | reftable/stack.c | 120 | ||||
-rw-r--r-- | reftable/system.h | 1 | ||||
-rw-r--r-- | reftable/writer.c | 66 | ||||
-rw-r--r-- | reftable/writer.h | 2 |
15 files changed, 194 insertions, 192 deletions
diff --git a/reftable/basics.c b/reftable/basics.c index 65ad761da0..bc4fcc9144 100644 --- a/reftable/basics.c +++ b/reftable/basics.c @@ -260,7 +260,7 @@ int names_equal(const char **a, const char **b) return a[i] == b[i]; } -int common_prefix_size(struct strbuf *a, struct strbuf *b) +int common_prefix_size(struct reftable_buf *a, struct reftable_buf *b) { int p = 0; for (; p < a->len && p < b->len; p++) { diff --git a/reftable/basics.h b/reftable/basics.h index bd33c34dea..7aa46d7c30 100644 --- a/reftable/basics.h +++ b/reftable/basics.h @@ -57,7 +57,9 @@ int reftable_buf_setlen(struct reftable_buf *buf, size_t len); int reftable_buf_cmp(const struct reftable_buf *a, const struct reftable_buf *b); /* - * Add the given bytes to the buffer. Returns 0 on success, + * Append `len` bytes from `data` to the buffer. This function works with + * arbitrary byte sequences, including ones that contain embedded NUL + * characters. As such, we use `void *` as input type. Returns 0 on success, * REFTABLE_OUT_OF_MEMORY_ERROR on allocation failure. */ int reftable_buf_add(struct reftable_buf *buf, const void *data, size_t len); @@ -144,8 +146,7 @@ char *reftable_strdup(const char *str); #endif /* Find the longest shared prefix size of `a` and `b` */ -struct strbuf; -int common_prefix_size(struct strbuf *a, struct strbuf *b); +int common_prefix_size(struct reftable_buf *a, struct reftable_buf *b); int hash_size(uint32_t id); diff --git a/reftable/block.c b/reftable/block.c index cd4180eac7..4f62b823db 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -38,7 +38,7 @@ int footer_size(int version) } static int block_writer_register_restart(struct block_writer *w, int n, - int is_restart, struct strbuf *key) + int is_restart, struct reftable_buf *key) { int rlen = w->restart_len; if (rlen >= MAX_RESTARTS) { @@ -59,8 +59,8 @@ static int block_writer_register_restart(struct block_writer *w, int n, w->next += n; - strbuf_reset(&w->last_key); - strbuf_add(&w->last_key, key->buf, key->len); + reftable_buf_reset(&w->last_key); + reftable_buf_add(&w->last_key, key->buf, key->len); w->entries++; return 0; } @@ -98,8 +98,8 @@ uint8_t block_writer_type(struct block_writer *bw) empty key. */ int block_writer_add(struct block_writer *w, struct reftable_record *rec) { - struct strbuf empty = STRBUF_INIT; - struct strbuf last = + struct reftable_buf empty = REFTABLE_BUF_INIT; + struct reftable_buf last = w->entries % w->restart_interval == 0 ? empty : w->last_key; struct string_view out = { .buf = w->buf + w->next, @@ -109,7 +109,7 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec) struct string_view start = out; int is_restart = 0; - struct strbuf key = STRBUF_INIT; + struct reftable_buf key = REFTABLE_BUF_INIT; int n = 0; int err = -1; @@ -133,7 +133,7 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec) err = block_writer_register_restart(w, start.len - out.len, is_restart, &key); done: - strbuf_release(&key); + reftable_buf_release(&key); return err; } @@ -325,7 +325,7 @@ uint8_t block_reader_type(const struct block_reader *r) return r->block.data[r->header_off]; } -int block_reader_first_key(const struct block_reader *br, struct strbuf *key) +int block_reader_first_key(const struct block_reader *br, struct reftable_buf *key) { int off = br->header_off + 4, n; struct string_view in = { @@ -334,7 +334,7 @@ int block_reader_first_key(const struct block_reader *br, struct strbuf *key) }; uint8_t extra = 0; - strbuf_reset(key); + reftable_buf_reset(key); n = reftable_decode_key(key, &extra, in); if (n < 0) @@ -355,13 +355,13 @@ void block_iter_seek_start(struct block_iter *it, const struct block_reader *br) it->block = br->block.data; it->block_len = br->block_len; it->hash_size = br->hash_size; - strbuf_reset(&it->last_key); + reftable_buf_reset(&it->last_key); it->next_off = br->header_off + 4; } struct restart_needle_less_args { int error; - struct strbuf needle; + struct reftable_buf needle; const struct block_reader *reader; }; @@ -433,7 +433,7 @@ int block_iter_next(struct block_iter *it, struct reftable_record *rec) void block_iter_reset(struct block_iter *it) { - strbuf_reset(&it->last_key); + reftable_buf_reset(&it->last_key); it->next_off = 0; it->block = NULL; it->block_len = 0; @@ -442,12 +442,12 @@ void block_iter_reset(struct block_iter *it) void block_iter_close(struct block_iter *it) { - strbuf_release(&it->last_key); - strbuf_release(&it->scratch); + reftable_buf_release(&it->last_key); + reftable_buf_release(&it->scratch); } int block_iter_seek_key(struct block_iter *it, const struct block_reader *br, - struct strbuf *want) + struct reftable_buf *want) { struct restart_needle_less_args args = { .needle = *want, @@ -537,7 +537,7 @@ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br, * with themselves. */ reftable_record_key(&rec, &it->last_key); - if (strbuf_cmp(&it->last_key, want) >= 0) { + if (reftable_buf_cmp(&it->last_key, want) >= 0) { it->next_off = prev_off; goto done; } @@ -554,7 +554,7 @@ void block_writer_release(struct block_writer *bw) REFTABLE_FREE_AND_NULL(bw->zstream); REFTABLE_FREE_AND_NULL(bw->restarts); REFTABLE_FREE_AND_NULL(bw->compressed); - strbuf_release(&bw->last_key); + reftable_buf_release(&bw->last_key); /* the block is not owned. */ } diff --git a/reftable/block.h b/reftable/block.h index 18d7ea0337..9a3effa513 100644 --- a/reftable/block.h +++ b/reftable/block.h @@ -38,7 +38,7 @@ struct block_writer { uint32_t restart_len; uint32_t restart_cap; - struct strbuf last_key; + struct reftable_buf last_key; int entries; }; @@ -98,7 +98,7 @@ void block_reader_release(struct block_reader *br); uint8_t block_reader_type(const struct block_reader *r); /* Decodes the first key in the block */ -int block_reader_first_key(const struct block_reader *br, struct strbuf *key); +int block_reader_first_key(const struct block_reader *br, struct reftable_buf *key); /* Iterate over entries in a block */ struct block_iter { @@ -109,13 +109,13 @@ struct block_iter { int hash_size; /* key for last entry we read. */ - struct strbuf last_key; - struct strbuf scratch; + struct reftable_buf last_key; + struct reftable_buf scratch; }; #define BLOCK_ITER_INIT { \ - .last_key = STRBUF_INIT, \ - .scratch = STRBUF_INIT, \ + .last_key = REFTABLE_BUF_INIT, \ + .scratch = REFTABLE_BUF_INIT, \ } /* Position `it` at start of the block */ @@ -123,7 +123,7 @@ void block_iter_seek_start(struct block_iter *it, const struct block_reader *br) /* Position `it` to the `want` key in the block */ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br, - struct strbuf *want); + struct reftable_buf *want); /* return < 0 for error, 0 for OK, > 0 for EOF. */ int block_iter_next(struct block_iter *it, struct reftable_record *rec); diff --git a/reftable/blocksource.c b/reftable/blocksource.c index a2a6a196d5..d6242d6790 100644 --- a/reftable/blocksource.c +++ b/reftable/blocksource.c @@ -27,7 +27,7 @@ static void strbuf_close(void *b UNUSED) static int strbuf_read_block(void *v, struct reftable_block *dest, uint64_t off, uint32_t size) { - struct strbuf *b = v; + struct reftable_buf *b = v; assert(off + size <= b->len); REFTABLE_CALLOC_ARRAY(dest->data, size); if (!dest->data) @@ -39,7 +39,7 @@ static int strbuf_read_block(void *v, struct reftable_block *dest, uint64_t off, static uint64_t strbuf_size(void *b) { - return ((struct strbuf *)b)->len; + return ((struct reftable_buf *)b)->len; } static struct reftable_block_source_vtable strbuf_vtable = { @@ -50,7 +50,7 @@ static struct reftable_block_source_vtable strbuf_vtable = { }; void block_source_from_strbuf(struct reftable_block_source *bs, - struct strbuf *buf) + struct reftable_buf *buf) { assert(!bs->ops); bs->ops = &strbuf_vtable; diff --git a/reftable/blocksource.h b/reftable/blocksource.h index 659a27b406..ee3647c653 100644 --- a/reftable/blocksource.h +++ b/reftable/blocksource.h @@ -12,9 +12,10 @@ https://developers.google.com/open-source/licenses/bsd #include "system.h" struct reftable_block_source; +struct reftable_buf; /* Create an in-memory block source for reading reftables */ void block_source_from_strbuf(struct reftable_block_source *bs, - struct strbuf *buf); + struct reftable_buf *buf); #endif diff --git a/reftable/iter.c b/reftable/iter.c index d926db653b..6c193fd31a 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -55,7 +55,7 @@ void iterator_set_empty(struct reftable_iterator *it) static void filtering_ref_iterator_close(void *iter_arg) { struct filtering_ref_iterator *fri = iter_arg; - strbuf_release(&fri->oid); + reftable_buf_release(&fri->oid); reftable_iterator_destroy(&fri->it); } @@ -115,7 +115,7 @@ static void indexed_table_ref_iter_close(void *p) block_iter_close(&it->cur); reftable_block_done(&it->block_reader.block); reftable_free(it->offsets); - strbuf_release(&it->oid); + reftable_buf_release(&it->oid); } static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it) @@ -197,7 +197,7 @@ int indexed_table_ref_iter_new(struct indexed_table_ref_iter **dest, *itr = empty; itr->r = r; - strbuf_add(&itr->oid, oid, oid_len); + reftable_buf_add(&itr->oid, oid, oid_len); itr->offsets = offsets; itr->offset_len = offset_len; diff --git a/reftable/iter.h b/reftable/iter.h index b3225bc7ad..40f98893b8 100644 --- a/reftable/iter.h +++ b/reftable/iter.h @@ -44,12 +44,12 @@ void iterator_set_empty(struct reftable_iterator *it); /* iterator that produces only ref records that point to `oid` */ struct filtering_ref_iterator { - struct strbuf oid; + struct reftable_buf oid; struct reftable_iterator it; }; #define FILTERING_REF_ITERATOR_INIT \ { \ - .oid = STRBUF_INIT \ + .oid = REFTABLE_BUF_INIT \ } void iterator_from_filtering_ref_iterator(struct reftable_iterator *, @@ -60,7 +60,7 @@ void iterator_from_filtering_ref_iterator(struct reftable_iterator *, */ struct indexed_table_ref_iter { struct reftable_reader *r; - struct strbuf oid; + struct reftable_buf oid; /* mutable */ uint64_t *offsets; @@ -75,7 +75,7 @@ struct indexed_table_ref_iter { #define INDEXED_TABLE_REF_ITER_INIT { \ .cur = BLOCK_ITER_INIT, \ - .oid = STRBUF_INIT, \ + .oid = REFTABLE_BUF_INIT, \ } void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it, diff --git a/reftable/reader.c b/reftable/reader.c index 8d37253922..388f8bf6d7 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -350,8 +350,8 @@ static int table_iter_seek_start(struct table_iter *ti, uint8_t typ, int index) static int table_iter_seek_linear(struct table_iter *ti, struct reftable_record *want) { - struct strbuf want_key = STRBUF_INIT; - struct strbuf got_key = STRBUF_INIT; + struct reftable_buf want_key = REFTABLE_BUF_INIT; + struct reftable_buf got_key = REFTABLE_BUF_INIT; struct reftable_record rec; int err; @@ -401,7 +401,7 @@ static int table_iter_seek_linear(struct table_iter *ti, if (err < 0) goto done; - if (strbuf_cmp(&got_key, &want_key) > 0) { + if (reftable_buf_cmp(&got_key, &want_key) > 0) { table_iter_block_done(&next); break; } @@ -422,8 +422,8 @@ static int table_iter_seek_linear(struct table_iter *ti, done: reftable_record_release(&rec); - strbuf_release(&want_key); - strbuf_release(&got_key); + reftable_buf_release(&want_key); + reftable_buf_release(&got_key); return err; } @@ -431,11 +431,11 @@ static int table_iter_seek_indexed(struct table_iter *ti, struct reftable_record *rec) { struct reftable_record want_index = { - .type = BLOCK_TYPE_INDEX, .u.idx = { .last_key = STRBUF_INIT } + .type = BLOCK_TYPE_INDEX, .u.idx = { .last_key = REFTABLE_BUF_INIT } }; struct reftable_record index_result = { .type = BLOCK_TYPE_INDEX, - .u.idx = { .last_key = STRBUF_INIT }, + .u.idx = { .last_key = REFTABLE_BUF_INIT }, }; int err; @@ -765,7 +765,7 @@ static int reftable_reader_refs_for_unindexed(struct reftable_reader *r, } *filter = empty; - strbuf_add(&filter->oid, oid, oid_len); + reftable_buf_add(&filter->oid, oid, oid_len); iterator_from_table_iter(&filter->it, ti); iterator_from_filtering_ref_iterator(it, filter); diff --git a/reftable/record.c b/reftable/record.c index 87157f2c38..0182c97343 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -98,7 +98,7 @@ const unsigned char *reftable_ref_record_val2(const struct reftable_ref_record * } } -static int decode_string(struct strbuf *dest, struct string_view in) +static int decode_string(struct reftable_buf *dest, struct string_view in) { int start_len = in.len; uint64_t tsize = 0; @@ -109,8 +109,8 @@ static int decode_string(struct strbuf *dest, struct string_view in) if (in.len < tsize) return -1; - strbuf_reset(dest); - strbuf_add(dest, in.buf, tsize); + reftable_buf_reset(dest); + reftable_buf_add(dest, in.buf, tsize); string_view_consume(&in, tsize); return start_len - in.len; @@ -133,7 +133,7 @@ static int encode_string(const char *str, struct string_view s) } int reftable_encode_key(int *restart, struct string_view dest, - struct strbuf prev_key, struct strbuf key, + struct reftable_buf prev_key, struct reftable_buf key, uint8_t extra) { struct string_view start = dest; @@ -183,7 +183,7 @@ int reftable_decode_keylen(struct string_view in, return start_len - in.len; } -int reftable_decode_key(struct strbuf *last_key, uint8_t *extra, +int reftable_decode_key(struct reftable_buf *last_key, uint8_t *extra, struct string_view in) { int start_len = in.len; @@ -200,19 +200,19 @@ int reftable_decode_key(struct strbuf *last_key, uint8_t *extra, prefix_len > last_key->len) return -1; - strbuf_setlen(last_key, prefix_len); - strbuf_add(last_key, in.buf, suffix_len); + reftable_buf_setlen(last_key, prefix_len); + reftable_buf_add(last_key, in.buf, suffix_len); string_view_consume(&in, suffix_len); return start_len - in.len; } -static void reftable_ref_record_key(const void *r, struct strbuf *dest) +static void reftable_ref_record_key(const void *r, struct reftable_buf *dest) { const struct reftable_ref_record *rec = (const struct reftable_ref_record *)r; - strbuf_reset(dest); - strbuf_addstr(dest, rec->refname); + reftable_buf_reset(dest); + reftable_buf_addstr(dest, rec->refname); } static int reftable_ref_record_copy_from(void *rec, const void *src_rec, @@ -350,9 +350,9 @@ static int reftable_ref_record_encode(const void *rec, struct string_view s, return start.len - s.len; } -static int reftable_ref_record_decode(void *rec, struct strbuf key, +static int reftable_ref_record_decode(void *rec, struct reftable_buf key, uint8_t val_type, struct string_view in, - int hash_size, struct strbuf *scratch) + int hash_size, struct reftable_buf *scratch) { struct reftable_ref_record *r = rec; struct string_view start = in; @@ -415,7 +415,7 @@ static int reftable_ref_record_decode(void *rec, struct strbuf key, goto done; } string_view_consume(&in, n); - r->value.symref = strbuf_detach(scratch, NULL); + r->value.symref = reftable_buf_detach(scratch); } break; case REFTABLE_REF_DELETION: @@ -465,12 +465,12 @@ static struct reftable_record_vtable reftable_ref_record_vtable = { .cmp = &reftable_ref_record_cmp_void, }; -static void reftable_obj_record_key(const void *r, struct strbuf *dest) +static void reftable_obj_record_key(const void *r, struct reftable_buf *dest) { const struct reftable_obj_record *rec = (const struct reftable_obj_record *)r; - strbuf_reset(dest); - strbuf_add(dest, rec->hash_prefix, rec->hash_prefix_len); + reftable_buf_reset(dest); + reftable_buf_add(dest, rec->hash_prefix, rec->hash_prefix_len); } static void reftable_obj_record_release(void *rec) @@ -547,10 +547,10 @@ static int reftable_obj_record_encode(const void *rec, struct string_view s, return start.len - s.len; } -static int reftable_obj_record_decode(void *rec, struct strbuf key, +static int reftable_obj_record_decode(void *rec, struct reftable_buf key, uint8_t val_type, struct string_view in, int hash_size UNUSED, - struct strbuf *scratch UNUSED) + struct reftable_buf *scratch UNUSED) { struct string_view start = in; struct reftable_obj_record *r = rec; @@ -664,19 +664,19 @@ static struct reftable_record_vtable reftable_obj_record_vtable = { .cmp = &reftable_obj_record_cmp_void, }; -static void reftable_log_record_key(const void *r, struct strbuf *dest) +static void reftable_log_record_key(const void *r, struct reftable_buf *dest) { const struct reftable_log_record *rec = (const struct reftable_log_record *)r; int len = strlen(rec->refname); uint8_t i64[8]; uint64_t ts = 0; - strbuf_reset(dest); - strbuf_add(dest, (uint8_t *)rec->refname, len + 1); + reftable_buf_reset(dest); + reftable_buf_add(dest, (uint8_t *)rec->refname, len + 1); ts = (~ts) - rec->update_index; put_be64(&i64[0], ts); - strbuf_add(dest, i64, sizeof(i64)); + reftable_buf_add(dest, i64, sizeof(i64)); } static int reftable_log_record_copy_from(void *rec, const void *src_rec, @@ -807,9 +807,9 @@ static int reftable_log_record_encode(const void *rec, struct string_view s, return start.len - s.len; } -static int reftable_log_record_decode(void *rec, struct strbuf key, +static int reftable_log_record_decode(void *rec, struct reftable_buf key, uint8_t val_type, struct string_view in, - int hash_size, struct strbuf *scratch) + int hash_size, struct reftable_buf *scratch) { struct string_view start = in; struct reftable_log_record *r = rec; @@ -1027,11 +1027,11 @@ static struct reftable_record_vtable reftable_log_record_vtable = { .cmp = &reftable_log_record_cmp_void, }; -static void reftable_index_record_key(const void *r, struct strbuf *dest) +static void reftable_index_record_key(const void *r, struct reftable_buf *dest) { const struct reftable_index_record *rec = r; - strbuf_reset(dest); - strbuf_add(dest, rec->last_key.buf, rec->last_key.len); + reftable_buf_reset(dest); + reftable_buf_add(dest, rec->last_key.buf, rec->last_key.len); } static int reftable_index_record_copy_from(void *rec, const void *src_rec, @@ -1040,8 +1040,8 @@ static int reftable_index_record_copy_from(void *rec, const void *src_rec, struct reftable_index_record *dst = rec; const struct reftable_index_record *src = src_rec; - strbuf_reset(&dst->last_key); - strbuf_add(&dst->last_key, src->last_key.buf, src->last_key.len); + reftable_buf_reset(&dst->last_key); + reftable_buf_add(&dst->last_key, src->last_key.buf, src->last_key.len); dst->offset = src->offset; return 0; @@ -1050,7 +1050,7 @@ static int reftable_index_record_copy_from(void *rec, const void *src_rec, static void reftable_index_record_release(void *rec) { struct reftable_index_record *idx = rec; - strbuf_release(&idx->last_key); + reftable_buf_release(&idx->last_key); } static uint8_t reftable_index_record_val_type(const void *rec UNUSED) @@ -1074,18 +1074,18 @@ static int reftable_index_record_encode(const void *rec, struct string_view out, return start.len - out.len; } -static int reftable_index_record_decode(void *rec, struct strbuf key, +static int reftable_index_record_decode(void *rec, struct reftable_buf key, uint8_t val_type UNUSED, struct string_view in, int hash_size UNUSED, - struct strbuf *scratch UNUSED) + struct reftable_buf *scratch UNUSED) { struct string_view start = in; struct reftable_index_record *r = rec; int n = 0; - strbuf_reset(&r->last_key); - strbuf_add(&r->last_key, key.buf, key.len); + reftable_buf_reset(&r->last_key); + reftable_buf_add(&r->last_key, key.buf, key.len); n = get_var_int(&r->offset, &in); if (n < 0) @@ -1101,14 +1101,14 @@ static int reftable_index_record_equal(const void *a, const void *b, struct reftable_index_record *ia = (struct reftable_index_record *) a; struct reftable_index_record *ib = (struct reftable_index_record *) b; - return ia->offset == ib->offset && !strbuf_cmp(&ia->last_key, &ib->last_key); + return ia->offset == ib->offset && !reftable_buf_cmp(&ia->last_key, &ib->last_key); } static int reftable_index_record_cmp(const void *_a, const void *_b) { const struct reftable_index_record *a = _a; const struct reftable_index_record *b = _b; - return strbuf_cmp(&a->last_key, &b->last_key); + return reftable_buf_cmp(&a->last_key, &b->last_key); } static struct reftable_record_vtable reftable_index_record_vtable = { @@ -1124,7 +1124,7 @@ static struct reftable_record_vtable reftable_index_record_vtable = { .cmp = &reftable_index_record_cmp, }; -void reftable_record_key(struct reftable_record *rec, struct strbuf *dest) +void reftable_record_key(struct reftable_record *rec, struct reftable_buf *dest) { reftable_record_vtable(rec)->key(reftable_record_data(rec), dest); } @@ -1151,9 +1151,9 @@ uint8_t reftable_record_val_type(struct reftable_record *rec) return reftable_record_vtable(rec)->val_type(reftable_record_data(rec)); } -int reftable_record_decode(struct reftable_record *rec, struct strbuf key, +int reftable_record_decode(struct reftable_record *rec, struct reftable_buf key, uint8_t extra, struct string_view src, int hash_size, - struct strbuf *scratch) + struct reftable_buf *scratch) { return reftable_record_vtable(rec)->decode(reftable_record_data(rec), key, extra, src, hash_size, @@ -1294,7 +1294,7 @@ void reftable_record_init(struct reftable_record *rec, uint8_t typ) case BLOCK_TYPE_OBJ: return; case BLOCK_TYPE_INDEX: - strbuf_init(&rec->u.idx.last_key, 0); + reftable_buf_init(&rec->u.idx.last_key); return; default: BUG("unhandled record type"); diff --git a/reftable/record.h b/reftable/record.h index 0f53ba5443..271da3bf36 100644 --- a/reftable/record.h +++ b/reftable/record.h @@ -9,6 +9,7 @@ https://developers.google.com/open-source/licenses/bsd #ifndef RECORD_H #define RECORD_H +#include "basics.h" #include "system.h" #include <stdint.h> @@ -38,8 +39,8 @@ int put_var_int(struct string_view *dest, uint64_t val); /* Methods for records. */ struct reftable_record_vtable { - /* encode the key of to a uint8_t strbuf. */ - void (*key)(const void *rec, struct strbuf *dest); + /* encode the key of to a uint8_t reftable_buf. */ + void (*key)(const void *rec, struct reftable_buf *dest); /* The record type of ('r' for ref). */ uint8_t type; @@ -54,9 +55,9 @@ struct reftable_record_vtable { int (*encode)(const void *rec, struct string_view dest, int hash_size); /* decode data from `src` into the record. */ - int (*decode)(void *rec, struct strbuf key, uint8_t extra, + int (*decode)(void *rec, struct reftable_buf key, uint8_t extra, struct string_view src, int hash_size, - struct strbuf *scratch); + struct reftable_buf *scratch); /* deallocate and null the record. */ void (*release)(void *rec); @@ -83,7 +84,7 @@ int reftable_is_block_type(uint8_t typ); /* Encode `key` into `dest`. Sets `is_restart` to indicate a restart. Returns * number of bytes written. */ int reftable_encode_key(int *is_restart, struct string_view dest, - struct strbuf prev_key, struct strbuf key, + struct reftable_buf prev_key, struct reftable_buf key, uint8_t extra); /* Decode a record's key lengths. */ @@ -96,13 +97,13 @@ int reftable_decode_keylen(struct string_view in, * Decode into `last_key` and `extra` from `in`. `last_key` is expected to * contain the decoded key of the preceding record, if any. */ -int reftable_decode_key(struct strbuf *last_key, uint8_t *extra, +int reftable_decode_key(struct reftable_buf *last_key, uint8_t *extra, struct string_view in); /* reftable_index_record are used internally to speed up lookups. */ struct reftable_index_record { uint64_t offset; /* Offset of block */ - struct strbuf last_key; /* Last key of the block. */ + struct reftable_buf last_key; /* Last key of the block. */ }; /* reftable_obj_record stores an object ID => ref mapping. */ @@ -136,15 +137,15 @@ void reftable_record_init(struct reftable_record *rec, uint8_t typ); /* see struct record_vtable */ int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b); int reftable_record_equal(struct reftable_record *a, struct reftable_record *b, int hash_size); -void reftable_record_key(struct reftable_record *rec, struct strbuf *dest); +void reftable_record_key(struct reftable_record *rec, struct reftable_buf *dest); int reftable_record_copy_from(struct reftable_record *rec, struct reftable_record *src, int hash_size); uint8_t reftable_record_val_type(struct reftable_record *rec); int reftable_record_encode(struct reftable_record *rec, struct string_view dest, int hash_size); -int reftable_record_decode(struct reftable_record *rec, struct strbuf key, +int reftable_record_decode(struct reftable_record *rec, struct reftable_buf key, uint8_t extra, struct string_view src, - int hash_size, struct strbuf *scratch); + int hash_size, struct reftable_buf *scratch); int reftable_record_is_deletion(struct reftable_record *rec); static inline uint8_t reftable_record_type(struct reftable_record *rec) 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) diff --git a/reftable/system.h b/reftable/system.h index d0cabd5d17..5ec8583343 100644 --- a/reftable/system.h +++ b/reftable/system.h @@ -13,7 +13,6 @@ https://developers.google.com/open-source/licenses/bsd #include "git-compat-util.h" #include "lockfile.h" -#include "strbuf.h" #include "tempfile.h" #include "hash.h" /* hash ID, sizes.*/ #include "dir.h" /* remove_dir_recursively, for tests.*/ diff --git a/reftable/writer.c b/reftable/writer.c index 031d8149a9..da6941a78a 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -115,7 +115,7 @@ static int writer_reinit_block_writer(struct reftable_writer *w, uint8_t typ) if (w->next == 0) block_start = header_size(writer_version(w)); - strbuf_reset(&w->last_key); + reftable_buf_reset(&w->last_key); ret = block_writer_init(&w->block_writer_data, typ, w->block, w->opts.block_size, block_start, hash_size(w->opts.hash_id)); @@ -146,8 +146,8 @@ int reftable_writer_new(struct reftable_writer **out, if (opts.block_size >= (1 << 24)) BUG("configured block size exceeds 16MB"); - strbuf_init(&wp->block_writer_data.last_key, 0); - strbuf_init(&wp->last_key, 0); + reftable_buf_init(&wp->block_writer_data.last_key); + reftable_buf_init(&wp->last_key); REFTABLE_CALLOC_ARRAY(wp->block, opts.block_size); if (!wp->block) { reftable_free(wp); @@ -179,7 +179,7 @@ static void writer_release(struct reftable_writer *w) block_writer_release(&w->block_writer_data); w->block_writer = NULL; writer_clear_index(w); - strbuf_release(&w->last_key); + reftable_buf_release(&w->last_key); } } @@ -190,7 +190,7 @@ void reftable_writer_free(struct reftable_writer *w) } struct obj_index_tree_node { - struct strbuf hash; + struct reftable_buf hash; uint64_t *offsets; size_t offset_len; size_t offset_cap; @@ -198,16 +198,16 @@ struct obj_index_tree_node { #define OBJ_INDEX_TREE_NODE_INIT \ { \ - .hash = STRBUF_INIT \ + .hash = REFTABLE_BUF_INIT \ } static int obj_index_tree_node_compare(const void *a, const void *b) { - return strbuf_cmp(&((const struct obj_index_tree_node *)a)->hash, + return reftable_buf_cmp(&((const struct obj_index_tree_node *)a)->hash, &((const struct obj_index_tree_node *)b)->hash); } -static int writer_index_hash(struct reftable_writer *w, struct strbuf *hash) +static int writer_index_hash(struct reftable_writer *w, struct reftable_buf *hash) { uint64_t off = w->next; struct obj_index_tree_node want = { .hash = *hash }; @@ -224,8 +224,8 @@ static int writer_index_hash(struct reftable_writer *w, struct strbuf *hash) *key = empty; - strbuf_reset(&key->hash); - strbuf_add(&key->hash, hash->buf, hash->len); + reftable_buf_reset(&key->hash); + reftable_buf_add(&key->hash, hash->buf, hash->len); tree_insert(&w->obj_index_tree, key, &obj_index_tree_node_compare); } else { @@ -246,17 +246,17 @@ static int writer_index_hash(struct reftable_writer *w, struct strbuf *hash) static int writer_add_record(struct reftable_writer *w, struct reftable_record *rec) { - struct strbuf key = STRBUF_INIT; + struct reftable_buf key = REFTABLE_BUF_INIT; int err; reftable_record_key(rec, &key); - if (strbuf_cmp(&w->last_key, &key) >= 0) { + if (reftable_buf_cmp(&w->last_key, &key) >= 0) { err = REFTABLE_API_ERROR; goto done; } - strbuf_reset(&w->last_key); - strbuf_add(&w->last_key, key.buf, key.len); + reftable_buf_reset(&w->last_key); + reftable_buf_add(&w->last_key, key.buf, key.len); if (!w->block_writer) { err = writer_reinit_block_writer(w, reftable_record_type(rec)); if (err < 0) @@ -303,7 +303,7 @@ static int writer_add_record(struct reftable_writer *w, } done: - strbuf_release(&key); + reftable_buf_release(&key); return err; } @@ -316,7 +316,7 @@ int reftable_writer_add_ref(struct reftable_writer *w, .ref = *ref }, }; - struct strbuf buf = STRBUF_INIT; + struct reftable_buf buf = REFTABLE_BUF_INIT; int err; if (!ref->refname || @@ -331,7 +331,7 @@ int reftable_writer_add_ref(struct reftable_writer *w, goto out; if (!w->opts.skip_index_objects && reftable_ref_record_val1(ref)) { - strbuf_add(&buf, (char *)reftable_ref_record_val1(ref), + reftable_buf_add(&buf, (char *)reftable_ref_record_val1(ref), hash_size(w->opts.hash_id)); err = writer_index_hash(w, &buf); @@ -340,8 +340,8 @@ int reftable_writer_add_ref(struct reftable_writer *w, } if (!w->opts.skip_index_objects && reftable_ref_record_val2(ref)) { - strbuf_reset(&buf); - strbuf_add(&buf, reftable_ref_record_val2(ref), + reftable_buf_reset(&buf); + reftable_buf_add(&buf, reftable_ref_record_val2(ref), hash_size(w->opts.hash_id)); err = writer_index_hash(w, &buf); @@ -352,7 +352,7 @@ int reftable_writer_add_ref(struct reftable_writer *w, err = 0; out: - strbuf_release(&buf); + reftable_buf_release(&buf); return err; } @@ -393,7 +393,7 @@ int reftable_writer_add_log(struct reftable_writer *w, struct reftable_log_record *log) { char *input_log_message = NULL; - struct strbuf cleaned_message = STRBUF_INIT; + struct reftable_buf cleaned_message = REFTABLE_BUF_INIT; int err = 0; if (log->value_type == REFTABLE_LOG_DELETION) @@ -404,24 +404,24 @@ int reftable_writer_add_log(struct reftable_writer *w, input_log_message = log->value.update.message; if (!w->opts.exact_log_message && log->value.update.message) { - strbuf_addstr(&cleaned_message, log->value.update.message); + reftable_buf_addstr(&cleaned_message, log->value.update.message); while (cleaned_message.len && cleaned_message.buf[cleaned_message.len - 1] == '\n') - strbuf_setlen(&cleaned_message, + reftable_buf_setlen(&cleaned_message, cleaned_message.len - 1); if (strchr(cleaned_message.buf, '\n')) { /* multiple lines not allowed. */ err = REFTABLE_API_ERROR; goto done; } - strbuf_addstr(&cleaned_message, "\n"); + reftable_buf_addstr(&cleaned_message, "\n"); log->value.update.message = cleaned_message.buf; } err = reftable_writer_add_log_verbatim(w, log); log->value.update.message = input_log_message; done: - strbuf_release(&cleaned_message); + reftable_buf_release(&cleaned_message); return err; } @@ -504,7 +504,7 @@ static int writer_finish_section(struct reftable_writer *w) return err; for (i = 0; i < idx_len; i++) - strbuf_release(&idx[i].last_key); + reftable_buf_release(&idx[i].last_key); reftable_free(idx); } @@ -521,13 +521,13 @@ static int writer_finish_section(struct reftable_writer *w) bstats->max_index_level = max_level; /* Reinit lastKey, as the next section can start with any key. */ - strbuf_reset(&w->last_key); + reftable_buf_reset(&w->last_key); return 0; } struct common_prefix_arg { - struct strbuf *last; + struct reftable_buf *last; int max; }; @@ -594,7 +594,7 @@ static void object_record_free(void *void_arg UNUSED, void *key) struct obj_index_tree_node *entry = key; REFTABLE_FREE_AND_NULL(entry->offsets); - strbuf_release(&entry->hash); + reftable_buf_release(&entry->hash); reftable_free(entry); } @@ -708,7 +708,7 @@ done: static void writer_clear_index(struct reftable_writer *w) { for (size_t i = 0; w->index && i < w->index_len; i++) - strbuf_release(&w->index[i].last_key); + reftable_buf_release(&w->index[i].last_key); REFTABLE_FREE_AND_NULL(w->index); w->index_len = 0; w->index_cap = 0; @@ -717,7 +717,7 @@ static void writer_clear_index(struct reftable_writer *w) static int writer_flush_nonempty_block(struct reftable_writer *w) { struct reftable_index_record index_record = { - .last_key = STRBUF_INIT, + .last_key = REFTABLE_BUF_INIT, }; uint8_t typ = block_writer_type(w->block_writer); struct reftable_block_stats *bstats; @@ -777,8 +777,8 @@ static int writer_flush_nonempty_block(struct reftable_writer *w) return REFTABLE_OUT_OF_MEMORY_ERROR; index_record.offset = w->next; - strbuf_reset(&index_record.last_key); - strbuf_add(&index_record.last_key, w->block_writer->last_key.buf, + reftable_buf_reset(&index_record.last_key); + reftable_buf_add(&index_record.last_key, w->block_writer->last_key.buf, w->block_writer->last_key.len); w->index[w->index_len] = index_record; w->index_len++; diff --git a/reftable/writer.h b/reftable/writer.h index 8d0df9cc52..e8a6fbb785 100644 --- a/reftable/writer.h +++ b/reftable/writer.h @@ -19,7 +19,7 @@ struct reftable_writer { int (*flush)(void *); void *write_arg; int pending_padding; - struct strbuf last_key; + struct reftable_buf last_key; /* offset of next block to write. */ uint64_t next; |