@@ -267,7 +267,7 @@ static void t_reftable_stack_transaction_api(void)
267267
268268 reftable_addition_destroy (add );
269269
270- err = reftable_stack_new_addition (& add , st );
270+ err = reftable_stack_new_addition (& add , st , 0 );
271271 check (!err );
272272
273273 err = reftable_addition_add (add , write_test_ref , & ref );
@@ -288,6 +288,68 @@ static void t_reftable_stack_transaction_api(void)
288288 clear_dir (dir );
289289}
290290
291+ static void t_reftable_stack_transaction_with_reload (void )
292+ {
293+ char * dir = get_tmp_dir (__LINE__ );
294+ struct reftable_stack * st1 = NULL , * st2 = NULL ;
295+ int err ;
296+ struct reftable_addition * add = NULL ;
297+ struct reftable_ref_record refs [2 ] = {
298+ {
299+ .refname = (char * ) "refs/heads/a" ,
300+ .update_index = 1 ,
301+ .value_type = REFTABLE_REF_VAL1 ,
302+ .value .val1 = { '1' },
303+ },
304+ {
305+ .refname = (char * ) "refs/heads/b" ,
306+ .update_index = 2 ,
307+ .value_type = REFTABLE_REF_VAL1 ,
308+ .value .val1 = { '1' },
309+ },
310+ };
311+ struct reftable_ref_record ref = { 0 };
312+
313+ err = reftable_new_stack (& st1 , dir , NULL );
314+ check (!err );
315+ err = reftable_new_stack (& st2 , dir , NULL );
316+ check (!err );
317+
318+ err = reftable_stack_new_addition (& add , st1 , 0 );
319+ check (!err );
320+ err = reftable_addition_add (add , write_test_ref , & refs [0 ]);
321+ check (!err );
322+ err = reftable_addition_commit (add );
323+ check (!err );
324+ reftable_addition_destroy (add );
325+
326+ /*
327+ * The second stack is now outdated, which we should notice. We do not
328+ * create the addition and lock the stack by default, but allow the
329+ * reload to happen when REFTABLE_STACK_NEW_ADDITION_RELOAD is set.
330+ */
331+ err = reftable_stack_new_addition (& add , st2 , 0 );
332+ check_int (err , = = , REFTABLE_OUTDATED_ERROR );
333+ err = reftable_stack_new_addition (& add , st2 , REFTABLE_STACK_NEW_ADDITION_RELOAD );
334+ check (!err );
335+ err = reftable_addition_add (add , write_test_ref , & refs [1 ]);
336+ check (!err );
337+ err = reftable_addition_commit (add );
338+ check (!err );
339+ reftable_addition_destroy (add );
340+
341+ for (size_t i = 0 ; i < ARRAY_SIZE (refs ); i ++ ) {
342+ err = reftable_stack_read_ref (st2 , refs [i ].refname , & ref );
343+ check (!err );
344+ check (reftable_ref_record_equal (& refs [i ], & ref , GIT_SHA1_RAWSZ ));
345+ }
346+
347+ reftable_ref_record_release (& ref );
348+ reftable_stack_destroy (st1 );
349+ reftable_stack_destroy (st2 );
350+ clear_dir (dir );
351+ }
352+
291353static void t_reftable_stack_transaction_api_performs_auto_compaction (void )
292354{
293355 char * dir = get_tmp_dir (__LINE__ );
@@ -318,7 +380,7 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
318380 */
319381 st -> opts .disable_auto_compact = i != n ;
320382
321- err = reftable_stack_new_addition (& add , st );
383+ err = reftable_stack_new_addition (& add , st , 0 );
322384 check (!err );
323385
324386 err = reftable_addition_add (add , write_test_ref , & ref );
@@ -1315,6 +1377,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
13151377 TEST (t_reftable_stack_reload_with_missing_table (), "stack iteration with garbage tables" );
13161378 TEST (t_reftable_stack_tombstone (), "'tombstone' refs in stack" );
13171379 TEST (t_reftable_stack_transaction_api (), "update transaction to stack" );
1380+ TEST (t_reftable_stack_transaction_with_reload (), "transaction with reload" );
13181381 TEST (t_reftable_stack_transaction_api_performs_auto_compaction (), "update transaction triggers auto-compaction" );
13191382 TEST (t_reftable_stack_update_index_check (), "update transactions with equal update indices" );
13201383 TEST (t_reftable_stack_uptodate (), "stack must be reloaded before ref update" );
0 commit comments