bundle: add bundle verification options type

When `unbundle()` is invoked, fsck verification may be configured by passing the `VERIFY_BUNDLE_FSCK` flag. This mechanism allows fsck checks on the bundle to be enabled or disabled entirely. To facilitate more fine-grained fsck configuration, additional context must be provided to `unbundle()`. Introduce the `unbundle_opts` type, which wraps the existing `verify_bundle_flags`, to facilitate future extension of `unbundle()` configuration. Also update `unbundle()` and its call sites to accept this new options type instead of the flags directly. The end behavior is functionally the same, but allows for the set of configurable options to be extended. This is leveraged in a subsequent commit to enable fsck message severity configuration. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Nov 27, 2024 at 17:33 UTC 87c01003cdff8c99ebdf053441e4527d85952284
5 files changed +22 -9
builtin/bundle.c
+1 -1
@@ -218,7 +218,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
218 strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
219 _("Unbundling objects"), NULL);
220 ret = !!unbundle(the_repository, &header, bundle_fd,
221 - &extra_index_pack_args, 0) ||
221 + &extra_index_pack_args, NULL) ||
222 list_bundle_refs(&header, argc, argv);
223 bundle_header_release(&header);
224
bundle-uri.c
+5 -2
@@ -367,6 +367,10 @@ static int unbundle_from_file(struct repository *r, const char *file)
367 struct string_list_item *refname;
368 struct strbuf bundle_ref = STRBUF_INIT;
369 size_t bundle_prefix_len;
370 + struct unbundle_opts opts = {
371 + .flags = VERIFY_BUNDLE_QUIET |
372 + (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0),
373 + };
374
375 bundle_fd = read_bundle_header(file, &header);
376 if (bundle_fd < 0) {
@@ -379,8 +383,7 @@ static int unbundle_from_file(struct repository *r, const char *file)
383 * a reachable ref pointing to the new tips, which will reach
384 * the prerequisite commits.
385 */
382 - result = unbundle(r, &header, bundle_fd, NULL,
383 - VERIFY_BUNDLE_QUIET | (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0));
386 + result = unbundle(r, &header, bundle_fd, NULL, &opts);
387 if (result) {
388 result = 1;
389 goto cleanup;
bundle.c
+5 -1
@@ -628,9 +628,13 @@ out:
628
629 int unbundle(struct repository *r, struct bundle_header *header,
630 int bundle_fd, struct strvec *extra_index_pack_args,
631 - enum verify_bundle_flags flags)
631 + struct unbundle_opts *opts)
632 {
633 struct child_process ip = CHILD_PROCESS_INIT;
634 + enum verify_bundle_flags flags = 0;
635 +
636 + if (opts)
637 + flags = opts->flags;
638
639 if (verify_bundle(r, header, flags))
640 return -1;
bundle.h
+7 -3
@@ -39,6 +39,10 @@ enum verify_bundle_flags {
39 int verify_bundle(struct repository *r, struct bundle_header *header,
40 enum verify_bundle_flags flags);
41
42 +struct unbundle_opts {
43 + enum verify_bundle_flags flags;
44 +};
45 +
46 /**
47 * Unbundle after reading the header with read_bundle_header().
48 *
@@ -49,12 +53,12 @@ int verify_bundle(struct repository *r, struct bundle_header *header,
53 * (e.g. "-v" for verbose/progress), NULL otherwise. The provided
54 * "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
55 *
52 - * Before unbundling, this method will call verify_bundle() with the
53 - * given 'flags'.
56 + * Before unbundling, this method will call verify_bundle() with 'flags'
57 + * provided in 'opts'.
58 */
59 int unbundle(struct repository *r, struct bundle_header *header,
60 int bundle_fd, struct strvec *extra_index_pack_args,
57 - enum verify_bundle_flags flags);
61 + struct unbundle_opts *opts);
62 int list_bundle_refs(struct bundle_header *header,
63 int argc, const char **argv);
64
transport.c
+4 -2
@@ -176,6 +176,9 @@ static int fetch_refs_from_bundle(struct transport *transport,
176 int nr_heads UNUSED,
177 struct ref **to_fetch UNUSED)
178 {
179 + struct unbundle_opts opts = {
180 + .flags = fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0,
181 + };
182 struct bundle_transport_data *data = transport->data;
183 struct strvec extra_index_pack_args = STRVEC_INIT;
184 int ret;
@@ -186,8 +189,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
189 if (!data->get_refs_from_bundle_called)
190 get_refs_from_bundle_inner(transport);
191 ret = unbundle(the_repository, &data->header, data->fd,
189 - &extra_index_pack_args,
190 - fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
192 + &extra_index_pack_args, &opts);
193 transport->hash_algo = data->header.hash_algo;
194
195 strvec_clear(&extra_index_pack_args);