@@ -425,7 +425,7 @@ static int reader_seek_linear(struct table_iter *ti,
425
425
struct strbuf want_key = STRBUF_INIT ;
426
426
struct strbuf got_key = STRBUF_INIT ;
427
427
struct reftable_record rec ;
428
- int err = -1 ;
428
+ int err ;
429
429
430
430
reftable_record_init (& rec , reftable_record_type (want ));
431
431
reftable_record_key (want , & want_key );
@@ -499,8 +499,8 @@ static int reader_seek_linear(struct table_iter *ti,
499
499
return err ;
500
500
}
501
501
502
- static int reader_seek_indexed (struct reftable_reader * r ,
503
- struct reftable_iterator * it ,
502
+ static int reader_seek_indexed (struct table_iter * ti ,
503
+ struct reftable_reader * r ,
504
504
struct reftable_record * rec )
505
505
{
506
506
struct reftable_record want_index = {
@@ -510,21 +510,17 @@ static int reader_seek_indexed(struct reftable_reader *r,
510
510
.type = BLOCK_TYPE_INDEX ,
511
511
.u .idx = { .last_key = STRBUF_INIT },
512
512
};
513
- struct table_iter ti = TABLE_ITER_INIT , * malloced ;
514
- int err = 0 ;
513
+ int err ;
515
514
516
515
reftable_record_key (rec , & want_index .u .idx .last_key );
517
- err = reader_start (r , & ti , reftable_record_type (rec ), 1 );
518
- if (err < 0 )
519
- goto done ;
520
516
521
517
/*
522
518
* The index may consist of multiple levels, where each level may have
523
519
* multiple index blocks. We start by doing a linear search in the
524
520
* highest layer that identifies the relevant index block as well as
525
521
* the record inside that block that corresponds to our wanted key.
526
522
*/
527
- err = reader_seek_linear (& ti , & want_index );
523
+ err = reader_seek_linear (ti , & want_index );
528
524
if (err < 0 )
529
525
goto done ;
530
526
@@ -550,36 +546,30 @@ static int reader_seek_indexed(struct reftable_reader *r,
550
546
* all levels of the index only to find out that the key does
551
547
* not exist.
552
548
*/
553
- err = table_iter_next (& ti , & index_result );
549
+ err = table_iter_next (ti , & index_result );
554
550
if (err != 0 )
555
551
goto done ;
556
552
557
- err = reader_table_iter_at (r , & ti , index_result .u .idx .offset , 0 );
553
+ err = reader_table_iter_at (r , ti , index_result .u .idx .offset , 0 );
558
554
if (err != 0 )
559
555
goto done ;
560
556
561
- err = block_iter_seek_key (& ti . bi , & ti . br , & want_index .u .idx .last_key );
557
+ err = block_iter_seek_key (& ti -> bi , & ti -> br , & want_index .u .idx .last_key );
562
558
if (err < 0 )
563
559
goto done ;
564
560
565
- if (ti . typ == reftable_record_type (rec )) {
561
+ if (ti -> typ == reftable_record_type (rec )) {
566
562
err = 0 ;
567
563
break ;
568
564
}
569
565
570
- if (ti . typ != BLOCK_TYPE_INDEX ) {
566
+ if (ti -> typ != BLOCK_TYPE_INDEX ) {
571
567
err = REFTABLE_FORMAT_ERROR ;
572
568
goto done ;
573
569
}
574
570
}
575
571
576
- REFTABLE_ALLOC_ARRAY (malloced , 1 );
577
- * malloced = ti ;
578
- iterator_from_table_iter (it , malloced );
579
-
580
572
done :
581
- if (err )
582
- table_iter_close (& ti );
583
573
reftable_record_release (& want_index );
584
574
reftable_record_release (& index_result );
585
575
return err ;
@@ -595,15 +585,15 @@ static int reader_seek_internal(struct reftable_reader *r,
595
585
struct table_iter ti = TABLE_ITER_INIT , * p ;
596
586
int err ;
597
587
598
- if (idx > 0 )
599
- return reader_seek_indexed (r , it , rec );
600
-
601
- err = reader_start (r , & ti , reftable_record_type (rec ), 0 );
588
+ err = reader_start (r , & ti , reftable_record_type (rec ), !!idx );
602
589
if (err < 0 )
603
590
goto out ;
604
591
605
- err = reader_seek_linear (& ti , rec );
606
- if (err < 0 )
592
+ if (idx )
593
+ err = reader_seek_indexed (& ti , r , rec );
594
+ else
595
+ err = reader_seek_linear (& ti , rec );
596
+ if (err )
607
597
goto out ;
608
598
609
599
REFTABLE_ALLOC_ARRAY (p , 1 );
0 commit comments