mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
reftable/block: handle allocation failures
Handle allocation failures in `block_writer_init()` and `block_reader_init()`. This requires us to bubble up error codes into `writer_reinit_block_writer()`. Adapt call sites accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
cd6a47167e
commit
2d5dbb37b2
@@ -102,19 +102,24 @@ static int writer_write_header(struct reftable_writer *w, uint8_t *dest)
|
||||
return header_size(writer_version(w));
|
||||
}
|
||||
|
||||
static void writer_reinit_block_writer(struct reftable_writer *w, uint8_t typ)
|
||||
static int writer_reinit_block_writer(struct reftable_writer *w, uint8_t typ)
|
||||
{
|
||||
int block_start = 0;
|
||||
if (w->next == 0) {
|
||||
int block_start = 0, ret;
|
||||
|
||||
if (w->next == 0)
|
||||
block_start = header_size(writer_version(w));
|
||||
}
|
||||
|
||||
strbuf_reset(&w->last_key);
|
||||
block_writer_init(&w->block_writer_data, typ, w->block,
|
||||
w->opts.block_size, block_start,
|
||||
hash_size(w->opts.hash_id));
|
||||
ret = block_writer_init(&w->block_writer_data, typ, w->block,
|
||||
w->opts.block_size, block_start,
|
||||
hash_size(w->opts.hash_id));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
w->block_writer = &w->block_writer_data;
|
||||
w->block_writer->restart_interval = w->opts.restart_interval;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reftable_writer_new(struct reftable_writer **out,
|
||||
@@ -247,8 +252,11 @@ static int writer_add_record(struct reftable_writer *w,
|
||||
|
||||
strbuf_reset(&w->last_key);
|
||||
strbuf_addbuf(&w->last_key, &key);
|
||||
if (!w->block_writer)
|
||||
writer_reinit_block_writer(w, reftable_record_type(rec));
|
||||
if (!w->block_writer) {
|
||||
err = writer_reinit_block_writer(w, reftable_record_type(rec));
|
||||
if (err < 0)
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (block_writer_type(w->block_writer) != reftable_record_type(rec))
|
||||
BUG("record of type %d added to writer of type %d",
|
||||
@@ -271,7 +279,9 @@ static int writer_add_record(struct reftable_writer *w,
|
||||
err = writer_flush_block(w);
|
||||
if (err < 0)
|
||||
goto done;
|
||||
writer_reinit_block_writer(w, reftable_record_type(rec));
|
||||
err = writer_reinit_block_writer(w, reftable_record_type(rec));
|
||||
if (err < 0)
|
||||
goto done;
|
||||
|
||||
/*
|
||||
* Try to add the record to the writer again. If this still fails then
|
||||
@@ -461,7 +471,9 @@ static int writer_finish_section(struct reftable_writer *w)
|
||||
|
||||
max_level++;
|
||||
index_start = w->next;
|
||||
writer_reinit_block_writer(w, BLOCK_TYPE_INDEX);
|
||||
err = writer_reinit_block_writer(w, BLOCK_TYPE_INDEX);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
idx = w->index;
|
||||
idx_len = w->index_len;
|
||||
@@ -555,7 +567,10 @@ static void write_object_record(void *void_arg, void *key)
|
||||
if (arg->err < 0)
|
||||
goto done;
|
||||
|
||||
writer_reinit_block_writer(arg->w, BLOCK_TYPE_OBJ);
|
||||
arg->err = writer_reinit_block_writer(arg->w, BLOCK_TYPE_OBJ);
|
||||
if (arg->err < 0)
|
||||
goto done;
|
||||
|
||||
arg->err = block_writer_add(arg->w->block_writer, &rec);
|
||||
if (arg->err == 0)
|
||||
goto done;
|
||||
@@ -584,16 +599,18 @@ static int writer_dump_object_index(struct reftable_writer *w)
|
||||
struct common_prefix_arg common = {
|
||||
.max = 1, /* obj_id_len should be >= 2. */
|
||||
};
|
||||
if (w->obj_index_tree) {
|
||||
int err;
|
||||
|
||||
if (w->obj_index_tree)
|
||||
infix_walk(w->obj_index_tree, &update_common, &common);
|
||||
}
|
||||
w->stats.object_id_len = common.max + 1;
|
||||
|
||||
writer_reinit_block_writer(w, BLOCK_TYPE_OBJ);
|
||||
err = writer_reinit_block_writer(w, BLOCK_TYPE_OBJ);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (w->obj_index_tree) {
|
||||
if (w->obj_index_tree)
|
||||
infix_walk(w->obj_index_tree, &write_object_record, &closure);
|
||||
}
|
||||
|
||||
if (closure.err < 0)
|
||||
return closure.err;
|
||||
|
||||
Reference in New Issue
Block a user