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
maint
Junio C Hamano 2024-12-13 07:33:36 -08:00
commit a32668829d
8 changed files with 89 additions and 20 deletions

View File

@ -222,7 +222,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix,
strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
_("Unbundling objects"), NULL);
ret = !!unbundle(the_repository, &header, bundle_fd,
&extra_index_pack_args, 0) ||
&extra_index_pack_args, NULL) ||
list_bundle_refs(&header, argc, argv);
bundle_header_release(&header);


View File

@ -367,6 +367,10 @@ static int unbundle_from_file(struct repository *r, const char *file)
struct string_list_item *refname;
struct strbuf bundle_ref = STRBUF_INIT;
size_t bundle_prefix_len;
struct unbundle_opts opts = {
.flags = VERIFY_BUNDLE_QUIET |
(fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0),
};

bundle_fd = read_bundle_header(file, &header);
if (bundle_fd < 0) {
@ -379,8 +383,7 @@ static int unbundle_from_file(struct repository *r, const char *file)
* a reachable ref pointing to the new tips, which will reach
* the prerequisite commits.
*/
result = unbundle(r, &header, bundle_fd, NULL,
VERIFY_BUNDLE_QUIET | (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0));
result = unbundle(r, &header, bundle_fd, NULL, &opts);
if (result) {
result = 1;
goto cleanup;

View File

@ -628,11 +628,15 @@ out:

int unbundle(struct repository *r, struct bundle_header *header,
int bundle_fd, struct strvec *extra_index_pack_args,
enum verify_bundle_flags flags)
struct unbundle_opts *opts)
{
struct child_process ip = CHILD_PROCESS_INIT;
struct unbundle_opts opts_fallback = { 0 };

if (verify_bundle(r, header, flags))
if (!opts)
opts = &opts_fallback;

if (verify_bundle(r, header, opts->flags))
return -1;

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

if (flags & VERIFY_BUNDLE_FSCK)
strvec_push(&ip.args, "--fsck-objects");
if (opts->flags & VERIFY_BUNDLE_FSCK)
strvec_pushf(&ip.args, "--fsck-objects%s",
opts->fsck_msg_types ? opts->fsck_msg_types : "");

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

View File

@ -39,6 +39,17 @@ enum verify_bundle_flags {
int verify_bundle(struct repository *r, struct bundle_header *header,
enum verify_bundle_flags flags);

struct unbundle_opts {
enum verify_bundle_flags flags;
/*
* fsck_msg_types may optionally contain fsck message severity
* configuration. If present, this configuration gets directly appended
* to a '--fsck-objects' option and therefore must be prefixed with '='.
* (E.g. "=missingEmail=ignore,gitmodulesUrl=ignore")
*/
const char *fsck_msg_types;
};

/**
* Unbundle after reading the header with read_bundle_header().
*
@ -49,12 +60,12 @@ int verify_bundle(struct repository *r, struct bundle_header *header,
* (e.g. "-v" for verbose/progress), NULL otherwise. The provided
* "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
*
* Before unbundling, this method will call verify_bundle() with the
* given 'flags'.
* Before unbundling, this method will call verify_bundle() with 'flags'
* provided in 'opts'.
*/
int unbundle(struct repository *r, struct bundle_header *header,
int bundle_fd, struct strvec *extra_index_pack_args,
enum verify_bundle_flags flags);
struct unbundle_opts *opts);
int list_bundle_refs(struct bundle_header *header,
int argc, const char **argv);


View File

@ -1857,8 +1857,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
return ref;
}

static int fetch_pack_config_cb(const char *var, const char *value,
const struct config_context *ctx, void *cb)
int fetch_pack_fsck_config(const char *var, const char *value,
struct strbuf *msg_types)
{
const char *msg_id;

@ -1866,9 +1866,9 @@ static int fetch_pack_config_cb(const char *var, const char *value,
char *path ;

if (git_config_pathname(&path, var, value))
return 1;
strbuf_addf(&fsck_msg_types, "%cskiplist=%s",
fsck_msg_types.len ? ',' : '=', path);
return 0;
strbuf_addf(msg_types, "%cskiplist=%s",
msg_types->len ? ',' : '=', path);
free(path);
return 0;
}
@ -1877,14 +1877,24 @@ static int fetch_pack_config_cb(const char *var, const char *value,
if (!value)
return config_error_nonbool(var);
if (is_valid_msg_type(msg_id, value))
strbuf_addf(&fsck_msg_types, "%c%s=%s",
fsck_msg_types.len ? ',' : '=', msg_id, value);
strbuf_addf(msg_types, "%c%s=%s",
msg_types->len ? ',' : '=', msg_id, value);
else
warning("Skipping unknown msg id '%s'", msg_id);
return 0;
}

return git_default_config(var, value, ctx, cb);
return 1;
}

static int fetch_pack_config_cb(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
int ret = fetch_pack_fsck_config(var, value, &fsck_msg_types);
if (ret > 0)
return git_default_config(var, value, ctx, cb);

return ret;
}

static void fetch_pack_config(void)

View File

@ -106,4 +106,15 @@ int report_unmatched_refs(struct ref **sought, int nr_sought);
*/
int fetch_pack_fsck_objects(void);

/*
* Check if the provided config variable pertains to fetch fsck and if so append
* the configuration to the provided strbuf.
*
* When a fetch fsck config option is successfully processed the function
* returns 0. If the provided config option is unrelated to fetch fsck, 1 is
* returned. Errors return -1.
*/
int fetch_pack_fsck_config(const char *var, const char *value,
struct strbuf *msg_types);

#endif

View File

@ -170,6 +170,13 @@ test_expect_success 'clone bundle with different fsckObjects configurations' '

test_must_fail git -c transfer.fsckObjects=true \
clone bundle-fsck/bad.bundle bundle-transfer-fsck 2>err &&
test_grep "missingEmail" err &&

git -c fetch.fsckObjects=true -c fetch.fsck.missingEmail=ignore \
clone bundle-fsck/bad.bundle bundle-fsck-ignore &&

test_must_fail git -c fetch.fsckObjects=true -c fetch.fsck.missingEmail=error \
clone bundle-fsck/bad.bundle bundle-fsck-error 2>err &&
test_grep "missingEmail" err
'


View File

@ -19,6 +19,7 @@
#include "branch.h"
#include "url.h"
#include "submodule.h"
#include "strbuf.h"
#include "string-list.h"
#include "oid-array.h"
#include "sigchain.h"
@ -172,12 +173,29 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
return result;
}

static int fetch_fsck_config_cb(const char *var, const char *value,
const struct config_context *ctx UNUSED, void *cb)
{
struct strbuf *msg_types = cb;
int ret;

ret = fetch_pack_fsck_config(var, value, msg_types);
if (ret > 0)
return 0;

return ret;
}

static int fetch_refs_from_bundle(struct transport *transport,
int nr_heads UNUSED,
struct ref **to_fetch UNUSED)
{
struct unbundle_opts opts = {
.flags = fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0,
};
struct bundle_transport_data *data = transport->data;
struct strvec extra_index_pack_args = STRVEC_INIT;
struct strbuf msg_types = STRBUF_INIT;
int ret;

if (transport->progress)
@ -185,12 +203,16 @@ static int fetch_refs_from_bundle(struct transport *transport,

if (!data->get_refs_from_bundle_called)
get_refs_from_bundle_inner(transport);

git_config(fetch_fsck_config_cb, &msg_types);
opts.fsck_msg_types = msg_types.buf;

ret = unbundle(the_repository, &data->header, data->fd,
&extra_index_pack_args,
fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0);
&extra_index_pack_args, &opts);
transport->hash_algo = data->header.hash_algo;

strvec_clear(&extra_index_pack_args);
strbuf_release(&msg_types);
return ret;
}