Skip to content

Commit 6da6f0b

Browse files
committed
Merge branch 'jt/bundle-fsck' into jch
"git bundle --unbundle" and "git clone" running on a bundle file both learned to trigger fsck over the new objects with configurable fck check levels. * jt/bundle-fsck: transport: propagate fsck configuration during bundle fetch fetch-pack: expose `fetch_pack_config_cb()` fetch-pack: introduce `fetch_pack_options` bundle: support fsck message configuration bundle: add bundle verification options type
2 parents 9ecb1ea + 3749cce commit 6da6f0b

File tree

8 files changed

+69
-28
lines changed

8 files changed

+69
-28
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: 11 additions & 6 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,8 +645,9 @@ 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)
645-
strvec_push(&ip.args, "--fsck-objects");
648+
if (opts.flags & VERIFY_BUNDLE_FSCK)
649+
strvec_pushf(&ip.args, "--fsck-objects%s",
650+
opts.fsck_msg_types ? opts.fsck_msg_types : "");
646651

647652
if (extra_index_pack_args)
648653
strvec_pushv(&ip.args, extra_index_pack_args->v);

bundle.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ 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+
const char *fsck_msg_types;
45+
};
46+
4247
/**
4348
* Unbundle after reading the header with read_bundle_header().
4449
*
@@ -49,12 +54,12 @@ int verify_bundle(struct repository *r, struct bundle_header *header,
4954
* (e.g. "-v" for verbose/progress), NULL otherwise. The provided
5055
* "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
5156
*
52-
* Before unbundling, this method will call verify_bundle() with the
53-
* given 'flags'.
57+
* Before unbundling, this method will call verify_bundle() with 'flags'
58+
* provided in 'opts'.
5459
*/
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);
60+
int unbundle(struct repository *r, struct bundle_header *header, int bundle_fd,
61+
struct strvec *extra_index_pack_args,
62+
struct verify_bundle_opts *opts);
5863
int list_bundle_refs(struct bundle_header *header,
5964
int argc, const char **argv);
6065

fetch-pack.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static int server_supports_filtering;
4848
static int advertise_sid;
4949
static struct shallow_lock shallow_lock;
5050
static const char *alternate_shallow_file;
51+
static struct fetch_pack_options fetch_pack_options = FETCH_PACK_OPTIONS_INIT;
5152
static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
52-
static struct strbuf fsck_msg_types = STRBUF_INIT;
5353
static struct string_list uri_protocols = STRING_LIST_INIT_DUP;
5454

5555
/* Remember to update object flag allocation in object.h */
@@ -1017,7 +1017,7 @@ static int get_pack(struct fetch_pack_args *args,
10171017
strvec_push(&cmd.args, "--fsck-objects");
10181018
else
10191019
strvec_pushf(&cmd.args, "--strict%s",
1020-
fsck_msg_types.buf);
1020+
fetch_pack_options.fsck_msg_types.buf);
10211021
}
10221022

10231023
if (index_pack_args) {
@@ -1828,18 +1828,19 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18281828
return ref;
18291829
}
18301830

1831-
static int fetch_pack_config_cb(const char *var, const char *value,
1832-
const struct config_context *ctx, void *cb)
1831+
int fetch_pack_config_cb(const char *var, const char *value,
1832+
const struct config_context *ctx, void *cb)
18331833
{
1834+
struct fetch_pack_options *opts = cb;
18341835
const char *msg_id;
18351836

18361837
if (strcmp(var, "fetch.fsck.skiplist") == 0) {
18371838
char *path ;
18381839

18391840
if (git_config_pathname(&path, var, value))
18401841
return 1;
1841-
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
1842-
fsck_msg_types.len ? ',' : '=', path);
1842+
strbuf_addf(&opts->fsck_msg_types, "%cskiplist=%s",
1843+
opts->fsck_msg_types.len ? ',' : '=', path);
18431844
free(path);
18441845
return 0;
18451846
}
@@ -1848,8 +1849,9 @@ static int fetch_pack_config_cb(const char *var, const char *value,
18481849
if (!value)
18491850
return config_error_nonbool(var);
18501851
if (is_valid_msg_type(msg_id, value))
1851-
strbuf_addf(&fsck_msg_types, "%c%s=%s",
1852-
fsck_msg_types.len ? ',' : '=', msg_id, value);
1852+
strbuf_addf(&opts->fsck_msg_types, "%c%s=%s",
1853+
opts->fsck_msg_types.len ? ',' : '=',
1854+
msg_id, value);
18531855
else
18541856
warning("Skipping unknown msg id '%s'", msg_id);
18551857
return 0;
@@ -1875,7 +1877,7 @@ static void fetch_pack_config(void)
18751877
}
18761878
}
18771879

1878-
git_config(fetch_pack_config_cb, NULL);
1880+
git_config(fetch_pack_config_cb, &fetch_pack_options);
18791881
}
18801882

18811883
static void fetch_pack_setup(void)

fetch-pack.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef FETCH_PACK_H
22
#define FETCH_PACK_H
33

4+
#include "config.h"
45
#include "string-list.h"
56
#include "protocol.h"
67
#include "list-objects-filter-options.h"
@@ -108,4 +109,15 @@ int report_unmatched_refs(struct ref **sought, int nr_sought);
108109
*/
109110
int fetch_pack_fsck_objects(void);
110111

112+
struct fetch_pack_options {
113+
struct strbuf fsck_msg_types;
114+
};
115+
116+
#define FETCH_PACK_OPTIONS_INIT { \
117+
.fsck_msg_types = STRBUF_INIT, \
118+
}
119+
120+
int fetch_pack_config_cb(const char *var, const char *value,
121+
const struct config_context *ctx, void *cb);
122+
111123
#endif

t/t5607-clone-bundle.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ test_expect_success 'clone bundle with different fsckObjects configurations' '
170170
171171
test_must_fail git -c transfer.fsckObjects=true \
172172
clone bundle-fsck/bad.bundle bundle-transfer-fsck 2>err &&
173+
test_grep "missingEmail" err &&
174+
175+
git -c fetch.fsckObjects=true -c fetch.fsck.missingEmail=ignore \
176+
clone bundle-fsck/bad.bundle bundle-fsck-ignore &&
177+
178+
test_must_fail git -c fetch.fsckObjects=true -c fetch.fsck.missingEmail=error \
179+
clone bundle-fsck/bad.bundle bundle-fsck-error 2>err &&
173180
test_grep "missingEmail" err
174181
'
175182

transport.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ static int fetch_refs_from_bundle(struct transport *transport,
177177
int nr_heads UNUSED,
178178
struct ref **to_fetch UNUSED)
179179
{
180+
struct verify_bundle_opts opts = { .flags = fetch_pack_fsck_objects() ?
181+
VERIFY_BUNDLE_FSCK : 0 };
182+
struct fetch_pack_options fetch_pack_options = FETCH_PACK_OPTIONS_INIT;
180183
struct bundle_transport_data *data = transport->data;
181184
struct strvec extra_index_pack_args = STRVEC_INIT;
182185
int ret;
@@ -186,12 +189,16 @@ static int fetch_refs_from_bundle(struct transport *transport,
186189

187190
if (!data->get_refs_from_bundle_called)
188191
get_refs_from_bundle_inner(transport);
192+
193+
git_config(fetch_pack_config_cb, &fetch_pack_options);
194+
opts.fsck_msg_types = fetch_pack_options.fsck_msg_types.buf;
195+
189196
ret = unbundle(the_repository, &data->header, data->fd,
190-
&extra_index_pack_args,
191-
fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
197+
&extra_index_pack_args, &opts);
192198
transport->hash_algo = data->header.hash_algo;
193199

194200
strvec_clear(&extra_index_pack_args);
201+
strbuf_release(&fetch_pack_options.fsck_msg_types);
195202
return ret;
196203
}
197204

0 commit comments

Comments
 (0)