aboutsummaryrefslogtreecommitdiffstats
path: root/reftable/block.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-04-08 11:43:12 -0700
committerJunio C Hamano <gitster@pobox.com>2025-04-08 11:43:12 -0700
commita7652bf99c654909d98f9b4d40b090357aede779 (patch)
tree75c27e46b7d357b42bfb910b1332e1d1e929da7f /reftable/block.c
parentb97b360c514acd0f5a148524a85bcdb583dbe914 (diff)
parent0e1b9c5eed8bfc091570cc93bd15d3c235d15971 (diff)
downloadgit-a7652bf99c654909d98f9b4d40b090357aede779.tar.gz
Merge branch 'ms/reftable-block-writer-errors'
Give more meaningful error return values from block writer layer of the reftable ref-API backend. * ms/reftable-block-writer-errors: reftable: adapt write_object_record() to propagate block_writer_add() errors reftable: adapt writer_add_record() to propagate block_writer_add() errors reftable: propagate specific error codes in block_writer_add()
Diffstat (limited to 'reftable/block.c')
-rw-r--r--reftable/block.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/reftable/block.c b/reftable/block.c
index b14a8f1259..0b8ebc3aa5 100644
--- a/reftable/block.c
+++ b/reftable/block.c
@@ -49,7 +49,7 @@ static int block_writer_register_restart(struct block_writer *w, int n,
if (is_restart)
rlen++;
if (2 + 3 * rlen + n > w->block_size - w->next)
- return -1;
+ return REFTABLE_ENTRY_TOO_BIG_ERROR;
if (is_restart) {
REFTABLE_ALLOC_GROW_OR_NULL(w->restarts, w->restart_len + 1,
w->restart_cap);
@@ -97,9 +97,10 @@ uint8_t block_writer_type(struct block_writer *bw)
return bw->block[bw->header_off];
}
-/* Adds the reftable_record to the block. Returns -1 if it does not fit, 0 on
- success. Returns REFTABLE_API_ERROR if attempting to write a record with
- empty key. */
+/*
+ * Adds the reftable_record to the block. Returns 0 on success and
+ * appropriate error codes on failure.
+ */
int block_writer_add(struct block_writer *w, struct reftable_record *rec)
{
struct reftable_buf empty = REFTABLE_BUF_INIT;
@@ -126,14 +127,14 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec)
n = reftable_encode_key(&is_restart, out, last, w->scratch,
reftable_record_val_type(rec));
if (n < 0) {
- err = -1;
+ err = n;
goto done;
}
string_view_consume(&out, n);
n = reftable_record_encode(rec, out, w->hash_size);
if (n < 0) {
- err = -1;
+ err = n;
goto done;
}
string_view_consume(&out, n);