bundle: add flags to verify_bundle()

The verify_bundle() method has a 'verbose' option, but we will want to extend this method to have more granular control over its output. First, replace this 'verbose' option with a new 'flags' option with a single possible value: VERIFY_BUNDLE_VERBOSE. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Oct 12, 2022 at 12:52 UTC 89bd7fedf947484da08e2722d663fdac23a431be
5 files changed +27 -10
builtin/bundle.c
+3 -2
@@ -119,7 +119,8 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
119 goto cleanup;
120 }
121 close(bundle_fd);
122 - if (verify_bundle(the_repository, &header, !quiet)) {
122 + if (verify_bundle(the_repository, &header,
123 + quiet ? 0 : VERIFY_BUNDLE_VERBOSE)) {
124 ret = 1;
125 goto cleanup;
126 }
@@ -185,7 +186,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
186 strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
187 _("Unbundling objects"), NULL);
188 ret = !!unbundle(the_repository, &header, bundle_fd,
188 - &extra_index_pack_args) ||
189 + &extra_index_pack_args, 0) ||
190 list_bundle_refs(&header, argc, argv);
191 bundle_header_release(&header);
192 cleanup:
bundle-uri.c
+6 -1
@@ -303,7 +303,12 @@ static int unbundle_from_file(struct repository *r, const char *file)
303 if ((bundle_fd = read_bundle_header(file, &header)) < 0)
304 return 1;
305
306 - if ((result = unbundle(r, &header, bundle_fd, NULL)))
306 + /*
307 + * Skip the reachability walk here, since we will be adding
308 + * a reachable ref pointing to the new tips, which will reach
309 + * the prerequisite commits.
310 + */
311 + if ((result = unbundle(r, &header, bundle_fd, NULL, 0)))
312 return 1;
313
314 /*
bundle.c
+5 -4
@@ -189,7 +189,7 @@ static int list_refs(struct string_list *r, int argc, const char **argv)
189
190 int verify_bundle(struct repository *r,
191 struct bundle_header *header,
192 - int verbose)
192 + enum verify_bundle_flags flags)
193 {
194 /*
195 * Do fast check, then if any prereqs are missing then go line by line
@@ -248,7 +248,7 @@ int verify_bundle(struct repository *r,
248 error("%s %s", oid_to_hex(oid), name);
249 }
250
251 - if (verbose) {
251 + if (flags & VERIFY_BUNDLE_VERBOSE) {
252 struct string_list *r;
253
254 r = &header->references;
@@ -617,7 +617,8 @@ err:
617 }
618
619 int unbundle(struct repository *r, struct bundle_header *header,
620 - int bundle_fd, struct strvec *extra_index_pack_args)
620 + int bundle_fd, struct strvec *extra_index_pack_args,
621 + enum verify_bundle_flags flags)
622 {
623 struct child_process ip = CHILD_PROCESS_INIT;
624 strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
@@ -631,7 +632,7 @@ int unbundle(struct repository *r, struct bundle_header *header,
632 strvec_clear(extra_index_pack_args);
633 }
634
634 - if (verify_bundle(r, header, 0))
635 + if (verify_bundle(r, header, flags))
636 return -1;
637 ip.in = bundle_fd;
638 ip.no_stdout = 1;
bundle.h
+12 -2
@@ -29,7 +29,13 @@ int read_bundle_header_fd(int fd, struct bundle_header *header,
29 int create_bundle(struct repository *r, const char *path,
30 int argc, const char **argv, struct strvec *pack_options,
31 int version);
32 -int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
32 +
33 +enum verify_bundle_flags {
34 + VERIFY_BUNDLE_VERBOSE = (1 << 0),
35 +};
36 +
37 +int verify_bundle(struct repository *r, struct bundle_header *header,
38 + enum verify_bundle_flags flags);
39
40 /**
41 * Unbundle after reading the header with read_bundle_header().
@@ -40,9 +46,13 @@ int verify_bundle(struct repository *r, struct bundle_header *header, int verbos
46 * Provide "extra_index_pack_args" to pass any extra arguments
47 * (e.g. "-v" for verbose/progress), NULL otherwise. The provided
48 * "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
49 + *
50 + * Before unbundling, this method will call verify_bundle() with the
51 + * given 'flags'.
52 */
53 int unbundle(struct repository *r, struct bundle_header *header,
45 - int bundle_fd, struct strvec *extra_index_pack_args);
54 + int bundle_fd, struct strvec *extra_index_pack_args,
55 + enum verify_bundle_flags flags);
56 int list_bundle_refs(struct bundle_header *header,
57 int argc, const char **argv);
58
transport.c
+1 -1
@@ -178,7 +178,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
178 if (!data->get_refs_from_bundle_called)
179 get_refs_from_bundle_inner(transport);
180 ret = unbundle(the_repository, &data->header, data->fd,
181 - &extra_index_pack_args);
181 + &extra_index_pack_args, 0);
182 transport->hash_algo = data->header.hash_algo;
183 return ret;
184 }