271
272
reftable_addition_destroy(add);
273
274
- err = reftable_stack_new_addition(&add, st);
274
+ err = reftable_stack_new_addition(&add, st, 0);
275
check(!err);
276
277
err = reftable_addition_add(add, write_test_ref, &ref);
292
clear_dir(dir);
293
}
294
295
+static void t_reftable_stack_transaction_with_reload(void)
296
+{
297
+ char *dir = get_tmp_dir(__LINE__);
298
+ struct reftable_stack *st1 = NULL, *st2 = NULL;
299
+ int err;
300
+ struct reftable_addition *add = NULL;
301
+ struct reftable_ref_record refs[2] = {
302
+ {
303
+ .refname = (char *) "refs/heads/a",
304
+ .update_index = 1,
305
+ .value_type = REFTABLE_REF_VAL1,
306
+ .value.val1 = { '1' },
307
+ },
308
+ {
309
+ .refname = (char *) "refs/heads/b",
310
+ .update_index = 2,
311
+ .value_type = REFTABLE_REF_VAL1,
312
+ .value.val1 = { '1' },
313
+ },
314
+ };
315
+ struct reftable_ref_record ref = { 0 };
316
+
317
+ err = reftable_new_stack(&st1, dir, NULL);
318
+ check(!err);
319
+ err = reftable_new_stack(&st2, dir, NULL);
320
+ check(!err);
321
+
322
+ err = reftable_stack_new_addition(&add, st1, 0);
323
+ check(!err);
324
+ err = reftable_addition_add(add, write_test_ref, &refs[0]);
325
+ check(!err);
326
+ err = reftable_addition_commit(add);
327
+ check(!err);
328
+ reftable_addition_destroy(add);
329
+
330
+ /*
331
+ * The second stack is now outdated, which we should notice. We do not
332
+ * create the addition and lock the stack by default, but allow the
333
+ * reload to happen when REFTABLE_STACK_NEW_ADDITION_RELOAD is set.
334
+ */
335
+ err = reftable_stack_new_addition(&add, st2, 0);
336
+ check_int(err, ==, REFTABLE_OUTDATED_ERROR);
337
+ err = reftable_stack_new_addition(&add, st2, REFTABLE_STACK_NEW_ADDITION_RELOAD);
338
+ check(!err);
339
+ err = reftable_addition_add(add, write_test_ref, &refs[1]);
340
+ check(!err);
341
+ err = reftable_addition_commit(add);
342
+ check(!err);
343
+ reftable_addition_destroy(add);
344
+
345
+ for (size_t i = 0; i < ARRAY_SIZE(refs); i++) {
346
+ err = reftable_stack_read_ref(st2, refs[i].refname, &ref);
347
+ check(!err);
348
+ check(reftable_ref_record_equal(&refs[i], &ref, GIT_SHA1_RAWSZ));
349
+ }
350
+
351
+ reftable_ref_record_release(&ref);
352
+ reftable_stack_destroy(st1);
353
+ reftable_stack_destroy(st2);
354
+ clear_dir(dir);
355
+}
356
+
357
static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
358
{
359
char *dir = get_tmp_dir(__LINE__);
384
*/
385
st->opts.disable_auto_compact = i != n;
386
325
- err = reftable_stack_new_addition(&add, st);
387
+ err = reftable_stack_new_addition(&add, st, 0);
388
check(!err);
389
390
err = reftable_addition_add(add, write_test_ref, &ref);
1376
TEST(t_reftable_stack_reload_with_missing_table(), "stack iteration with garbage tables");
1377
TEST(t_reftable_stack_tombstone(), "'tombstone' refs in stack");
1378
TEST(t_reftable_stack_transaction_api(), "update transaction to stack");
1379
+ TEST(t_reftable_stack_transaction_with_reload(), "transaction with reload");
1380
TEST(t_reftable_stack_transaction_api_performs_auto_compaction(), "update transaction triggers auto-compaction");
1381
TEST(t_reftable_stack_update_index_check(), "update transactions with equal update indices");
1382
TEST(t_reftable_stack_uptodate(), "stack must be reloaded before ref update");