Skip to content

Commit

Permalink
Merge branch 'ps/ref-backend-migration-optim' into next
Browse files Browse the repository at this point in the history
Optimize migration procedure between two ref backends.

* ps/ref-backend-migration-optim:
  reftable: rename scratch buffer
  refs: adapt `initial_transaction` flag to be unsigned
  • Loading branch information
gitster committed Nov 26, 2024
2 parents ed3858b + ef46ad0 commit 7bb66a1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ int refs_verify_refname_available(struct ref_store *refs,
const char *refname,
const struct string_list *extras,
const struct string_list *skip,
int initial_transaction,
unsigned int initial_transaction,
struct strbuf *err)
{
const char *slash;
Expand Down
2 changes: 1 addition & 1 deletion refs.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int refs_verify_refname_available(struct ref_store *refs,
const char *refname,
const struct string_list *extras,
const struct string_list *skip,
int initial_transaction,
unsigned int initial_transaction,
struct strbuf *err);

int refs_ref_exists(struct ref_store *refs, const char *refname);
Expand Down
10 changes: 5 additions & 5 deletions reftable/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec)
int n = 0;
int err;

err = reftable_record_key(rec, &w->buf);
err = reftable_record_key(rec, &w->scratch);
if (err < 0)
goto done;

if (!w->buf.len) {
if (!w->scratch.len) {
err = REFTABLE_API_ERROR;
goto done;
}

n = reftable_encode_key(&is_restart, out, last, w->buf,
n = reftable_encode_key(&is_restart, out, last, w->scratch,
reftable_record_val_type(rec));
if (n < 0) {
err = -1;
Expand All @@ -140,7 +140,7 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec)
string_view_consume(&out, n);

err = block_writer_register_restart(w, start.len - out.len, is_restart,
&w->buf);
&w->scratch);
done:
return err;
}
Expand Down Expand Up @@ -565,7 +565,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);
reftable_buf_release(&bw->buf);
reftable_buf_release(&bw->scratch);
reftable_buf_release(&bw->last_key);
/* the block is not owned. */
}
Expand Down
3 changes: 2 additions & 1 deletion reftable/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ struct block_writer {
uint32_t restart_cap;

struct reftable_buf last_key;
struct reftable_buf buf;
/* Scratch buffer used to avoid allocations. */
struct reftable_buf scratch;
int entries;
};

Expand Down
22 changes: 11 additions & 11 deletions reftable/writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int reftable_writer_new(struct reftable_writer **out,

reftable_buf_init(&wp->block_writer_data.last_key);
reftable_buf_init(&wp->last_key);
reftable_buf_init(&wp->buf);
reftable_buf_init(&wp->scratch);
REFTABLE_CALLOC_ARRAY(wp->block, opts.block_size);
if (!wp->block) {
reftable_free(wp);
Expand Down Expand Up @@ -181,7 +181,7 @@ static void writer_release(struct reftable_writer *w)
w->block_writer = NULL;
writer_clear_index(w);
reftable_buf_release(&w->last_key);
reftable_buf_release(&w->buf);
reftable_buf_release(&w->scratch);
}
}

Expand Down Expand Up @@ -253,17 +253,17 @@ static int writer_add_record(struct reftable_writer *w,
{
int err;

err = reftable_record_key(rec, &w->buf);
err = reftable_record_key(rec, &w->scratch);
if (err < 0)
goto done;

if (reftable_buf_cmp(&w->last_key, &w->buf) >= 0) {
if (reftable_buf_cmp(&w->last_key, &w->scratch) >= 0) {
err = REFTABLE_API_ERROR;
goto done;
}

reftable_buf_reset(&w->last_key);
err = reftable_buf_add(&w->last_key, w->buf.buf, w->buf.len);
err = reftable_buf_add(&w->last_key, w->scratch.buf, w->scratch.len);
if (err < 0)
goto done;

Expand Down Expand Up @@ -339,25 +339,25 @@ int reftable_writer_add_ref(struct reftable_writer *w,
goto out;

if (!w->opts.skip_index_objects && reftable_ref_record_val1(ref)) {
reftable_buf_reset(&w->buf);
err = reftable_buf_add(&w->buf, (char *)reftable_ref_record_val1(ref),
reftable_buf_reset(&w->scratch);
err = reftable_buf_add(&w->scratch, (char *)reftable_ref_record_val1(ref),
hash_size(w->opts.hash_id));
if (err < 0)
goto out;

err = writer_index_hash(w, &w->buf);
err = writer_index_hash(w, &w->scratch);
if (err < 0)
goto out;
}

if (!w->opts.skip_index_objects && reftable_ref_record_val2(ref)) {
reftable_buf_reset(&w->buf);
err = reftable_buf_add(&w->buf, reftable_ref_record_val2(ref),
reftable_buf_reset(&w->scratch);
err = reftable_buf_add(&w->scratch, reftable_ref_record_val2(ref),
hash_size(w->opts.hash_id));
if (err < 0)
goto out;

err = writer_index_hash(w, &w->buf);
err = writer_index_hash(w, &w->scratch);
if (err < 0)
goto out;
}
Expand Down
3 changes: 2 additions & 1 deletion reftable/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ struct reftable_writer {
void *write_arg;
int pending_padding;
struct reftable_buf last_key;
struct reftable_buf buf;
/* Scratch buffer used to avoid allocations. */
struct reftable_buf scratch;

/* offset of next block to write. */
uint64_t next;
Expand Down

0 comments on commit 7bb66a1

Please sign in to comment.