@@ -550,6 +550,85 @@ static void t_reftable_stack_add(void)
550
550
clear_dir (dir );
551
551
}
552
552
553
+ static void t_reftable_stack_iterator (void )
554
+ {
555
+ struct reftable_write_options opts = { 0 };
556
+ struct reftable_stack * st = NULL ;
557
+ char * dir = get_tmp_dir (__LINE__ );
558
+ struct reftable_ref_record refs [10 ] = { 0 };
559
+ struct reftable_log_record logs [10 ] = { 0 };
560
+ struct reftable_iterator it = { 0 };
561
+ size_t N = ARRAY_SIZE (refs ), i ;
562
+ int err ;
563
+
564
+ err = reftable_new_stack (& st , dir , & opts );
565
+ check (!err );
566
+
567
+ for (i = 0 ; i < N ; i ++ ) {
568
+ refs [i ].refname = xstrfmt ("branch%02" PRIuMAX , (uintmax_t )i );
569
+ refs [i ].update_index = i + 1 ;
570
+ refs [i ].value_type = REFTABLE_REF_VAL1 ;
571
+ set_test_hash (refs [i ].value .val1 , i );
572
+
573
+ logs [i ].refname = xstrfmt ("branch%02" PRIuMAX , (uintmax_t )i );
574
+ logs [i ].update_index = i + 1 ;
575
+ logs [i ].value_type = REFTABLE_LOG_UPDATE ;
576
+ logs [i ].value .update .email = xstrdup ("johndoe@invalid" );
577
+ logs [i ].value .update .message = xstrdup ("commit\n" );
578
+ set_test_hash (logs [i ].value .update .new_hash , i );
579
+ }
580
+
581
+ for (i = 0 ; i < N ; i ++ ) {
582
+ err = reftable_stack_add (st , write_test_ref , & refs [i ]);
583
+ check (!err );
584
+ }
585
+
586
+ for (i = 0 ; i < N ; i ++ ) {
587
+ struct write_log_arg arg = {
588
+ .log = & logs [i ],
589
+ .update_index = reftable_stack_next_update_index (st ),
590
+ };
591
+ err = reftable_stack_add (st , write_test_log , & arg );
592
+ check (!err );
593
+ }
594
+
595
+ reftable_stack_init_ref_iterator (st , & it );
596
+ reftable_iterator_seek_ref (& it , refs [0 ].refname );
597
+ for (i = 0 ; ; i ++ ) {
598
+ struct reftable_ref_record ref = { 0 };
599
+ err = reftable_iterator_next_ref (& it , & ref );
600
+ if (err > 0 )
601
+ break ;
602
+ check (!err );
603
+ check (reftable_ref_record_equal (& ref , & refs [i ], GIT_SHA1_RAWSZ ));
604
+ reftable_ref_record_release (& ref );
605
+ }
606
+ check_int (i , = = , N );
607
+
608
+ reftable_iterator_destroy (& it );
609
+
610
+ reftable_stack_init_log_iterator (st , & it );
611
+ reftable_iterator_seek_log (& it , logs [0 ].refname );
612
+ for (i = 0 ; ; i ++ ) {
613
+ struct reftable_log_record log = { 0 };
614
+ err = reftable_iterator_next_log (& it , & log );
615
+ if (err > 0 )
616
+ break ;
617
+ check (!err );
618
+ check (reftable_log_record_equal (& log , & logs [i ], GIT_SHA1_RAWSZ ));
619
+ reftable_log_record_release (& log );
620
+ }
621
+ check_int (i , = = , N );
622
+
623
+ reftable_stack_destroy (st );
624
+ reftable_iterator_destroy (& it );
625
+ for (i = 0 ; i < N ; i ++ ) {
626
+ reftable_ref_record_release (& refs [i ]);
627
+ reftable_log_record_release (& logs [i ]);
628
+ }
629
+ clear_dir (dir );
630
+ }
631
+
553
632
static void t_reftable_stack_log_normalize (void )
554
633
{
555
634
int err = 0 ;
@@ -1125,6 +1204,7 @@ int cmd_main(int argc, const char *argv[])
1125
1204
TEST (t_reftable_stack_compaction_concurrent_clean (), "compaction with unclean stack shutdown" );
1126
1205
TEST (t_reftable_stack_compaction_with_locked_tables (), "compaction with locked tables" );
1127
1206
TEST (t_reftable_stack_hash_id (), "read stack with wrong hash ID" );
1207
+ TEST (t_reftable_stack_iterator (), "log and ref iterator for reftable stack" );
1128
1208
TEST (t_reftable_stack_lock_failure (), "stack addition with lockfile failure" );
1129
1209
TEST (t_reftable_stack_log_normalize (), "log messages should be normalized" );
1130
1210
TEST (t_reftable_stack_tombstone (), "'tombstone' refs in stack" );
0 commit comments