connected: drop dependency on the_repository
The next commits will need to use the repository to read configuration in check_connected(). Rather than accessing `the_repository`, refactor the code to instead require the caller to pass in a repository so that we can remove `USE_THE_REPOSITORY_VARIABLE`. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Kristofer Karlsson <krka@spotify.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
1 parent
97998dcfd1
commit
d6d2d8557c
7 files changed
+29
-21
No files matched your search
+1
-1
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"));
|
||||
|
||||
|
||||
+11
-11
@@ -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);
|
||||
}
|
||||
|
||||
+3
-1
@@ -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 */
|
||||
+2
-1
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user