Skip to content

Commit 81a03a3

Browse files
pks-tgitster
authored andcommitted
reftable/reader: separate concerns of table iter and reftable reader
In "reftable/reader.c" we implement two different interfaces: - The reftable reader contains the logic to read reftables. - The table iterator is used to iterate through a single reftable read by the reader. The way those two types are used in the code is somewhat confusing though because seeking inside a table is implemented as if it was part of the reftable reader, even though it is ultimately more of a detail implemented by the table iterator. Make the boundary between those two types clearer by renaming functions that seek records in a table such that they clearly belong to the table iterator's logic. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dfdd145 commit 81a03a3

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

reftable/reader.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,8 @@ static void iterator_from_table_iter(struct reftable_iterator *it,
386386
it->ops = &table_iter_vtable;
387387
}
388388

389-
static int reader_table_iter_at(struct reftable_reader *r,
390-
struct table_iter *ti, uint64_t off,
391-
uint8_t typ)
389+
static int table_iter_seek_to(struct table_iter *ti, struct reftable_reader *r,
390+
uint64_t off, uint8_t typ)
392391
{
393392
int err;
394393

@@ -403,8 +402,8 @@ static int reader_table_iter_at(struct reftable_reader *r,
403402
return 0;
404403
}
405404

406-
static int reader_start(struct reftable_reader *r, struct table_iter *ti,
407-
uint8_t typ, int index)
405+
static int table_iter_seek_start(struct table_iter *ti, struct reftable_reader *r,
406+
uint8_t typ, int index)
408407
{
409408
struct reftable_reader_offsets *offs = reader_offsets_for(r, typ);
410409
uint64_t off = offs->offset;
@@ -416,11 +415,11 @@ static int reader_start(struct reftable_reader *r, struct table_iter *ti,
416415
typ = BLOCK_TYPE_INDEX;
417416
}
418417

419-
return reader_table_iter_at(r, ti, off, typ);
418+
return table_iter_seek_to(ti, r, off, typ);
420419
}
421420

422-
static int reader_seek_linear(struct table_iter *ti,
423-
struct reftable_record *want)
421+
static int table_iter_seek_linear(struct table_iter *ti,
422+
struct reftable_record *want)
424423
{
425424
struct strbuf want_key = STRBUF_INIT;
426425
struct strbuf got_key = STRBUF_INIT;
@@ -499,9 +498,8 @@ static int reader_seek_linear(struct table_iter *ti,
499498
return err;
500499
}
501500

502-
static int reader_seek_indexed(struct table_iter *ti,
503-
struct reftable_reader *r,
504-
struct reftable_record *rec)
501+
static int table_iter_seek_indexed(struct table_iter *ti,
502+
struct reftable_record *rec)
505503
{
506504
struct reftable_record want_index = {
507505
.type = BLOCK_TYPE_INDEX, .u.idx = { .last_key = STRBUF_INIT }
@@ -520,7 +518,7 @@ static int reader_seek_indexed(struct table_iter *ti,
520518
* highest layer that identifies the relevant index block as well as
521519
* the record inside that block that corresponds to our wanted key.
522520
*/
523-
err = reader_seek_linear(ti, &want_index);
521+
err = table_iter_seek_linear(ti, &want_index);
524522
if (err < 0)
525523
goto done;
526524

@@ -550,7 +548,7 @@ static int reader_seek_indexed(struct table_iter *ti,
550548
if (err != 0)
551549
goto done;
552550

553-
err = reader_table_iter_at(r, ti, index_result.u.idx.offset, 0);
551+
err = table_iter_seek_to(ti, ti->r, index_result.u.idx.offset, 0);
554552
if (err != 0)
555553
goto done;
556554

@@ -585,14 +583,14 @@ static int reader_seek_internal(struct reftable_reader *r,
585583
struct table_iter ti = TABLE_ITER_INIT, *p;
586584
int err;
587585

588-
err = reader_start(r, &ti, reftable_record_type(rec), !!idx);
586+
err = table_iter_seek_start(&ti, r, reftable_record_type(rec), !!idx);
589587
if (err < 0)
590588
goto out;
591589

592590
if (idx)
593-
err = reader_seek_indexed(&ti, r, rec);
591+
err = table_iter_seek_indexed(&ti, rec);
594592
else
595-
err = reader_seek_linear(&ti, rec);
593+
err = table_iter_seek_linear(&ti, rec);
596594
if (err)
597595
goto out;
598596

@@ -742,7 +740,7 @@ static int reftable_reader_refs_for_unindexed(struct reftable_reader *r,
742740
int err;
743741

744742
*ti = ti_empty;
745-
err = reader_start(r, ti, BLOCK_TYPE_REF, 0);
743+
err = table_iter_seek_start(ti, r, BLOCK_TYPE_REF, 0);
746744
if (err < 0) {
747745
reftable_free(ti);
748746
return err;

0 commit comments

Comments
 (0)