bundle API: change "flags" to be "extra_index_pack_args"

Since the "flags" parameter was added in be042aff24c (Teach progress eye-candy to fetch_refs_from_bundle(), 2011-09-18) there's never been more than the one flag: BUNDLE_VERBOSE. Let's have the only caller who cares about that pass "-v" itself instead through new "extra_index_pack_args" parameter. The flexibility of being able to pass arbitrary arguments to "unbundle" will be used in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 5, 2021 at 09:34 UTC 7366096de9d3e4aee4b49dfdf0438a8636187a84
4 files changed +19 -10
builtin/bundle.c
+3 -1
@@ -166,6 +166,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
166 OPT_END()
167 };
168 char *bundle_file;
169 + struct strvec extra_index_pack_args = STRVEC_INIT;
170
171 argc = parse_options_cmd_bundle(argc, argv, prefix,
172 builtin_bundle_unbundle_usage, options, &bundle_file);
@@ -177,7 +178,8 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
178 }
179 if (!startup_info->have_repository)
180 die(_("Need a repository to unbundle."));
180 - ret = !!unbundle(the_repository, &header, bundle_fd, 0) ||
181 + ret = !!unbundle(the_repository, &header, bundle_fd,
182 + &extra_index_pack_args) ||
183 list_bundle_refs(&header, argc, argv);
184 bundle_header_release(&header);
185 cleanup:
bundle.c
+6 -6
@@ -569,18 +569,18 @@ err:
569 }
570
571 int unbundle(struct repository *r, struct bundle_header *header,
572 - int bundle_fd, int flags)
572 + int bundle_fd, struct strvec *extra_index_pack_args)
573 {
574 - const char *argv_index_pack[] = {"index-pack",
575 - "--fix-thin", "--stdin", NULL, NULL};
574 struct child_process ip = CHILD_PROCESS_INIT;
575 + strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
576
578 - if (flags & BUNDLE_VERBOSE)
579 - argv_index_pack[3] = "-v";
577 + if (extra_index_pack_args) {
578 + strvec_pushv(&ip.args, extra_index_pack_args->v);
579 + strvec_clear(extra_index_pack_args);
580 + }
581
582 if (verify_bundle(r, header, 0))
583 return -1;
583 - ip.argv = argv_index_pack;
584 ip.in = bundle_fd;
585 ip.no_stdout = 1;
586 ip.git_cmd = 1;
bundle.h
+5 -2
@@ -26,16 +26,19 @@ int create_bundle(struct repository *r, const char *path,
26 int argc, const char **argv, struct strvec *pack_options,
27 int version);
28 int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
29 -#define BUNDLE_VERBOSE 1
29
30 /**
31 * Unbundle after reading the header with read_bundle_header().
32 *
33 * We'll invoke "git index-pack --stdin --fix-thin" for you on the
34 * provided `bundle_fd` from read_bundle_header().
35 + *
36 + * Provide "extra_index_pack_args" to pass any extra arguments
37 + * (e.g. "-v" for verbose/progress), NULL otherwise. The provided
38 + * "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
39 */
40 int unbundle(struct repository *r, struct bundle_header *header,
38 - int bundle_fd, int flags);
41 + int bundle_fd, struct strvec *extra_index_pack_args);
42 int list_bundle_refs(struct bundle_header *header,
43 int argc, const char **argv);
44
transport.c
+5 -1
@@ -162,12 +162,16 @@ static int fetch_refs_from_bundle(struct transport *transport,
162 int nr_heads, struct ref **to_fetch)
163 {
164 struct bundle_transport_data *data = transport->data;
165 + struct strvec extra_index_pack_args = STRVEC_INIT;
166 int ret;
167
168 + if (transport->progress)
169 + strvec_push(&extra_index_pack_args, "-v");
170 +
171 if (!data->get_refs_from_bundle_called)
172 get_refs_from_bundle(transport, 0, NULL);
173 ret = unbundle(the_repository, &data->header, data->fd,
170 - transport->progress ? BUNDLE_VERBOSE : 0);
174 + &extra_index_pack_args);
175 transport->hash_algo = data->header.hash_algo;
176 return ret;
177 }