Skip to content

Commit a326688

Browse files
committed
Merge branch 'jt/bundle-fsck'
"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 caacdb5 + baa1591 commit a326688

File tree

8 files changed

+89
-20
lines changed

8 files changed

+89
-20
lines changed

builtin/bundle.c

+1-1
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

+5-2
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

+9-4
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

+14-3
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

+18-8
Original file line numberDiff line numberDiff line change
@@ -1857,18 +1857,18 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18571857
return ref;
18581858
}
18591859

1860-
static int fetch_pack_config_cb(const char *var, const char *value,
1861-
const struct config_context *ctx, void *cb)
1860+
int fetch_pack_fsck_config(const char *var, const char *value,
1861+
struct strbuf *msg_types)
18621862
{
18631863
const char *msg_id;
18641864

18651865
if (strcmp(var, "fetch.fsck.skiplist") == 0) {
18661866
char *path ;
18671867

18681868
if (git_config_pathname(&path, var, value))
1869-
return 1;
1870-
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
1871-
fsck_msg_types.len ? ',' : '=', path);
1869+
return 0;
1870+
strbuf_addf(msg_types, "%cskiplist=%s",
1871+
msg_types->len ? ',' : '=', path);
18721872
free(path);
18731873
return 0;
18741874
}
@@ -1877,14 +1877,24 @@ static int fetch_pack_config_cb(const char *var, const char *value,
18771877
if (!value)
18781878
return config_error_nonbool(var);
18791879
if (is_valid_msg_type(msg_id, value))
1880-
strbuf_addf(&fsck_msg_types, "%c%s=%s",
1881-
fsck_msg_types.len ? ',' : '=', msg_id, value);
1880+
strbuf_addf(msg_types, "%c%s=%s",
1881+
msg_types->len ? ',' : '=', msg_id, value);
18821882
else
18831883
warning("Skipping unknown msg id '%s'", msg_id);
18841884
return 0;
18851885
}
18861886

1887-
return git_default_config(var, value, ctx, cb);
1887+
return 1;
1888+
}
1889+
1890+
static int fetch_pack_config_cb(const char *var, const char *value,
1891+
const struct config_context *ctx, void *cb)
1892+
{
1893+
int ret = fetch_pack_fsck_config(var, value, &fsck_msg_types);
1894+
if (ret > 0)
1895+
return git_default_config(var, value, ctx, cb);
1896+
1897+
return ret;
18881898
}
18891899

18901900
static void fetch_pack_config(void)

fetch-pack.h

+11
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,15 @@ int report_unmatched_refs(struct ref **sought, int nr_sought);
106106
*/
107107
int fetch_pack_fsck_objects(void);
108108

109+
/*
110+
* Check if the provided config variable pertains to fetch fsck and if so append
111+
* the configuration to the provided strbuf.
112+
*
113+
* When a fetch fsck config option is successfully processed the function
114+
* returns 0. If the provided config option is unrelated to fetch fsck, 1 is
115+
* returned. Errors return -1.
116+
*/
117+
int fetch_pack_fsck_config(const char *var, const char *value,
118+
struct strbuf *msg_types);
119+
109120
#endif

t/t5607-clone-bundle.sh

+7
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

+24-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "branch.h"
2020
#include "url.h"
2121
#include "submodule.h"
22+
#include "strbuf.h"
2223
#include "string-list.h"
2324
#include "oid-array.h"
2425
#include "sigchain.h"
@@ -172,25 +173,46 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
172173
return result;
173174
}
174175

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

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

186204
if (!data->get_refs_from_bundle_called)
187205
get_refs_from_bundle_inner(transport);
206+
207+
git_config(fetch_fsck_config_cb, &msg_types);
208+
opts.fsck_msg_types = msg_types.buf;
209+
188210
ret = unbundle(the_repository, &data->header, data->fd,
189-
&extra_index_pack_args,
190-
fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
211+
&extra_index_pack_args, &opts);
191212
transport->hash_algo = data->header.hash_algo;
192213

193214
strvec_clear(&extra_index_pack_args);
215+
strbuf_release(&msg_types);
194216
return ret;
195217
}
196218

0 commit comments

Comments
 (0)