Skip to content

Commit fd4d1af

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: split out fsck config parsing bundle: support fsck message configuration bundle: add bundle verification options type
2 parents 9b63876 + 852919a commit fd4d1af

File tree

8 files changed

+80
-19
lines changed

8 files changed

+80
-19
lines changed

builtin/bundle.c

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

bundle-uri.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ static int unbundle_from_file(struct repository *r, const char *file)
367367
struct string_list_item *refname;
368368
struct strbuf bundle_ref = STRBUF_INIT;
369369
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+
};
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,15 @@ int create_bundle(struct repository *r, const char *path,
628628

629629
int unbundle(struct repository *r, struct bundle_header *header,
630630
int bundle_fd, struct strvec *extra_index_pack_args,
631-
enum verify_bundle_flags flags)
631+
struct unbundle_opts *opts)
632632
{
633633
struct child_process ip = CHILD_PROCESS_INIT;
634+
struct unbundle_opts opts_fallback = { 0 };
634635

635-
if (verify_bundle(r, header, flags))
636+
if (!opts)
637+
opts = &opts_fallback;
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: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ enum verify_bundle_flags {
3939
int verify_bundle(struct repository *r, struct bundle_header *header,
4040
enum verify_bundle_flags flags);
4141

42+
struct unbundle_opts {
43+
enum verify_bundle_flags flags;
44+
/**
45+
* fsck_msg_types may optionally contain fsck message severity
46+
* configuration. If present, this configuration gets directly appended
47+
* to a '--fsck-objects' option and therefore must be prefixed with '='.
48+
* (E.g. "=missingEmail=ignore,gitmodulesUrl=ignore")
49+
*/
50+
const char *fsck_msg_types;
51+
};
52+
4253
/**
4354
* Unbundle after reading the header with read_bundle_header().
4455
*
@@ -49,12 +60,12 @@ int verify_bundle(struct repository *r, struct bundle_header *header,
4960
* (e.g. "-v" for verbose/progress), NULL otherwise. The provided
5061
* "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
5162
*
52-
* Before unbundling, this method will call verify_bundle() with the
53-
* given 'flags'.
63+
* Before unbundling, this method will call verify_bundle() with 'flags'
64+
* provided in 'opts'.
5465
*/
5566
int unbundle(struct repository *r, struct bundle_header *header,
5667
int bundle_fd, struct strvec *extra_index_pack_args,
57-
enum verify_bundle_flags flags);
68+
struct unbundle_opts *opts);
5869
int list_bundle_refs(struct bundle_header *header,
5970
int argc, const char **argv);
6071

fetch-pack.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,8 +1828,8 @@ 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_fsck_config(const char *var, const char *value,
1832+
struct strbuf *msg_types)
18331833
{
18341834
const char *msg_id;
18351835

@@ -1838,8 +1838,8 @@ static int fetch_pack_config_cb(const char *var, const char *value,
18381838

18391839
if (git_config_pathname(&path, var, value))
18401840
return 1;
1841-
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
1842-
fsck_msg_types.len ? ',' : '=', path);
1841+
strbuf_addf(msg_types, "%cskiplist=%s",
1842+
msg_types->len ? ',' : '=', path);
18431843
free(path);
18441844
return 0;
18451845
}
@@ -1848,14 +1848,24 @@ static int fetch_pack_config_cb(const char *var, const char *value,
18481848
if (!value)
18491849
return config_error_nonbool(var);
18501850
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);
1851+
strbuf_addf(msg_types, "%c%s=%s",
1852+
msg_types->len ? ',' : '=', msg_id, value);
18531853
else
18541854
warning("Skipping unknown msg id '%s'", msg_id);
18551855
return 0;
18561856
}
18571857

1858-
return git_default_config(var, value, ctx, cb);
1858+
return -1;
1859+
}
1860+
1861+
static int fetch_pack_config_cb(const char *var, const char *value,
1862+
const struct config_context *ctx, void *cb)
1863+
{
1864+
int ret = fetch_pack_fsck_config(var, value, &fsck_msg_types);
1865+
if (ret < 0)
1866+
return git_default_config(var, value, ctx, cb);
1867+
1868+
return ret;
18591869
}
18601870

18611871
static void fetch_pack_config(void)

fetch-pack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,7 @@ int report_unmatched_refs(struct ref **sought, int nr_sought);
108108
*/
109109
int fetch_pack_fsck_objects(void);
110110

111+
int fetch_pack_fsck_config(const char *var, const char *value,
112+
struct strbuf *msg_types);
113+
111114
#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: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "branch.h"
2121
#include "url.h"
2222
#include "submodule.h"
23+
#include "strbuf.h"
2324
#include "string-list.h"
2425
#include "oid-array.h"
2526
#include "sigchain.h"
@@ -173,25 +174,46 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
173174
return result;
174175
}
175176

177+
static int fetch_fsck_config_cb(const char *var, const char *value,
178+
const struct config_context *ctx UNUSED, void *cb)
179+
{
180+
struct strbuf *msg_types = cb;
181+
int ret;
182+
183+
ret = fetch_pack_fsck_config(var, value, msg_types);
184+
if (ret < 0)
185+
return 0;
186+
187+
return ret;
188+
}
189+
176190
static int fetch_refs_from_bundle(struct transport *transport,
177191
int nr_heads UNUSED,
178192
struct ref **to_fetch UNUSED)
179193
{
194+
struct unbundle_opts opts = {
195+
.flags = fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0,
196+
};
180197
struct bundle_transport_data *data = transport->data;
181198
struct strvec extra_index_pack_args = STRVEC_INIT;
199+
struct strbuf msg_types = STRBUF_INIT;
182200
int ret;
183201

184202
if (transport->progress)
185203
strvec_push(&extra_index_pack_args, "-v");
186204

187205
if (!data->get_refs_from_bundle_called)
188206
get_refs_from_bundle_inner(transport);
207+
208+
git_config(fetch_fsck_config_cb, &msg_types);
209+
opts.fsck_msg_types = msg_types.buf;
210+
189211
ret = unbundle(the_repository, &data->header, data->fd,
190-
&extra_index_pack_args,
191-
fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
212+
&extra_index_pack_args, &opts);
192213
transport->hash_algo = data->header.hash_algo;
193214

194215
strvec_clear(&extra_index_pack_args);
216+
strbuf_release(&msg_types);
195217
return ret;
196218
}
197219

0 commit comments

Comments
 (0)