Skip to content

Commit 972000e

Browse files
jltoblergitster
authored andcommitted
bundle: add bundle verification options type
Bundle verification performed as part of `unbundle()` is configurable via providing `verify_bundle_flags`. This is done by invoking `verify_bundle()` and propagating the set flags. If the `VERIFY_BUNDLE_FSCK` flag is provided, the `fsck-objects` flag is specified when invoking git-index-pack(1) to perform fsck checks on the objects in the bundle. Introduce a new type, `verify_bundle_opts`, and update `unbundle()` to accept this instead of `verify_bundle_flags` to perform the same verification configuration. In a subsequent commit, `verify_bundle_opts` will be extended to support configuration of fsck message severity. Signed-off-by: Justin Tobler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4083a6f commit 972000e

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

builtin/bundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix)
218218
strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
219219
_("Unbundling objects"), NULL);
220220
ret = !!unbundle(the_repository, &header, bundle_fd,
221-
&extra_index_pack_args, 0) ||
221+
&extra_index_pack_args, NULL) ||
222222
list_bundle_refs(&header, argc, argv);
223223
bundle_header_release(&header);
224224

bundle-uri.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,16 @@ static int copy_uri_to_file(const char *filename, const char *uri)
361361

362362
static int unbundle_from_file(struct repository *r, const char *file)
363363
{
364-
int result = 0;
365-
int bundle_fd;
364+
struct verify_bundle_opts opts = {
365+
.flags = VERIFY_BUNDLE_QUIET |
366+
(fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0)
367+
};
366368
struct bundle_header header = BUNDLE_HEADER_INIT;
367-
struct string_list_item *refname;
368369
struct strbuf bundle_ref = STRBUF_INIT;
370+
struct string_list_item *refname;
369371
size_t bundle_prefix_len;
372+
int result = 0;
373+
int bundle_fd;
370374

371375
bundle_fd = read_bundle_header(file, &header);
372376
if (bundle_fd < 0) {
@@ -379,8 +383,7 @@ static int unbundle_from_file(struct repository *r, const char *file)
379383
* a reachable ref pointing to the new tips, which will reach
380384
* the prerequisite commits.
381385
*/
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);
384387
if (result) {
385388
result = 1;
386389
goto cleanup;

bundle.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,17 @@ int create_bundle(struct repository *r, const char *path,
626626
return ret;
627627
}
628628

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)
629+
int unbundle(struct repository *r, struct bundle_header *header, int bundle_fd,
630+
struct strvec *extra_index_pack_args,
631+
struct verify_bundle_opts *_opts)
632632
{
633633
struct child_process ip = CHILD_PROCESS_INIT;
634+
struct verify_bundle_opts opts = { 0 };
634635

635-
if (verify_bundle(r, header, flags))
636+
if (_opts)
637+
opts = *_opts;
638+
639+
if (verify_bundle(r, header, opts.flags))
636640
return -1;
637641

638642
strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
@@ -641,7 +645,7 @@ int unbundle(struct repository *r, struct bundle_header *header,
641645
if (header->filter.choice)
642646
strvec_push(&ip.args, "--promisor=from-bundle");
643647

644-
if (flags & VERIFY_BUNDLE_FSCK)
648+
if (opts.flags & VERIFY_BUNDLE_FSCK)
645649
strvec_push(&ip.args, "--fsck-objects");
646650

647651
if (extra_index_pack_args)

bundle.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ enum verify_bundle_flags {
3939
int verify_bundle(struct repository *r, struct bundle_header *header,
4040
enum verify_bundle_flags flags);
4141

42+
struct verify_bundle_opts {
43+
enum verify_bundle_flags flags;
44+
};
45+
4246
/**
4347
* Unbundle after reading the header with read_bundle_header().
4448
*
@@ -49,12 +53,12 @@ int verify_bundle(struct repository *r, struct bundle_header *header,
4953
* (e.g. "-v" for verbose/progress), NULL otherwise. The provided
5054
* "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
5155
*
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'.
5458
*/
55-
int unbundle(struct repository *r, struct bundle_header *header,
56-
int bundle_fd, struct strvec *extra_index_pack_args,
57-
enum verify_bundle_flags flags);
59+
int unbundle(struct repository *r, struct bundle_header *header, int bundle_fd,
60+
struct strvec *extra_index_pack_args,
61+
struct verify_bundle_opts *opts);
5862
int list_bundle_refs(struct bundle_header *header,
5963
int argc, const char **argv);
6064

transport.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ static int fetch_refs_from_bundle(struct transport *transport,
176176
int nr_heads UNUSED,
177177
struct ref **to_fetch UNUSED)
178178
{
179+
struct verify_bundle_opts opts = { .flags = fetch_pack_fsck_objects() ?
180+
VERIFY_BUNDLE_FSCK : 0 };
179181
struct bundle_transport_data *data = transport->data;
180182
struct strvec extra_index_pack_args = STRVEC_INIT;
181183
int ret;
@@ -185,9 +187,9 @@ static int fetch_refs_from_bundle(struct transport *transport,
185187

186188
if (!data->get_refs_from_bundle_called)
187189
get_refs_from_bundle_inner(transport);
190+
188191
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);
191193
transport->hash_algo = data->header.hash_algo;
192194

193195
strvec_clear(&extra_index_pack_args);

0 commit comments

Comments
 (0)