diff --git a/builtin/clone.c b/builtin/clone.c index 44037dd428..1532361ea0 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -572,7 +572,7 @@ static void update_remote_refs(const struct ref *refs, opt.transport = transport; opt.progress = transport->progress; - if (check_connected(iterate_ref_map, &rm, &opt)) + if (check_connected(the_repository, iterate_ref_map, &rm, &opt)) die(_("remote did not send all necessary objects")); } diff --git a/builtin/fetch.c b/builtin/fetch.c index b2decc6cfd..0ef7fe92f1 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1250,7 +1250,8 @@ static int store_updated_refs(struct display_state *display_state, opt.exclude_hidden_refs_section = "fetch"; rm = ref_map; - if (check_connected(iterate_ref_map, &rm, &opt)) { + if (check_connected(the_repository, iterate_ref_map, + &rm, &opt)) { rc = error(_("%s did not send all necessary objects"), display_state->url); goto abort; @@ -1422,7 +1423,7 @@ static int check_exist_and_connected(struct ref *ref_map) opt.quiet = 1; opt.exclude_hidden_refs_section = "fetch"; - return check_connected(iterate_ref_map, &rm, &opt); + return check_connected(the_repository, iterate_ref_map, &rm, &opt); } static int fetch_and_consume_refs(struct display_state *display_state, diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 1d5b050beb..4f8f58950a 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1385,7 +1385,8 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si) oid_array_append(&extra, &si->shallow->oid[i]); setup_alternate_shallow(&shallow_lock, &opt.shallow_file, &extra); - if (check_connected(command_singleton_iterator, cmd, &opt)) { + if (check_connected(the_repository, command_singleton_iterator, + cmd, &opt)) { rollback_shallow_file(the_repository, &shallow_lock); oid_array_clear(&extra); return -1; @@ -1827,8 +1828,9 @@ static void set_connectivity_errors(struct command *commands, odb_transaction_env(transaction, &env); opt.env = env.v; - if (!check_connected(command_singleton_iterator, &singleton, - &opt)) + if (!check_connected(the_repository, + command_singleton_iterator, + &singleton, &opt)) continue; cmd->error_string = "missing necessary objects"; @@ -2090,7 +2092,9 @@ static void execute_commands(struct command *commands, opt.env = env.v; opt.exclude_hidden_refs_section = "receive"; - if (check_connected(iterate_receive_command_list, &data, &opt)) + if (check_connected(the_repository, + iterate_receive_command_list, + &data, &opt)) set_connectivity_errors(commands, si, transaction); if (use_sideband) diff --git a/bundle.c b/bundle.c index f55a521b2a..0a68e856f5 100644 --- a/bundle.c +++ b/bundle.c @@ -259,7 +259,7 @@ int verify_bundle(struct repository *r, if (ret) goto cleanup; - if ((ret = check_connected(iterate_ref_map, &iter, &opts))) + if ((ret = check_connected(r, iterate_ref_map, &iter, &opts))) error(_("some prerequisite commits exist in the object store, " "but are not connected to the repository's history")); diff --git a/connected.c b/connected.c index 929b9bd28d..34045f1032 100644 --- a/connected.c +++ b/connected.c @@ -1,5 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "gettext.h" #include "hex.h" @@ -35,23 +33,24 @@ static int promised_object_cb(const struct object_id *oid UNUSED, * objects in non-promisor packs, in which case we'll have to fall back to the * rev-list-based connectivity checks. Returns a negative error code on error. */ -static int check_connected_promisor(oid_iterate_fn fn, +static int check_connected_promisor(struct repository *repo, + oid_iterate_fn fn, void *cb_data, const struct object_id **oid) { struct odb_for_each_object_options opts = { .flags = ODB_FOR_EACH_OBJECT_PROMISOR_ONLY, - .prefix_hex_len = the_repository->hash_algo->hexsz, + .prefix_hex_len = repo->hash_algo->hexsz, }; int err; - odb_reprepare(the_repository->objects); + odb_reprepare(repo->objects); do { bool found = false; opts.prefix = *oid; - err = odb_for_each_object_ext(the_repository->objects, NULL, + err = odb_for_each_object_ext(repo->objects, NULL, promised_object_cb, &found, &opts); if (err < 0) return err; @@ -78,7 +77,8 @@ static int check_connected_promisor(oid_iterate_fn fn, * * Returns 0 if everything is connected, non-zero otherwise. */ -int check_connected(oid_iterate_fn fn, void *cb_data, +int check_connected(struct repository *repo, + oid_iterate_fn fn, void *cb_data, struct check_connected_options *opt) { struct child_process rev_list = CHILD_PROCESS_INIT; @@ -101,8 +101,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data, return err; } - if (repo_has_promisor_remote(the_repository)) { - err = check_connected_promisor(fn, cb_data, &oid); + if (repo_has_promisor_remote(repo)) { + err = check_connected_promisor(repo, fn, cb_data, &oid); if (err) { if (opt->err_fd) close(opt->err_fd); @@ -119,7 +119,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data, strvec_push(&rev_list.args,"rev-list"); strvec_push(&rev_list.args, "--objects"); strvec_push(&rev_list.args, "--stdin"); - if (repo_has_promisor_remote(the_repository)) + if (repo_has_promisor_remote(repo)) strvec_push(&rev_list.args, "--exclude-promisor-objects"); if (!opt->is_deepening_fetch) { strvec_push(&rev_list.args, "--not"); @@ -160,7 +160,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data, strbuf_add(&idx_file, transport->pack_lockfiles.items[0].string, base_len); strbuf_addstr(&idx_file, ".idx"); - new_pack = add_packed_git(the_repository, idx_file.buf, + new_pack = add_packed_git(repo, idx_file.buf, idx_file.len, 1); strbuf_release(&idx_file); } diff --git a/connected.h b/connected.h index 16b2c84f2e..0624965baa 100644 --- a/connected.h +++ b/connected.h @@ -2,6 +2,7 @@ #define CONNECTED_H struct object_id; +struct repository; struct transport; /* @@ -66,7 +67,8 @@ struct check_connected_options { * * If "opt" is NULL, behaves as if CHECK_CONNECTED_INIT was passed. */ -int check_connected(oid_iterate_fn fn, void *cb_data, +int check_connected(struct repository *repo, + oid_iterate_fn fn, void *cb_data, struct check_connected_options *opt); #endif /* CONNECTED_H */ diff --git a/fetch-pack.c b/fetch-pack.c index 30a4dd6119..2cf8f8d653 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -2186,7 +2186,8 @@ struct ref *fetch_pack(struct fetch_pack_args *args, opt.shallow_file = alternate_shallow_file; if (args->deepen) opt.is_deepening_fetch = 1; - if (check_connected(iterate_ref_map, &iterator, &opt)) { + if (check_connected(the_repository, iterate_ref_map, + &iterator, &opt)) { error(_("remote did not send all necessary objects")); free_refs(ref_cpy); ref_cpy = NULL;