reftable: split up write options

When initializing the reftable stack the caller may optionally pass some write options. These write options mix up two different concerns though: - Of course, they allow the caller to configure how new reftables are being written. - But they also allow the caller to configure the stack itself, like its hash ID and the `on_reload` callback. This is somewhat awkward, as it doesn't easily give the caller the flexibility to for example write multiple reftables with different options. Furthermore, this requires us to eagerly parse relevant configuration when initializing the reftable backend. Refactor the code by splitting out those options that configure the stack itself. Creating a new stack will thus only require this limited set of options, whereas the caller is expected to pass write options to all functions that end up writing tables. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 25, 2026 at 11:20 UTC 44f46f2be5b6fb47733e495be3de21eeec4c7ede
14 files changed +258 -198
refs/reftable-backend.c
+18 -11
@@ -48,9 +48,9 @@ static void reftable_backend_on_reload(void *payload)
48
49 static int reftable_backend_init(struct reftable_backend *be,
50 const char *path,
51 - const struct reftable_write_options *_opts)
51 + const struct reftable_stack_options *_opts)
52 {
53 - struct reftable_write_options opts = *_opts;
53 + struct reftable_stack_options opts = *_opts;
54 opts.on_reload = reftable_backend_on_reload;
55 opts.on_reload_payload = be;
56 return reftable_new_stack(&be->stack, path, &opts);
@@ -140,6 +140,7 @@ struct reftable_ref_store {
140 * is populated lazily when we try to resolve `worktrees/$worktree` refs.
141 */
142 struct strmap worktree_backends;
143 + struct reftable_stack_options stack_options;
144 struct reftable_write_options write_options;
145
146 unsigned int store_flags;
@@ -190,7 +191,7 @@ static int backend_for_worktree(struct reftable_backend **out,
191
192 CALLOC_ARRAY(*out, 1);
193 store->err = ret = reftable_backend_init(*out, worktree_dir.buf,
193 - &store->write_options);
194 + &store->stack_options);
195 if (ret < 0) {
196 free(*out);
197 goto out;
@@ -404,10 +405,10 @@ static struct ref_store *reftable_be_init(struct repository *repo,
405
406 switch (repo->hash_algo->format_id) {
407 case GIT_SHA1_FORMAT_ID:
407 - refs->write_options.hash_id = REFTABLE_HASH_SHA1;
408 + refs->stack_options.hash_id = REFTABLE_HASH_SHA1;
409 break;
410 case GIT_SHA256_FORMAT_ID:
410 - refs->write_options.hash_id = REFTABLE_HASH_SHA256;
411 + refs->stack_options.hash_id = REFTABLE_HASH_SHA256;
412 break;
413 default:
414 BUG("unknown hash algorithm %d", repo->hash_algo->format_id);
@@ -441,7 +442,7 @@ static struct ref_store *reftable_be_init(struct repository *repo,
442 }
443 strbuf_addstr(&path, "/reftable");
444 refs->err = reftable_backend_init(&refs->main_backend, path.buf,
444 - &refs->write_options);
445 + &refs->stack_options);
446 if (refs->err)
447 goto done;
448
@@ -457,7 +458,7 @@ static struct ref_store *reftable_be_init(struct repository *repo,
458 strbuf_addstr(&refdir, "/reftable");
459
460 refs->err = reftable_backend_init(&refs->worktree_backend, refdir.buf,
460 - &refs->write_options);
461 + &refs->stack_options);
462 if (refs->err)
463 goto done;
464 }
@@ -997,6 +998,7 @@ static int prepare_transaction_update(struct write_transaction_table_arg **out,
998 struct reftable_addition *addition;
999
1000 ret = reftable_stack_new_addition(&addition, be->stack,
1001 + &refs->write_options,
1002 REFTABLE_STACK_NEW_ADDITION_RELOAD);
1003 if (ret) {
1004 if (ret == REFTABLE_LOCK_ERROR)
@@ -1685,9 +1687,9 @@ static int reftable_be_optimize(struct ref_store *ref_store,
1687 stack = refs->main_backend.stack;
1688
1689 if (opts->flags & REFS_OPTIMIZE_AUTO)
1688 - ret = reftable_stack_auto_compact(stack);
1690 + ret = reftable_stack_auto_compact(stack, &refs->write_options);
1691 else
1690 - ret = reftable_stack_compact_all(stack, NULL);
1692 + ret = reftable_stack_compact_all(stack, &refs->write_options, NULL);
1693 if (ret < 0) {
1694 ret = error(_("unable to compact stack: %s"),
1695 reftable_error_str(ret));
@@ -1721,8 +1723,8 @@ static int reftable_be_optimize_required(struct ref_store *ref_store,
1723 if (opts->flags & REFS_OPTIMIZE_AUTO)
1724 use_heuristics = true;
1725
1724 - return reftable_stack_compaction_required(stack, use_heuristics,
1725 - required);
1726 + return reftable_stack_compaction_required(stack, &refs->write_options,
1727 + use_heuristics, required);
1728 }
1729
1730 struct write_create_symref_arg {
@@ -1979,6 +1981,7 @@ static int reftable_be_rename_ref(struct ref_store *ref_store,
1981 if (ret)
1982 goto done;
1983 ret = reftable_stack_add(arg.be->stack, &write_copy_table, &arg,
1984 + &refs->write_options,
1985 REFTABLE_STACK_NEW_ADDITION_RELOAD);
1986
1987 done:
@@ -2009,6 +2012,7 @@ static int reftable_be_copy_ref(struct ref_store *ref_store,
2012 if (ret)
2013 goto done;
2014 ret = reftable_stack_add(arg.be->stack, &write_copy_table, &arg,
2015 + &refs->write_options,
2016 REFTABLE_STACK_NEW_ADDITION_RELOAD);
2017
2018 done:
@@ -2374,6 +2378,7 @@ static int reftable_be_create_reflog(struct ref_store *ref_store,
2378 arg.stack = be->stack;
2379
2380 ret = reftable_stack_add(be->stack, &write_reflog_existence_table, &arg,
2381 + &refs->write_options,
2382 REFTABLE_STACK_NEW_ADDITION_RELOAD);
2383
2384 done:
@@ -2446,6 +2451,7 @@ static int reftable_be_delete_reflog(struct ref_store *ref_store,
2451 arg.stack = be->stack;
2452
2453 ret = reftable_stack_add(be->stack, &write_reflog_delete_table, &arg,
2454 + &refs->write_options,
2455 REFTABLE_STACK_NEW_ADDITION_RELOAD);
2456
2457 assert(ret != REFTABLE_API_ERROR);
@@ -2568,6 +2574,7 @@ static int reftable_be_reflog_expire(struct ref_store *ref_store,
2574 goto done;
2575
2576 ret = reftable_stack_new_addition(&add, be->stack,
2577 + &refs->write_options,
2578 REFTABLE_STACK_NEW_ADDITION_RELOAD);
2579 if (ret < 0)
2580 goto done;
reftable/reftable-stack.h
+27 -3
@@ -26,11 +26,29 @@
26 */
27 struct reftable_stack;
28
29 +/* Options related to opening a stack. */
30 +struct reftable_stack_options {
31 + /*
32 + * 4-byte identifier ("sha1", "s256") of the hash. Defaults to SHA1 if
33 + * unset.
34 + */
35 + enum reftable_hash hash_id;
36 +
37 + /*
38 + * Callback function to execute whenever the stack is being reloaded.
39 + * This can be used e.g. to discard cached information that relies on
40 + * the old stack's data. The payload data will be passed as argument to
41 + * the callback.
42 + */
43 + void (*on_reload)(void *payload);
44 + void *on_reload_payload;
45 +};
46 +
47 /* open a new reftable stack. The tables along with the table list will be
48 * stored in 'dir'. Typically, this should be .git/reftables.
49 */
50 int reftable_new_stack(struct reftable_stack **dest, const char *dir,
33 - const struct reftable_write_options *opts);
51 + const struct reftable_stack_options *opts);
52
53 /* returns the update_index at which a next table should be written. */
54 uint64_t reftable_stack_next_update_index(struct reftable_stack *st);
@@ -52,6 +70,7 @@ enum {
70 */
71 int reftable_stack_new_addition(struct reftable_addition **dest,
72 struct reftable_stack *st,
73 + const struct reftable_write_options *opts,
74 unsigned int flags);
75
76 /* Adds a reftable to transaction. */
@@ -77,7 +96,9 @@ void reftable_addition_destroy(struct reftable_addition *add);
96 int reftable_stack_add(struct reftable_stack *st,
97 int (*write_table)(struct reftable_writer *wr,
98 void *write_arg),
80 - void *write_arg, unsigned flags);
99 + void *write_arg,
100 + const struct reftable_write_options *opts,
101 + unsigned flags);
102
103 struct reftable_iterator;
104
@@ -122,6 +143,7 @@ struct reftable_log_expiry_config {
143 /* compacts all reftables into a giant table. Expire reflog entries if config is
144 * non-NULL */
145 int reftable_stack_compact_all(struct reftable_stack *st,
146 + const struct reftable_write_options *opts,
147 struct reftable_log_expiry_config *config);
148
149 /*
@@ -132,11 +154,13 @@ int reftable_stack_compact_all(struct reftable_stack *st,
154 * compacted to maintain geometric progression.
155 */
156 int reftable_stack_compaction_required(struct reftable_stack *st,
157 + const struct reftable_write_options *opts,
158 bool use_heuristics,
159 bool *required);
160
161 /* heuristically compact unbalanced table stack. */
139 -int reftable_stack_auto_compact(struct reftable_stack *st);
162 +int reftable_stack_auto_compact(struct reftable_stack *st,
163 + const struct reftable_write_options *opts);
164
165 /* delete stale .ref tables. */
166 int reftable_stack_clean(struct reftable_stack *st);
reftable/reftable-writer.h
+2 -15
@@ -28,11 +28,6 @@ struct reftable_write_options {
28 /* how often to write complete keys in each block. */
29 uint16_t restart_interval;
30
31 - /* 4-byte identifier ("sha1", "s256") of the hash.
32 - * Defaults to SHA1 if unset
33 - */
34 - enum reftable_hash hash_id;
35 -
31 /* Default mode for creating files. If unset, use 0666 (+umask) */
32 unsigned int default_permissions;
33
@@ -60,15 +55,6 @@ struct reftable_write_options {
55 * negative value will cause us to block indefinitely.
56 */
57 long lock_timeout_ms;
63 -
64 - /*
65 - * Callback function to execute whenever the stack is being reloaded.
66 - * This can be used e.g. to discard cached information that relies on
67 - * the old stack's data. The payload data will be passed as argument to
68 - * the callback.
69 - */
70 - void (*on_reload)(void *payload);
71 - void *on_reload_payload;
58 };
59
60 /* reftable_block_stats holds statistics for a single block type */
@@ -114,7 +100,8 @@ struct reftable_writer;
100 int reftable_writer_new(struct reftable_writer **out,
101 ssize_t (*writer_func)(void *, const void *, size_t),
102 int (*flush_func)(void *),
117 - void *writer_arg, const struct reftable_write_options *opts);
103 + void *writer_arg, enum reftable_hash hash_id,
104 + const struct reftable_write_options *opts);
105
106 /*
107 * Set the range of update indices for the records we will add. When writing a
reftable/stack.c
+66 -34
@@ -501,10 +501,10 @@ out:
501 }
502
503 int reftable_new_stack(struct reftable_stack **dest, const char *dir,
504 - const struct reftable_write_options *_opts)
504 + const struct reftable_stack_options *_opts)
505 {
506 struct reftable_buf list_file_name = REFTABLE_BUF_INIT;
507 - struct reftable_write_options opts = { 0 };
507 + struct reftable_stack_options opts = { 0 };
508 struct reftable_stack *p;
509 int err;
510
@@ -629,6 +629,7 @@ int reftable_stack_reload(struct reftable_stack *st)
629 struct reftable_addition {
630 struct reftable_flock tables_list_lock;
631 struct reftable_stack *stack;
632 + struct reftable_write_options opts;
633
634 char **new_tables;
635 size_t new_tables_len, new_tables_cap;
@@ -657,6 +658,7 @@ static void reftable_addition_close(struct reftable_addition *add)
658
659 static int reftable_stack_init_addition(struct reftable_addition *add,
660 struct reftable_stack *st,
661 + const struct reftable_write_options *opts,
662 unsigned int flags)
663 {
664 struct reftable_buf lock_file_name = REFTABLE_BUF_INIT;
@@ -664,15 +666,17 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
666
667 memset(add, 0, sizeof(*add));
668 add->stack = st;
669 + if (opts)
670 + add->opts = *opts;
671
672 err = flock_acquire(&add->tables_list_lock, st->list_file,
669 - st->opts.lock_timeout_ms);
673 + add->opts.lock_timeout_ms);
674 if (err < 0)
675 goto done;
676
673 - if (st->opts.default_permissions) {
677 + if (add->opts.default_permissions) {
678 if (chmod(add->tables_list_lock.path,
675 - st->opts.default_permissions) < 0) {
679 + add->opts.default_permissions) < 0) {
680 err = REFTABLE_IO_ERROR;
681 goto done;
682 }
@@ -702,12 +706,14 @@ done:
706 static int stack_try_add(struct reftable_stack *st,
707 int (*write_table)(struct reftable_writer *wr,
708 void *arg),
705 - void *arg, unsigned flags)
709 + void *arg,
710 + const struct reftable_write_options *opts,
711 + unsigned flags)
712 {
713 struct reftable_addition add;
714 int err;
715
710 - err = reftable_stack_init_addition(&add, st, flags);
716 + err = reftable_stack_init_addition(&add, st, opts, flags);
717 if (err < 0)
718 goto done;
719
@@ -723,9 +729,11 @@ done:
729
730 int reftable_stack_add(struct reftable_stack *st,
731 int (*write)(struct reftable_writer *wr, void *arg),
726 - void *arg, unsigned flags)
732 + void *arg,
733 + const struct reftable_write_options *opts,
734 + unsigned flags)
735 {
728 - int err = stack_try_add(st, write, arg, flags);
736 + int err = stack_try_add(st, write, arg, opts, flags);
737 if (err < 0) {
738 if (err == REFTABLE_OUTDATED_ERROR) {
739 /* Ignore error return, we want to propagate
@@ -810,7 +818,7 @@ int reftable_addition_commit(struct reftable_addition *add)
818 if (err)
819 goto done;
820
813 - if (!add->stack->opts.disable_auto_compact) {
821 + if (!add->opts.disable_auto_compact) {
822 /*
823 * Auto-compact the stack to keep the number of tables in
824 * control. It is possible that a concurrent writer is already
@@ -820,7 +828,7 @@ int reftable_addition_commit(struct reftable_addition *add)
828 * concurrent writer, which causes `REFTABLE_OUTDATED_ERROR`.
829 * Both of these errors are benign, so we simply ignore them.
830 */
823 - err = reftable_stack_auto_compact(add->stack);
831 + err = reftable_stack_auto_compact(add->stack, &add->opts);
832 if (err < 0 && err != REFTABLE_LOCK_ERROR &&
833 err != REFTABLE_OUTDATED_ERROR)
834 goto done;
@@ -834,6 +842,7 @@ done:
842
843 int reftable_stack_new_addition(struct reftable_addition **dest,
844 struct reftable_stack *st,
845 + const struct reftable_write_options *opts,
846 unsigned int flags)
847 {
848 int err;
@@ -842,7 +851,7 @@ int reftable_stack_new_addition(struct reftable_addition **dest,
851 if (!*dest)
852 return REFTABLE_OUT_OF_MEMORY_ERROR;
853
845 - err = reftable_stack_init_addition(*dest, st, flags);
854 + err = reftable_stack_init_addition(*dest, st, opts, flags);
855 if (err) {
856 reftable_free(*dest);
857 *dest = NULL;
@@ -862,7 +871,7 @@ int reftable_addition_add(struct reftable_addition *add,
871 struct reftable_writer *wr = NULL;
872 struct reftable_tmpfile tab_file = REFTABLE_TMPFILE_INIT;
873 struct fd_writer writer = {
865 - .opts = &add->stack->opts,
874 + .opts = &add->opts,
875 };
876 int err = 0;
877
@@ -883,9 +892,9 @@ int reftable_addition_add(struct reftable_addition *add,
892 err = tmpfile_from_pattern(&tab_file, temp_tab_file_name.buf);
893 if (err < 0)
894 goto done;
886 - if (add->stack->opts.default_permissions) {
895 + if (add->opts.default_permissions) {
896 if (chmod(tab_file.path,
888 - add->stack->opts.default_permissions)) {
897 + add->opts.default_permissions)) {
898 err = REFTABLE_IO_ERROR;
899 goto done;
900 }
@@ -893,7 +902,7 @@ int reftable_addition_add(struct reftable_addition *add,
902
903 writer.fd = tab_file.fd;
904 err = reftable_writer_new(&wr, fd_writer_write, fd_writer_flush,
896 - &writer, &add->stack->opts);
905 + &writer, add->stack->opts.hash_id, &add->opts);
906 if (err < 0)
907 goto done;
908
@@ -1066,13 +1075,14 @@ done:
1075 static int stack_compact_locked(struct reftable_stack *st,
1076 size_t first, size_t last,
1077 struct reftable_log_expiry_config *config,
1078 + const struct reftable_write_options *opts,
1079 struct reftable_tmpfile *tab_file_out)
1080 {
1081 struct reftable_buf next_name = REFTABLE_BUF_INIT;
1082 struct reftable_buf tab_file_path = REFTABLE_BUF_INIT;
1083 struct reftable_writer *wr = NULL;
1084 struct fd_writer writer= {
1075 - .opts = &st->opts,
1085 + .opts = opts,
1086 };
1087 struct reftable_tmpfile tab_file = REFTABLE_TMPFILE_INIT;
1088 int err = 0;
@@ -1094,15 +1104,15 @@ static int stack_compact_locked(struct reftable_stack *st,
1104 if (err < 0)
1105 goto done;
1106
1097 - if (st->opts.default_permissions &&
1098 - chmod(tab_file.path, st->opts.default_permissions) < 0) {
1107 + if (opts->default_permissions &&
1108 + chmod(tab_file.path, opts->default_permissions) < 0) {
1109 err = REFTABLE_IO_ERROR;
1110 goto done;
1111 }
1112
1113 writer.fd = tab_file.fd;
1114 err = reftable_writer_new(&wr, fd_writer_write, fd_writer_flush,
1105 - &writer, &st->opts);
1115 + &writer, st->opts.hash_id, opts);
1116 if (err < 0)
1117 goto done;
1118
@@ -1150,6 +1160,7 @@ enum stack_compact_range_flags {
1160 static int stack_compact_range(struct reftable_stack *st,
1161 size_t first, size_t last,
1162 struct reftable_log_expiry_config *expiry,
1163 + const struct reftable_write_options *opts,
1164 unsigned int flags)
1165 {
1166 struct reftable_buf tables_list_buf = REFTABLE_BUF_INIT;
@@ -1175,7 +1186,7 @@ static int stack_compact_range(struct reftable_stack *st,
1186 * Hold the lock so that we can read "tables.list" and lock all tables
1187 * which are part of the user-specified range.
1188 */
1178 - err = flock_acquire(&tables_list_lock, st->list_file, st->opts.lock_timeout_ms);
1189 + err = flock_acquire(&tables_list_lock, st->list_file, opts->lock_timeout_ms);
1190 if (err < 0)
1191 goto done;
1192
@@ -1274,7 +1285,7 @@ static int stack_compact_range(struct reftable_stack *st,
1285 * these tables may end up with an empty new table in case tombstones
1286 * end up cancelling out all refs in that range.
1287 */
1277 - err = stack_compact_locked(st, first, last, expiry, &new_table);
1288 + err = stack_compact_locked(st, first, last, expiry, opts, &new_table);
1289 if (err < 0) {
1290 if (err != REFTABLE_EMPTY_TABLE_ERROR)
1291 goto done;
@@ -1286,13 +1297,13 @@ static int stack_compact_range(struct reftable_stack *st,
1297 * "tables.list". We'll then replace the compacted range of tables with
1298 * the new table.
1299 */
1289 - err = flock_acquire(&tables_list_lock, st->list_file, st->opts.lock_timeout_ms);
1300 + err = flock_acquire(&tables_list_lock, st->list_file, opts->lock_timeout_ms);
1301 if (err < 0)
1302 goto done;
1303
1293 - if (st->opts.default_permissions) {
1304 + if (opts->default_permissions) {
1305 if (chmod(tables_list_lock.path,
1295 - st->opts.default_permissions) < 0) {
1306 + opts->default_permissions) < 0) {
1307 err = REFTABLE_IO_ERROR;
1308 goto done;
1309 }
@@ -1513,10 +1524,16 @@ done:
1524 }
1525
1526 int reftable_stack_compact_all(struct reftable_stack *st,
1527 + const struct reftable_write_options *opts,
1528 struct reftable_log_expiry_config *config)
1529 {
1530 + struct reftable_write_options opts_default = { 0 };
1531 size_t last = st->merged->tables_len ? st->merged->tables_len - 1 : 0;
1519 - return stack_compact_range(st, 0, last, config, 0);
1532 +
1533 + if (!opts)
1534 + opts = &opts_default;
1535 +
1536 + return stack_compact_range(st, 0, last, config, opts, 0);
1537 }
1538
1539 static int segment_size(struct segment *s)
@@ -1601,6 +1618,7 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
1618 }
1619
1620 static int stack_segments_for_compaction(struct reftable_stack *st,
1621 + const struct reftable_write_options *opts,
1622 struct segment *seg)
1623 {
1624 int version = (st->opts.hash_id == REFTABLE_HASH_SHA1) ? 1 : 2;
@@ -1615,13 +1633,14 @@ static int stack_segments_for_compaction(struct reftable_stack *st,
1633 sizes[i] = st->tables[i]->size - overhead;
1634
1635 *seg = suggest_compaction_segment(sizes, st->merged->tables_len,
1618 - st->opts.auto_compaction_factor);
1636 + opts->auto_compaction_factor);
1637 reftable_free(sizes);
1638
1639 return 0;
1640 }
1641
1642 static int update_segment_if_compaction_required(struct reftable_stack *st,
1643 + const struct reftable_write_options *opts,
1644 struct segment *seg,
1645 bool use_geometric,
1646 bool *required)
@@ -1638,7 +1657,7 @@ static int update_segment_if_compaction_required(struct reftable_stack *st,
1657 return 0;
1658 }
1659
1641 - err = stack_segments_for_compaction(st, seg);
1660 + err = stack_segments_for_compaction(st, opts, seg);
1661 if (err)
1662 return err;
1663
@@ -1647,27 +1666,40 @@ static int update_segment_if_compaction_required(struct reftable_stack *st,
1666 }
1667
1668 int reftable_stack_compaction_required(struct reftable_stack *st,
1669 + const struct reftable_write_options *opts,
1670 bool use_heuristics,
1671 bool *required)
1672 {
1673 + struct reftable_write_options opts_default = { 0 };
1674 struct segment seg;
1654 - return update_segment_if_compaction_required(st, &seg, use_heuristics,
1655 - required);
1675 +
1676 + if (!opts)
1677 + opts = &opts_default;
1678 +
1679 + return update_segment_if_compaction_required(st, opts, &seg,
1680 + use_heuristics, required);
1681 }
1682
1658 -int reftable_stack_auto_compact(struct reftable_stack *st)
1683 +int reftable_stack_auto_compact(struct reftable_stack *st,
1684 + const struct reftable_write_options *opts)
1685 {
1686 + struct reftable_write_options opts_default = { 0 };
1687 struct segment seg;
1688 bool required;
1689 int err;
1690
1664 - err = update_segment_if_compaction_required(st, &seg, true, &required);
1691 + if (!opts)
1692 + opts = &opts_default;
1693 +
1694 + err = update_segment_if_compaction_required(st, opts, &seg, true,
1695 + &required);
1696 if (err)
1697 return err;
1698
1699 if (required)
1700 return stack_compact_range(st, seg.start, seg.end - 1,
1670 - NULL, STACK_COMPACT_RANGE_BEST_EFFORT);
1701 + NULL, opts,
1702 + STACK_COMPACT_RANGE_BEST_EFFORT);
1703
1704 return 0;
1705 }
@@ -1807,7 +1839,7 @@ static int reftable_stack_clean_locked(struct reftable_stack *st)
1839 int reftable_stack_clean(struct reftable_stack *st)
1840 {
1841 struct reftable_addition *add = NULL;
1810 - int err = reftable_stack_new_addition(&add, st, 0);
1842 + int err = reftable_stack_new_addition(&add, st, NULL, 0);
1843 if (err < 0) {
1844 goto done;
1845 }
reftable/stack.h
+1 -1
@@ -20,7 +20,7 @@ struct reftable_stack {
20
21 char *reftable_dir;
22
23 - struct reftable_write_options opts;
23 + struct reftable_stack_options opts;
24
25 struct reftable_table **tables;
26 size_t tables_len;
reftable/writer.c
+12 -9
@@ -80,9 +80,6 @@ static void options_set_defaults(struct reftable_write_options *opts)
80 opts->restart_interval = 16;
81 }
82
83 - if (opts->hash_id == 0) {
84 - opts->hash_id = REFTABLE_HASH_SHA1;
85 - }
83 if (opts->block_size == 0) {
84 opts->block_size = DEFAULT_BLOCK_SIZE;
85 }
@@ -90,7 +87,7 @@ static void options_set_defaults(struct reftable_write_options *opts)
87
88 static int writer_version(struct reftable_writer *w)
89 {
93 - return (w->opts.hash_id == 0 || w->opts.hash_id == REFTABLE_HASH_SHA1) ?
90 + return (w->hash_id == 0 || w->hash_id == REFTABLE_HASH_SHA1) ?
91 1 :
92 2;
93 }
@@ -107,7 +104,7 @@ static int writer_write_header(struct reftable_writer *w, uint8_t *dest)
104 if (writer_version(w) == 2) {
105 uint32_t hash_id;
106
110 - switch (w->opts.hash_id) {
107 + switch (w->hash_id) {
108 case REFTABLE_HASH_SHA1:
109 hash_id = REFTABLE_FORMAT_ID_SHA1;
110 break;
@@ -134,7 +131,7 @@ static int writer_reinit_block_writer(struct reftable_writer *w, uint8_t typ)
131 reftable_buf_reset(&w->last_key);
132 ret = block_writer_init(&w->block_writer_data, typ, w->block,
133 w->opts.block_size, block_start,
137 - hash_size(w->opts.hash_id));
134 + hash_size(w->hash_id));
135 if (ret < 0)
136 return ret;
137
@@ -147,7 +144,9 @@ static int writer_reinit_block_writer(struct reftable_writer *w, uint8_t typ)
144 int reftable_writer_new(struct reftable_writer **out,
145 ssize_t (*writer_func)(void *, const void *, size_t),
146 int (*flush_func)(void *),
150 - void *writer_arg, const struct reftable_write_options *_opts)
147 + void *writer_arg,
148 + enum reftable_hash hash_id,
149 + const struct reftable_write_options *_opts)
150 {
151 struct reftable_write_options opts = {0};
152 struct reftable_writer *wp;
@@ -162,6 +161,9 @@ int reftable_writer_new(struct reftable_writer **out,
161 if (opts.block_size >= (1 << 24))
162 return REFTABLE_API_ERROR;
163
164 + if (!hash_id)
165 + hash_id = REFTABLE_HASH_SHA1;
166 +
167 reftable_buf_init(&wp->block_writer_data.last_key);
168 reftable_buf_init(&wp->last_key);
169 reftable_buf_init(&wp->scratch);
@@ -173,6 +175,7 @@ int reftable_writer_new(struct reftable_writer **out,
175 wp->write = writer_func;
176 wp->write_arg = writer_arg;
177 wp->opts = opts;
178 + wp->hash_id = hash_id;
179 wp->flush = flush_func;
180 writer_reinit_block_writer(wp, REFTABLE_BLOCK_TYPE_REF);
181
@@ -367,7 +370,7 @@ int reftable_writer_add_ref(struct reftable_writer *w,
370 if (!w->opts.skip_index_objects && reftable_ref_record_val1(ref)) {
371 reftable_buf_reset(&w->scratch);
372 err = reftable_buf_add(&w->scratch, (char *)reftable_ref_record_val1(ref),
370 - hash_size(w->opts.hash_id));
373 + hash_size(w->hash_id));
374 if (err < 0)
375 goto out;
376
@@ -379,7 +382,7 @@ int reftable_writer_add_ref(struct reftable_writer *w,
382 if (!w->opts.skip_index_objects && reftable_ref_record_val2(ref)) {
383 reftable_buf_reset(&w->scratch);
384 err = reftable_buf_add(&w->scratch, reftable_ref_record_val2(ref),
382 - hash_size(w->opts.hash_id));
385 + hash_size(w->hash_id));
386 if (err < 0)
387 goto out;
388
reftable/writer.h
+1
@@ -27,6 +27,7 @@ struct reftable_writer {
27 uint64_t next;
28 uint64_t min_update_index, max_update_index;
29 struct reftable_write_options opts;
30 + enum reftable_hash hash_id;
31
32 /* memory buffer for writing */
33 uint8_t *block;
t/helper/test-reftable.c
+1 -1
@@ -174,7 +174,7 @@ static int dump_table(struct reftable_merged_table *mt)
174 static int dump_stack(const char *stackdir, uint32_t hash_id)
175 {
176 struct reftable_stack *stack = NULL;
177 - struct reftable_write_options opts = { .hash_id = hash_id };
177 + struct reftable_stack_options opts = { .hash_id = hash_id };
178 struct reftable_merged_table *merged = NULL;
179
180 int err = reftable_new_stack(&stack, stackdir, &opts);
t/unit-tests/lib-reftable.c
+5 -3
@@ -25,11 +25,12 @@ static int strbuf_writer_flush(void *arg UNUSED)
25 }
26
27 struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
28 + enum reftable_hash hash_id,
29 struct reftable_write_options *opts)
30 {
31 struct reftable_writer *writer;
32 int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
32 - buf, opts);
33 + buf, hash_id, opts);
34 cl_assert(!ret);
35 return writer;
36 }
@@ -39,6 +40,7 @@ void cl_reftable_write_to_buf(struct reftable_buf *buf,
40 size_t nrefs,
41 struct reftable_log_record *logs,
42 size_t nlogs,
43 + enum reftable_hash hash_id,
44 struct reftable_write_options *_opts)
45 {
46 struct reftable_write_options opts = { 0 };
@@ -66,7 +68,7 @@ void cl_reftable_write_to_buf(struct reftable_buf *buf,
68 min = ui;
69 }
70
69 - writer = cl_reftable_strbuf_writer(buf, &opts);
71 + writer = cl_reftable_strbuf_writer(buf, hash_id, &opts);
72 ret = reftable_writer_set_limits(writer, min, max);
73 cl_assert(!ret);
74
@@ -88,7 +90,7 @@ void cl_reftable_write_to_buf(struct reftable_buf *buf,
90 size_t off = i * (opts.block_size ? opts.block_size
91 : DEFAULT_BLOCK_SIZE);
92 if (!off)
91 - off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
93 + off = header_size(hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
94 cl_assert(buf->buf[off] == 'r');
95 }
96
t/unit-tests/lib-reftable.h
+2
@@ -10,6 +10,7 @@ struct reftable_buf;
10 void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
11
12 struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
13 + enum reftable_hash hash_id,
14 struct reftable_write_options *opts);
15
16 void cl_reftable_write_to_buf(struct reftable_buf *buf,
@@ -17,4 +18,5 @@ void cl_reftable_write_to_buf(struct reftable_buf *buf,
18 size_t nrecords,
19 struct reftable_log_record *logs,
20 size_t nlogs,
21 + enum reftable_hash hash_id,
22 struct reftable_write_options *opts);
t/unit-tests/u-reftable-merged.c
+6 -3
@@ -34,7 +34,8 @@ merged_table_from_records(struct reftable_ref_record **refs,
34 cl_assert(*source != NULL);
35
36 for (size_t i = 0; i < n; i++) {
37 - cl_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0, &opts);
37 + cl_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0,
38 + REFTABLE_HASH_SHA1, &opts);
39 block_source_from_buf(&(*source)[i], &buf[i]);
40
41 err = reftable_table_new(&(*tables)[i], &(*source)[i],
@@ -357,7 +358,8 @@ merged_table_from_log_records(struct reftable_log_record **logs,
358 cl_assert(*source != NULL);
359
360 for (size_t i = 0; i < n; i++) {
360 - cl_reftable_write_to_buf(&buf[i], NULL, 0, logs[i], sizes[i], &opts);
361 + cl_reftable_write_to_buf(&buf[i], NULL, 0, logs[i], sizes[i],
362 + REFTABLE_HASH_SHA1, &opts);
363 block_source_from_buf(&(*source)[i], &buf[i]);
364
365 err = reftable_table_new(&(*tables)[i], &(*source)[i],
@@ -487,7 +489,8 @@ void test_reftable_merged__default_write_opts(void)
489 {
490 struct reftable_write_options opts = { 0 };
491 struct reftable_buf buf = REFTABLE_BUF_INIT;
490 - struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
492 + struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
493 + REFTABLE_HASH_SHA1, &opts);
494 struct reftable_ref_record rec = {
495 .refname = (char *) "master",
496 .update_index = 1,
t/unit-tests/u-reftable-readwrite.c
+28 -10
@@ -48,7 +48,6 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
48 {
49 struct reftable_write_options opts = {
50 .block_size = block_size,
51 - .hash_id = hash_id,
51 };
52 struct reftable_ref_record *refs;
53 struct reftable_log_record *logs;
@@ -78,7 +77,7 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
77 logs[i].value.update.message = (char *) "message";
78 }
79
81 - cl_reftable_write_to_buf(buf, refs, N, logs, N, &opts);
80 + cl_reftable_write_to_buf(buf, refs, N, logs, N, hash_id, &opts);
81
82 reftable_free(refs);
83 reftable_free(logs);
@@ -103,6 +102,7 @@ void test_reftable_readwrite__log_buffer_size(void)
102 .message = (char *) "commit: 9\n",
103 } } };
104 struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
105 + REFTABLE_HASH_SHA1,
106 &opts);
107
108 /* This tests buffer extension for log compression. Must use a random
@@ -143,6 +143,7 @@ void test_reftable_readwrite__log_overflow(void)
143 },
144 };
145 struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
146 + REFTABLE_HASH_SHA1,
147 &opts);
148
149 memset(msg, 'x', sizeof(msg) - 1);
@@ -157,6 +158,7 @@ void test_reftable_readwrite__log_write_limits(void)
158 struct reftable_write_options opts = { 0 };
159 struct reftable_buf buf = REFTABLE_BUF_INIT;
160 struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
161 + REFTABLE_HASH_SHA1,
162 &opts);
163 struct reftable_log_record log = {
164 .refname = (char *)"refs/head/master",
@@ -202,7 +204,9 @@ void test_reftable_readwrite__log_write_read(void)
204 struct reftable_table *table;
205 struct reftable_block_source source = { 0 };
206 struct reftable_buf buf = REFTABLE_BUF_INIT;
205 - struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
207 + struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
208 + REFTABLE_HASH_SHA1,
209 + &opts);
210 const struct reftable_stats *stats = NULL;
211 int N = 2, i;
212 char **names;
@@ -299,6 +303,7 @@ void test_reftable_readwrite__log_zlib_corruption(void)
303 struct reftable_block_source source = { 0 };
304 struct reftable_buf buf = REFTABLE_BUF_INIT;
305 struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
306 + REFTABLE_HASH_SHA1,
307 &opts);
308 const struct reftable_stats *stats = NULL;
309 char message[100] = { 0 };
@@ -531,6 +536,7 @@ static void t_table_refs_for(int indexed)
536 struct reftable_block_source source = { 0 };
537 struct reftable_buf buf = REFTABLE_BUF_INIT;
538 struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
539 + REFTABLE_HASH_SHA1,
540 &opts);
541 struct reftable_iterator it = { 0 };
542 int N = 50, j, i;
@@ -622,7 +628,9 @@ void test_reftable_readwrite__write_empty_table(void)
628 {
629 struct reftable_write_options opts = { 0 };
630 struct reftable_buf buf = REFTABLE_BUF_INIT;
625 - struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
631 + struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
632 + REFTABLE_HASH_SHA1,
633 + &opts);
634 struct reftable_block_source source = { 0 };
635 struct reftable_table *table = NULL;
636 struct reftable_ref_record rec = { 0 };
@@ -660,7 +668,9 @@ void test_reftable_readwrite__write_object_id_min_length(void)
668 .block_size = 75,
669 };
670 struct reftable_buf buf = REFTABLE_BUF_INIT;
663 - struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
671 + struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
672 + REFTABLE_HASH_SHA1,
673 + &opts);
674 struct reftable_ref_record ref = {
675 .update_index = 1,
676 .value_type = REFTABLE_REF_VAL1,
@@ -691,7 +701,9 @@ void test_reftable_readwrite__write_object_id_length(void)
701 .block_size = 75,
702 };
703 struct reftable_buf buf = REFTABLE_BUF_INIT;
694 - struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
704 + struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
705 + REFTABLE_HASH_SHA1,
706 + &opts);
707 struct reftable_ref_record ref = {
708 .update_index = 1,
709 .value_type = REFTABLE_REF_VAL1,
@@ -721,7 +733,9 @@ void test_reftable_readwrite__write_empty_key(void)
733 {
734 struct reftable_write_options opts = { 0 };
735 struct reftable_buf buf = REFTABLE_BUF_INIT;
724 - struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
736 + struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
737 + REFTABLE_HASH_SHA1,
738 + &opts);
739 struct reftable_ref_record ref = {
740 .refname = (char *) "",
741 .update_index = 1,
@@ -740,7 +754,9 @@ void test_reftable_readwrite__write_key_order(void)
754 {
755 struct reftable_write_options opts = { 0 };
756 struct reftable_buf buf = REFTABLE_BUF_INIT;
743 - struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
757 + struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
758 + REFTABLE_HASH_SHA1,
759 + &opts);
760 struct reftable_ref_record refs[2] = {
761 {
762 .refname = (char *) "b",
@@ -787,7 +803,8 @@ void test_reftable_readwrite__write_multiple_indices(void)
803 int i;
804 int err;
805
790 - writer = cl_reftable_strbuf_writer(&writer_buf, &opts);
806 + writer = cl_reftable_strbuf_writer(&writer_buf, REFTABLE_HASH_SHA1,
807 + &opts);
808 reftable_writer_set_limits(writer, 1, 1);
809 for (i = 0; i < 100; i++) {
810 struct reftable_ref_record ref = {
@@ -861,7 +878,8 @@ void test_reftable_readwrite__write_multi_level_index(void)
878 struct reftable_table *table;
879 int err;
880
864 - writer = cl_reftable_strbuf_writer(&writer_buf, &opts);
881 + writer = cl_reftable_strbuf_writer(&writer_buf, REFTABLE_HASH_SHA1,
882 + &opts);
883 reftable_writer_set_limits(writer, 1, 1);
884 for (size_t i = 0; i < 200; i++) {
885 struct reftable_ref_record ref = {
t/unit-tests/u-reftable-stack.c
+84 -105
@@ -111,10 +111,9 @@ static int write_test_ref(struct reftable_writer *wr, void *arg)
111 static void write_n_ref_tables(struct reftable_stack *st,
112 size_t n)
113 {
114 - int disable_auto_compact;
115 -
116 - disable_auto_compact = st->opts.disable_auto_compact;
117 - st->opts.disable_auto_compact = 1;
114 + struct reftable_write_options opts = {
115 + .disable_auto_compact = 1,
116 + };
117
118 for (size_t i = 0; i < n; i++) {
119 struct reftable_ref_record ref = {
@@ -128,10 +127,8 @@ static void write_n_ref_tables(struct reftable_stack *st,
127 cl_reftable_set_hash(ref.value.val1, i, REFTABLE_HASH_SHA1);
128
129 cl_assert_equal_i(reftable_stack_add(st,
131 - &write_test_ref, &ref, 0), 0);
130 + &write_test_ref, &ref, &opts, 0), 0);
131 }
133 -
134 - st->opts.disable_auto_compact = disable_auto_compact;
132 }
133
134 struct write_log_arg {
@@ -168,10 +165,10 @@ void test_reftable_stack__add_one(void)
165 struct stat stat_result = { 0 };
166 int err;
167
171 - err = reftable_new_stack(&st, dir, &opts);
168 + err = reftable_new_stack(&st, dir, NULL);
169 cl_assert(!err);
170
174 - err = reftable_stack_add(st, write_test_ref, &ref, 0);
171 + err = reftable_stack_add(st, write_test_ref, &ref, &opts, 0);
172 cl_assert(!err);
173
174 err = reftable_stack_read_ref(st, ref.refname, &dest);
@@ -210,7 +207,6 @@ void test_reftable_stack__add_one(void)
207
208 void test_reftable_stack__uptodate(void)
209 {
213 - struct reftable_write_options opts = { 0 };
210 struct reftable_stack *st1 = NULL;
211 struct reftable_stack *st2 = NULL;
212 char *dir = get_tmp_dir(__LINE__);
@@ -232,15 +228,15 @@ void test_reftable_stack__uptodate(void)
228 /* simulate multi-process access to the same stack
229 by creating two stacks for the same directory.
230 */
235 - cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
236 - cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
231 + cl_assert_equal_i(reftable_new_stack(&st1, dir, NULL), 0);
232 + cl_assert_equal_i(reftable_new_stack(&st2, dir, NULL), 0);
233 cl_assert_equal_i(reftable_stack_add(st1, write_test_ref,
238 - &ref1, 0), 0);
234 + &ref1, NULL, 0), 0);
235 cl_assert_equal_i(reftable_stack_add(st2, write_test_ref,
240 - &ref2, 0), REFTABLE_OUTDATED_ERROR);
236 + &ref2, NULL, 0), REFTABLE_OUTDATED_ERROR);
237 cl_assert_equal_i(reftable_stack_reload(st2), 0);
238 cl_assert_equal_i(reftable_stack_add(st2, write_test_ref,
243 - &ref2, 0), 0);
239 + &ref2, NULL, 0), 0);
240 reftable_stack_destroy(st1);
241 reftable_stack_destroy(st2);
242 clear_dir(dir);
@@ -249,7 +245,6 @@ void test_reftable_stack__uptodate(void)
245 void test_reftable_stack__transaction_api(void)
246 {
247 char *dir = get_tmp_dir(__LINE__);
252 - struct reftable_write_options opts = { 0 };
248 struct reftable_stack *st = NULL;
249 struct reftable_addition *add = NULL;
250
@@ -261,11 +256,11 @@ void test_reftable_stack__transaction_api(void)
256 };
257 struct reftable_ref_record dest = { 0 };
258
264 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
259 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
260
261 reftable_addition_destroy(add);
262
268 - cl_assert_equal_i(reftable_stack_new_addition(&add, st, 0), 0);
263 + cl_assert_equal_i(reftable_stack_new_addition(&add, st, NULL, 0), 0);
264 cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
265 &ref), 0);
266 cl_assert_equal_i(reftable_addition_commit(add), 0);
@@ -306,7 +301,7 @@ void test_reftable_stack__transaction_with_reload(void)
301
302 cl_assert_equal_i(reftable_new_stack(&st1, dir, NULL), 0);
303 cl_assert_equal_i(reftable_new_stack(&st2, dir, NULL), 0);
309 - cl_assert_equal_i(reftable_stack_new_addition(&add, st1, 0), 0);
304 + cl_assert_equal_i(reftable_stack_new_addition(&add, st1, NULL, 0), 0);
305 cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
306 &refs[0]), 0);
307 cl_assert_equal_i(reftable_addition_commit(add), 0);
@@ -317,9 +312,9 @@ void test_reftable_stack__transaction_with_reload(void)
312 * create the addition and lock the stack by default, but allow the
313 * reload to happen when REFTABLE_STACK_NEW_ADDITION_RELOAD is set.
314 */
320 - cl_assert_equal_i(reftable_stack_new_addition(&add, st2, 0),
315 + cl_assert_equal_i(reftable_stack_new_addition(&add, st2, NULL, 0),
316 REFTABLE_OUTDATED_ERROR);
322 - cl_assert_equal_i(reftable_stack_new_addition(&add, st2,
317 + cl_assert_equal_i(reftable_stack_new_addition(&add, st2, NULL,
318 REFTABLE_STACK_NEW_ADDITION_RELOAD), 0);
319 cl_assert_equal_i(reftable_addition_add(add, write_test_ref,
320 &refs[1]), 0);
@@ -342,12 +337,11 @@ void test_reftable_stack__transaction_with_reload(void)
337 void test_reftable_stack__transaction_api_performs_auto_compaction(void)
338 {
339 char *dir = get_tmp_dir(__LINE__);
345 - struct reftable_write_options opts = {0};
340 struct reftable_addition *add = NULL;
341 struct reftable_stack *st = NULL;
342 size_t n = 20;
343
350 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
344 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
345
346 for (size_t i = 0; i <= n; i++) {
347 struct reftable_ref_record ref = {
@@ -356,6 +350,9 @@ void test_reftable_stack__transaction_api_performs_auto_compaction(void)
350 .value.symref = (char *) "master",
351 };
352 char name[100];
353 + struct reftable_write_options write_opts = {
354 + .disable_auto_compact = (i != n),
355 + };
356
357 snprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
358 ref.refname = name;
@@ -365,10 +362,8 @@ void test_reftable_stack__transaction_api_performs_auto_compaction(void)
362 * we can ensure that we indeed honor this setting and have
363 * better control over when exactly auto compaction runs.
364 */
368 - st->opts.disable_auto_compact = i != n;
369 -
365 cl_assert_equal_i(reftable_stack_new_addition(&add,
371 - st, 0), 0);
366 + st, &write_opts, 0), 0);
367 cl_assert_equal_i(reftable_addition_add(add,
368 write_test_ref, &ref), 0);
369 cl_assert_equal_i(reftable_addition_commit(add), 0);
@@ -398,15 +393,14 @@ void test_reftable_stack__auto_compaction_fails_gracefully(void)
393 .value_type = REFTABLE_REF_VAL1,
394 .value.val1 = {0x01},
395 };
401 - struct reftable_write_options opts = { 0 };
396 struct reftable_stack *st;
397 struct reftable_buf table_path = REFTABLE_BUF_INIT;
398 char *dir = get_tmp_dir(__LINE__);
399 int err;
400
407 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
401 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
402 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
409 - &ref, 0), 0);
403 + &ref, NULL, 0), 0);
404 cl_assert_equal_i(st->merged->tables_len, 1);
405 cl_assert_equal_i(st->stats.attempts, 0);
406 cl_assert_equal_i(st->stats.failures, 0);
@@ -424,7 +418,7 @@ void test_reftable_stack__auto_compaction_fails_gracefully(void)
418 write_file_buf(table_path.buf, "", 0);
419
420 ref.update_index = 2;
427 - err = reftable_stack_add(st, write_test_ref, &ref, 0);
421 + err = reftable_stack_add(st, write_test_ref, &ref, NULL, 0);
422 cl_assert(!err);
423 cl_assert_equal_i(st->merged->tables_len, 2);
424 cl_assert_equal_i(st->stats.attempts, 1);
@@ -443,7 +437,6 @@ static int write_error(struct reftable_writer *wr UNUSED, void *arg)
437 void test_reftable_stack__update_index_check(void)
438 {
439 char *dir = get_tmp_dir(__LINE__);
446 - struct reftable_write_options opts = { 0 };
440 struct reftable_stack *st = NULL;
441 struct reftable_ref_record ref1 = {
442 .refname = (char *) "name1",
@@ -458,11 +451,11 @@ void test_reftable_stack__update_index_check(void)
451 .value.symref = (char *) "master",
452 };
453
461 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
454 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
455 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
463 - &ref1, 0), 0);
456 + &ref1, NULL, 0), 0);
457 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
465 - &ref2, 0), REFTABLE_API_ERROR);
458 + &ref2, NULL, 0), REFTABLE_API_ERROR);
459 reftable_stack_destroy(st);
460 clear_dir(dir);
461 }
@@ -470,14 +463,13 @@ void test_reftable_stack__update_index_check(void)
463 void test_reftable_stack__lock_failure(void)
464 {
465 char *dir = get_tmp_dir(__LINE__);
473 - struct reftable_write_options opts = { 0 };
466 struct reftable_stack *st = NULL;
467 int i;
468
477 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
469 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
470 for (i = -1; i != REFTABLE_EMPTY_TABLE_ERROR; i--)
471 cl_assert_equal_i(reftable_stack_add(st, write_error,
480 - &i, 0), i);
472 + &i, NULL, 0), i);
473
474 reftable_stack_destroy(st);
475 clear_dir(dir);
@@ -499,7 +491,7 @@ void test_reftable_stack__add(void)
491 size_t i, N = ARRAY_SIZE(refs);
492 int err = 0;
493
502 - err = reftable_new_stack(&st, dir, &opts);
494 + err = reftable_new_stack(&st, dir, NULL);
495 cl_assert(!err);
496
497 for (i = 0; i < N; i++) {
@@ -521,7 +513,7 @@ void test_reftable_stack__add(void)
513
514 for (i = 0; i < N; i++)
515 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
524 - &refs[i], 0), 0);
516 + &refs[i], &opts, 0), 0);
517
518 for (i = 0; i < N; i++) {
519 struct write_log_arg arg = {
@@ -529,10 +521,10 @@ void test_reftable_stack__add(void)
521 .update_index = reftable_stack_next_update_index(st),
522 };
523 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
532 - &arg, 0), 0);
524 + &arg, &opts, 0), 0);
525 }
526
535 - cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
527 + cl_assert_equal_i(reftable_stack_compact_all(st, &opts, NULL), 0);
528
529 for (i = 0; i < N; i++) {
530 struct reftable_ref_record dest = { 0 };
@@ -584,7 +576,6 @@ void test_reftable_stack__add(void)
576
577 void test_reftable_stack__iterator(void)
578 {
587 - struct reftable_write_options opts = { 0 };
579 struct reftable_stack *st = NULL;
580 char *dir = get_tmp_dir(__LINE__);
581 struct reftable_ref_record refs[10] = { 0 };
@@ -593,7 +584,7 @@ void test_reftable_stack__iterator(void)
584 size_t N = ARRAY_SIZE(refs), i;
585 int err;
586
596 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
587 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
588
589 for (i = 0; i < N; i++) {
590 refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
@@ -613,7 +604,7 @@ void test_reftable_stack__iterator(void)
604
605 for (i = 0; i < N; i++)
606 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
616 - &refs[i], 0), 0);
607 + &refs[i], NULL, 0), 0);
608
609 for (i = 0; i < N; i++) {
610 struct write_log_arg arg = {
@@ -622,7 +613,7 @@ void test_reftable_stack__iterator(void)
613 };
614
615 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
625 - &arg, 0), 0);
616 + &arg, NULL, 0), 0);
617 }
618
619 reftable_stack_init_ref_iterator(st, &it);
@@ -669,9 +660,6 @@ void test_reftable_stack__iterator(void)
660
661 void test_reftable_stack__log_normalize(void)
662 {
672 - struct reftable_write_options opts = {
673 - 0,
674 - };
663 struct reftable_stack *st = NULL;
664 char *dir = get_tmp_dir(__LINE__);
665 struct reftable_log_record input = {
@@ -693,15 +681,15 @@ void test_reftable_stack__log_normalize(void)
681 .update_index = 1,
682 };
683
696 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
684 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
685
686 input.value.update.message = (char *) "one\ntwo";
687 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
700 - &arg, 0), REFTABLE_API_ERROR);
688 + &arg, NULL, 0), REFTABLE_API_ERROR);
689
690 input.value.update.message = (char *) "one";
691 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
704 - &arg, 0), 0);
692 + &arg, NULL, 0), 0);
693 cl_assert_equal_i(reftable_stack_read_log(st, input.refname,
694 &dest), 0);
695 cl_assert_equal_s(dest.value.update.message, "one\n");
@@ -709,7 +697,7 @@ void test_reftable_stack__log_normalize(void)
697 input.value.update.message = (char *) "two\n";
698 arg.update_index = 2;
699 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
712 - &arg, 0), 0);
700 + &arg, NULL, 0), 0);
701 cl_assert_equal_i(reftable_stack_read_log(st, input.refname,
702 &dest), 0);
703 cl_assert_equal_s(dest.value.update.message, "two\n");
@@ -723,7 +711,6 @@ void test_reftable_stack__log_normalize(void)
711 void test_reftable_stack__tombstone(void)
712 {
713 char *dir = get_tmp_dir(__LINE__);
726 - struct reftable_write_options opts = { 0 };
714 struct reftable_stack *st = NULL;
715 struct reftable_ref_record refs[2] = { 0 };
716 struct reftable_log_record logs[2] = { 0 };
@@ -731,7 +718,7 @@ void test_reftable_stack__tombstone(void)
718 struct reftable_ref_record dest = { 0 };
719 struct reftable_log_record log_dest = { 0 };
720
734 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
721 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
722
723 /* even entries add the refs, odd entries delete them. */
724 for (i = 0; i < N; i++) {
@@ -760,7 +747,7 @@ void test_reftable_stack__tombstone(void)
747 }
748 for (i = 0; i < N; i++)
749 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
763 - &refs[i], 0), 0);
750 + &refs[i], NULL, 0), 0);
751
752 for (i = 0; i < N; i++) {
753 struct write_log_arg arg = {
@@ -768,7 +755,7 @@ void test_reftable_stack__tombstone(void)
755 .update_index = reftable_stack_next_update_index(st),
756 };
757 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
771 - &arg, 0), 0);
758 + &arg, NULL, 0), 0);
759 }
760
761 cl_assert_equal_i(reftable_stack_read_ref(st, "branch",
@@ -779,7 +766,7 @@ void test_reftable_stack__tombstone(void)
766 &log_dest), 1);
767 reftable_log_record_release(&log_dest);
768
782 - cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
769 + cl_assert_equal_i(reftable_stack_compact_all(st, NULL, NULL), 0);
770 cl_assert_equal_i(reftable_stack_read_ref(st, "branch",
771 &dest), 1);
772 cl_assert_equal_i(reftable_stack_read_log(st, "branch",
@@ -799,7 +786,6 @@ void test_reftable_stack__tombstone(void)
786 void test_reftable_stack__hash_id(void)
787 {
788 char *dir = get_tmp_dir(__LINE__);
802 - struct reftable_write_options opts = { 0 };
789 struct reftable_stack *st = NULL;
790
791 struct reftable_ref_record ref = {
@@ -808,15 +794,14 @@ void test_reftable_stack__hash_id(void)
794 .value.symref = (char *) "target",
795 .update_index = 1,
796 };
811 - struct reftable_write_options opts32 = { .hash_id = REFTABLE_HASH_SHA256 };
797 + struct reftable_stack_options opts32 = { .hash_id = REFTABLE_HASH_SHA256 };
798 struct reftable_stack *st32 = NULL;
813 - struct reftable_write_options opts_default = { 0 };
799 struct reftable_stack *st_default = NULL;
800 struct reftable_ref_record dest = { 0 };
801
817 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
802 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
803 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
819 - &ref, 0), 0);
804 + &ref, NULL, 0), 0);
805
806 /* can't read it with the wrong hash ID. */
807 cl_assert_equal_i(reftable_new_stack(&st32, dir,
@@ -824,7 +809,7 @@ void test_reftable_stack__hash_id(void)
809
810 /* check that we can read it back with default opts too. */
811 cl_assert_equal_i(reftable_new_stack(&st_default, dir,
827 - &opts_default), 0);
812 + NULL), 0);
813 cl_assert_equal_i(reftable_stack_read_ref(st_default, "master",
814 &dest), 0);
815 cl_assert(reftable_ref_record_equal(&ref, &dest,
@@ -855,7 +840,6 @@ void test_reftable_stack__suggest_compaction_segment_nothing(void)
840 void test_reftable_stack__reflog_expire(void)
841 {
842 char *dir = get_tmp_dir(__LINE__);
858 - struct reftable_write_options opts = { 0 };
843 struct reftable_stack *st = NULL;
844 struct reftable_log_record logs[20] = { 0 };
845 size_t i, N = ARRAY_SIZE(logs) - 1;
@@ -864,7 +848,7 @@ void test_reftable_stack__reflog_expire(void)
848 };
849 struct reftable_log_record log = { 0 };
850
867 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
851 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
852
853 for (i = 1; i <= N; i++) {
854 char buf[256];
@@ -885,18 +869,18 @@ void test_reftable_stack__reflog_expire(void)
869 .update_index = reftable_stack_next_update_index(st),
870 };
871 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
888 - &arg, 0), 0);
872 + &arg, NULL, 0), 0);
873 }
874
891 - cl_assert_equal_i(reftable_stack_compact_all(st, NULL), 0);
892 - cl_assert_equal_i(reftable_stack_compact_all(st, &expiry), 0);
875 + cl_assert_equal_i(reftable_stack_compact_all(st, NULL, NULL), 0);
876 + cl_assert_equal_i(reftable_stack_compact_all(st, NULL, &expiry), 0);
877 cl_assert_equal_i(reftable_stack_read_log(st, logs[9].refname,
878 &log), 1);
879 cl_assert_equal_i(reftable_stack_read_log(st, logs[11].refname,
880 &log), 0);
881
882 expiry.min_update_index = 15;
899 - cl_assert_equal_i(reftable_stack_compact_all(st, &expiry), 0);
883 + cl_assert_equal_i(reftable_stack_compact_all(st, NULL, &expiry), 0);
884 cl_assert_equal_i(reftable_stack_read_log(st, logs[14].refname,
885 &log), 1);
886 cl_assert_equal_i(reftable_stack_read_log(st, logs[16].refname,
@@ -918,15 +902,14 @@ static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
902
903 void test_reftable_stack__empty_add(void)
904 {
921 - struct reftable_write_options opts = { 0 };
905 struct reftable_stack *st = NULL;
906 char *dir = get_tmp_dir(__LINE__);
907 struct reftable_stack *st2 = NULL;
908
926 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
909 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
910 cl_assert_equal_i(reftable_stack_add(st, write_nothing,
928 - NULL, 0), 0);
929 - cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
911 + NULL, NULL, 0), 0);
912 + cl_assert_equal_i(reftable_new_stack(&st2, dir, NULL), 0);
913 clear_dir(dir);
914 reftable_stack_destroy(st);
915 reftable_stack_destroy(st2);
@@ -952,7 +935,7 @@ void test_reftable_stack__auto_compaction(void)
935 size_t i, N = 100;
936 int err;
937
955 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
938 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
939
940 for (i = 0; i < N; i++) {
941 char name[100];
@@ -964,10 +947,10 @@ void test_reftable_stack__auto_compaction(void)
947 };
948 snprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
949
967 - err = reftable_stack_add(st, write_test_ref, &ref, 0);
950 + err = reftable_stack_add(st, write_test_ref, &ref, &opts, 0);
951 cl_assert(!err);
952
970 - err = reftable_stack_auto_compact(st);
953 + err = reftable_stack_auto_compact(st, &opts);
954 cl_assert(!err);
955 cl_assert(i < 2 || st->merged->tables_len < 2 * fastlogN(i, 2));
956 }
@@ -989,7 +972,7 @@ void test_reftable_stack__auto_compaction_factor(void)
972 size_t N = 100;
973 int err;
974
992 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
975 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
976
977 for (size_t i = 0; i < N; i++) {
978 char name[20];
@@ -1000,7 +983,7 @@ void test_reftable_stack__auto_compaction_factor(void)
983 };
984 xsnprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
985
1003 - err = reftable_stack_add(st, &write_test_ref, &ref, 0);
986 + err = reftable_stack_add(st, &write_test_ref, &ref, &opts, 0);
987 cl_assert(!err);
988
989 cl_assert(i < 5 || st->merged->tables_len < 5 * fastlogN(i, 5));
@@ -1020,7 +1003,7 @@ void test_reftable_stack__auto_compaction_with_locked_tables(void)
1003 char *dir = get_tmp_dir(__LINE__);
1004 int err;
1005
1023 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1006 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
1007
1008 write_n_ref_tables(st, 5);
1009 cl_assert_equal_i(st->merged->tables_len, 5);
@@ -1042,7 +1025,7 @@ void test_reftable_stack__auto_compaction_with_locked_tables(void)
1025 * would in theory compact all tables, due to the preexisting lock we
1026 * only compact the newest two tables.
1027 */
1045 - err = reftable_stack_auto_compact(st);
1028 + err = reftable_stack_auto_compact(st, &opts);
1029 cl_assert(!err);
1030 cl_assert_equal_i(st->stats.failures, 0);
1031 cl_assert_equal_i(st->merged->tables_len, 4);
@@ -1054,12 +1037,11 @@ void test_reftable_stack__auto_compaction_with_locked_tables(void)
1037
1038 void test_reftable_stack__add_performs_auto_compaction(void)
1039 {
1057 - struct reftable_write_options opts = { 0 };
1040 struct reftable_stack *st = NULL;
1041 char *dir = get_tmp_dir(__LINE__);
1042 size_t i, n = 20;
1043
1062 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1044 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
1045
1046 for (i = 0; i <= n; i++) {
1047 struct reftable_ref_record ref = {
@@ -1067,6 +1049,9 @@ void test_reftable_stack__add_performs_auto_compaction(void)
1049 .value_type = REFTABLE_REF_SYMREF,
1050 .value.symref = (char *) "master",
1051 };
1052 + struct reftable_write_options write_opts = {
1053 + .disable_auto_compact = (i != n),
1054 + };
1055 bool required = false;
1056 char buf[128];
1057
@@ -1075,20 +1060,18 @@ void test_reftable_stack__add_performs_auto_compaction(void)
1060 * we can ensure that we indeed honor this setting and have
1061 * better control over when exactly auto compaction runs.
1062 */
1078 - st->opts.disable_auto_compact = i != n;
1079 -
1063 snprintf(buf, sizeof(buf), "branch-%04"PRIuMAX, (uintmax_t)i);
1064 ref.refname = buf;
1065
1066 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
1084 - &ref, 0), 0);
1067 + &ref, &write_opts, 0), 0);
1068
1069 /*
1070 * The stack length should grow continuously for all runs where
1071 * auto compaction is disabled. When enabled, we should merge
1072 * all tables in the stack.
1073 */
1091 - cl_assert_equal_i(reftable_stack_compaction_required(st, true, &required), 0);
1074 + cl_assert_equal_i(reftable_stack_compaction_required(st, NULL, true, &required), 0);
1075 if (i != n) {
1076 cl_assert_equal_i(st->merged->tables_len, i + 1);
1077 if (i < 1)
@@ -1115,7 +1098,7 @@ void test_reftable_stack__compaction_with_locked_tables(void)
1098 char *dir = get_tmp_dir(__LINE__);
1099 int err;
1100
1118 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1101 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
1102
1103 write_n_ref_tables(st, 3);
1104 cl_assert_equal_i(st->merged->tables_len, 3);
@@ -1131,7 +1114,7 @@ void test_reftable_stack__compaction_with_locked_tables(void)
1114 * Compaction is expected to fail given that we were not able to
1115 * compact all tables.
1116 */
1134 - err = reftable_stack_compact_all(st, NULL);
1117 + err = reftable_stack_compact_all(st, &opts, NULL);
1118 cl_assert_equal_i(err, REFTABLE_LOCK_ERROR);
1119 cl_assert_equal_i(st->stats.failures, 1);
1120 cl_assert_equal_i(st->merged->tables_len, 3);
@@ -1143,15 +1126,14 @@ void test_reftable_stack__compaction_with_locked_tables(void)
1126
1127 void test_reftable_stack__compaction_concurrent(void)
1128 {
1146 - struct reftable_write_options opts = { 0 };
1129 struct reftable_stack *st1 = NULL, *st2 = NULL;
1130 char *dir = get_tmp_dir(__LINE__);
1131
1150 - cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
1132 + cl_assert_equal_i(reftable_new_stack(&st1, dir, NULL), 0);
1133 write_n_ref_tables(st1, 3);
1134
1153 - cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
1154 - cl_assert_equal_i(reftable_stack_compact_all(st1, NULL), 0);
1135 + cl_assert_equal_i(reftable_new_stack(&st2, dir, NULL), 0);
1136 + cl_assert_equal_i(reftable_stack_compact_all(st1, NULL, NULL), 0);
1137
1138 reftable_stack_destroy(st1);
1139 reftable_stack_destroy(st2);
@@ -1171,20 +1153,19 @@ static void unclean_stack_close(struct reftable_stack *st)
1153
1154 void test_reftable_stack__compaction_concurrent_clean(void)
1155 {
1174 - struct reftable_write_options opts = { 0 };
1156 struct reftable_stack *st1 = NULL, *st2 = NULL, *st3 = NULL;
1157 char *dir = get_tmp_dir(__LINE__);
1158
1178 - cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
1159 + cl_assert_equal_i(reftable_new_stack(&st1, dir, NULL), 0);
1160 write_n_ref_tables(st1, 3);
1161
1181 - cl_assert_equal_i(reftable_new_stack(&st2, dir, &opts), 0);
1182 - cl_assert_equal_i(reftable_stack_compact_all(st1, NULL), 0);
1162 + cl_assert_equal_i(reftable_new_stack(&st2, dir, NULL), 0);
1163 + cl_assert_equal_i(reftable_stack_compact_all(st1, NULL, NULL), 0);
1164
1165 unclean_stack_close(st1);
1166 unclean_stack_close(st2);
1167
1187 - cl_assert_equal_i(reftable_new_stack(&st3, dir, &opts), 0);
1168 + cl_assert_equal_i(reftable_new_stack(&st3, dir, NULL), 0);
1169 cl_assert_equal_i(reftable_stack_clean(st3), 0);
1170 cl_assert_equal_i(count_dir_entries(dir), 2);
1171
@@ -1197,7 +1178,6 @@ void test_reftable_stack__compaction_concurrent_clean(void)
1178
1179 void test_reftable_stack__read_across_reload(void)
1180 {
1200 - struct reftable_write_options opts = { 0 };
1181 struct reftable_stack *st1 = NULL, *st2 = NULL;
1182 struct reftable_ref_record rec = { 0 };
1183 struct reftable_iterator it = { 0 };
@@ -1205,17 +1185,17 @@ void test_reftable_stack__read_across_reload(void)
1185 int err;
1186
1187 /* Create a first stack and set up an iterator for it. */
1208 - cl_assert_equal_i(reftable_new_stack(&st1, dir, &opts), 0);
1188 + cl_assert_equal_i(reftable_new_stack(&st1, dir, NULL), 0);
1189 write_n_ref_tables(st1, 2);
1190 cl_assert_equal_i(st1->merged->tables_len, 2);
1191 reftable_stack_init_ref_iterator(st1, &it);
1192 cl_assert_equal_i(reftable_iterator_seek_ref(&it, ""), 0);
1193
1194 /* Set up a second stack for the same directory and compact it. */
1215 - err = reftable_new_stack(&st2, dir, &opts);
1195 + err = reftable_new_stack(&st2, dir, NULL);
1196 cl_assert(!err);
1197 cl_assert_equal_i(st2->merged->tables_len, 2);
1218 - err = reftable_stack_compact_all(st2, NULL);
1198 + err = reftable_stack_compact_all(st2, NULL, NULL);
1199 cl_assert(!err);
1200 cl_assert_equal_i(st2->merged->tables_len, 1);
1201
@@ -1244,7 +1224,6 @@ void test_reftable_stack__read_across_reload(void)
1224
1225 void test_reftable_stack__reload_with_missing_table(void)
1226 {
1247 - struct reftable_write_options opts = { 0 };
1227 struct reftable_stack *st = NULL;
1228 struct reftable_ref_record rec = { 0 };
1229 struct reftable_iterator it = { 0 };
@@ -1253,7 +1232,7 @@ void test_reftable_stack__reload_with_missing_table(void)
1232 int err;
1233
1234 /* Create a first stack and set up an iterator for it. */
1256 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1235 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
1236 write_n_ref_tables(st, 2);
1237 cl_assert_equal_i(st->merged->tables_len, 2);
1238 reftable_stack_init_ref_iterator(st, &it);
@@ -1320,11 +1299,11 @@ void test_reftable_stack__invalid_limit_updates(void)
1299 char *dir = get_tmp_dir(__LINE__);
1300 struct reftable_stack *st = NULL;
1301
1323 - cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
1302 + cl_assert_equal_i(reftable_new_stack(&st, dir, NULL), 0);
1303
1304 reftable_addition_destroy(add);
1305
1327 - cl_assert_equal_i(reftable_stack_new_addition(&add, st, 0), 0);
1306 + cl_assert_equal_i(reftable_stack_new_addition(&add, st, &opts, 0), 0);
1307
1308 /*
1309 * write_limits_after_ref also updates the update indexes after adding
t/unit-tests/u-reftable-table.c
+5 -3
@@ -22,7 +22,8 @@ void test_reftable_table__seek_once(void)
22 struct reftable_buf buf = REFTABLE_BUF_INIT;
23 int ret;
24
25 - cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
25 + cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0,
26 + REFTABLE_HASH_SHA1, NULL);
27 block_source_from_buf(&source, &buf);
28
29 ret = reftable_table_new(&table, &source, "name");
@@ -64,7 +65,7 @@ void test_reftable_table__reseek(void)
65 int ret;
66
67 cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records),
67 - NULL, 0, NULL);
68 + NULL, 0, REFTABLE_HASH_SHA1, NULL);
69 block_source_from_buf(&source, &buf);
70
71 ret = reftable_table_new(&table, &source, "name");
@@ -147,7 +148,8 @@ void test_reftable_table__block_iterator(void)
148 (uintmax_t) i);
149 }
150
150 - cl_reftable_write_to_buf(&buf, records, nrecords, NULL, 0, NULL);
151 + cl_reftable_write_to_buf(&buf, records, nrecords, NULL, 0,
152 + REFTABLE_HASH_SHA1, NULL);
153 block_source_from_buf(&source, &buf);
154
155 ret = reftable_table_new(&table, &source, "name");