Merge branch 'sp/refs-reduce-the-repository'
Code clean-up to use the right instance of a repository instance in calls inside refs subsystem. * sp/refs-reduce-the-repository: refs/reftable-backend: drop uses of the_repository refs: remove the_hash_algo global state refs: add struct repository parameter in get_files_ref_lock_timeout_ms()main
commit
655096d1dc
17
refs.c
17
refs.c
|
|
@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,
|
||||||
return REF_WORKTREE_SHARED;
|
return REF_WORKTREE_SHARED;
|
||||||
}
|
}
|
||||||
|
|
||||||
long get_files_ref_lock_timeout_ms(void)
|
long get_files_ref_lock_timeout_ms(struct repository *repo)
|
||||||
{
|
{
|
||||||
static int configured = 0;
|
static int configured = 0;
|
||||||
|
|
||||||
|
|
@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)
|
||||||
static int timeout_ms = 100;
|
static int timeout_ms = 100;
|
||||||
|
|
||||||
if (!configured) {
|
if (!configured) {
|
||||||
repo_config_get_int(the_repository, "core.filesreflocktimeout", &timeout_ms);
|
repo_config_get_int(repo, "core.filesreflocktimeout", &timeout_ms);
|
||||||
configured = 1;
|
configured = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1472,7 +1472,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return ref_transaction_update(transaction, refname, new_oid,
|
return ref_transaction_update(transaction, refname, new_oid,
|
||||||
null_oid(the_hash_algo), new_target, NULL, flags,
|
null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,
|
||||||
msg, err);
|
msg, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1491,7 +1491,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
|
||||||
if (old_target && !(flags & REF_NO_DEREF))
|
if (old_target && !(flags & REF_NO_DEREF))
|
||||||
BUG("delete cannot operate on symrefs with deref mode");
|
BUG("delete cannot operate on symrefs with deref mode");
|
||||||
return ref_transaction_update(transaction, refname,
|
return ref_transaction_update(transaction, refname,
|
||||||
null_oid(the_hash_algo), old_oid,
|
null_oid(transaction->ref_store->repo->hash_algo), old_oid,
|
||||||
NULL, old_target, flags,
|
NULL, old_target, flags,
|
||||||
msg, err);
|
msg, err);
|
||||||
}
|
}
|
||||||
|
|
@ -2379,7 +2379,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
|
||||||
subrepo = xmalloc(sizeof(*subrepo));
|
subrepo = xmalloc(sizeof(*subrepo));
|
||||||
|
|
||||||
if (repo_submodule_init(subrepo, repo, submodule,
|
if (repo_submodule_init(subrepo, repo, submodule,
|
||||||
null_oid(the_hash_algo))) {
|
null_oid(repo->hash_algo))) {
|
||||||
free(subrepo);
|
free(subrepo);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
@ -2571,14 +2571,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_
|
||||||
strbuf_reset(buf);
|
strbuf_reset(buf);
|
||||||
|
|
||||||
if (!(update->flags & REF_HAVE_OLD))
|
if (!(update->flags & REF_HAVE_OLD))
|
||||||
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
|
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
|
||||||
else if (update->old_target)
|
else if (update->old_target)
|
||||||
strbuf_addf(buf, "ref:%s ", update->old_target);
|
strbuf_addf(buf, "ref:%s ", update->old_target);
|
||||||
else
|
else
|
||||||
strbuf_addf(buf, "%s ", oid_to_hex(&update->old_oid));
|
strbuf_addf(buf, "%s ", oid_to_hex(&update->old_oid));
|
||||||
|
|
||||||
if (!(update->flags & REF_HAVE_NEW))
|
if (!(update->flags & REF_HAVE_NEW))
|
||||||
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
|
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
|
||||||
else if (update->new_target)
|
else if (update->new_target)
|
||||||
strbuf_addf(buf, "ref:%s ", update->new_target);
|
strbuf_addf(buf, "ref:%s ", update->new_target);
|
||||||
else
|
else
|
||||||
|
|
@ -3146,6 +3146,7 @@ struct migration_data {
|
||||||
static int migrate_one_ref(const struct reference *ref, void *cb_data)
|
static int migrate_one_ref(const struct reference *ref, void *cb_data)
|
||||||
{
|
{
|
||||||
struct migration_data *data = cb_data;
|
struct migration_data *data = cb_data;
|
||||||
|
const struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;
|
||||||
struct strbuf symref_target = STRBUF_INIT;
|
struct strbuf symref_target = STRBUF_INIT;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
@ -3154,7 +3155,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),
|
ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),
|
||||||
symref_target.buf, NULL,
|
symref_target.buf, NULL,
|
||||||
REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
|
REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|
|
||||||
|
|
@ -792,7 +792,7 @@ retry:
|
||||||
|
|
||||||
if (hold_lock_file_for_update_timeout(
|
if (hold_lock_file_for_update_timeout(
|
||||||
&lock->lk, ref_file.buf, LOCK_NO_DEREF,
|
&lock->lk, ref_file.buf, LOCK_NO_DEREF,
|
||||||
get_files_ref_lock_timeout_ms()) < 0) {
|
get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {
|
||||||
int myerr = errno;
|
int myerr = errno;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (myerr == ENOENT && --attempts_remaining > 0) {
|
if (myerr == ENOENT && --attempts_remaining > 0) {
|
||||||
|
|
@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)
|
||||||
return remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);
|
return remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct create_reflock_cb {
|
||||||
|
struct lock_file *lk;
|
||||||
|
struct repository *repo;
|
||||||
|
};
|
||||||
|
|
||||||
static int create_reflock(const char *path, void *cb)
|
static int create_reflock(const char *path, void *cb)
|
||||||
{
|
{
|
||||||
struct lock_file *lk = cb;
|
struct create_reflock_cb *data = cb;
|
||||||
|
|
||||||
return hold_lock_file_for_update_timeout(
|
return hold_lock_file_for_update_timeout(
|
||||||
lk, path, LOCK_NO_DEREF,
|
data->lk, path, LOCK_NO_DEREF,
|
||||||
get_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;
|
get_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
|
||||||
{
|
{
|
||||||
struct strbuf ref_file = STRBUF_INIT;
|
struct strbuf ref_file = STRBUF_INIT;
|
||||||
struct ref_lock *lock;
|
struct ref_lock *lock;
|
||||||
|
struct create_reflock_cb cb_data;
|
||||||
|
|
||||||
files_assert_main_repository(refs, "lock_ref_oid_basic");
|
files_assert_main_repository(refs, "lock_ref_oid_basic");
|
||||||
assert(err);
|
assert(err);
|
||||||
|
|
@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
|
||||||
|
|
||||||
lock->ref_name = xstrdup(refname);
|
lock->ref_name = xstrdup(refname);
|
||||||
lock->count = 1;
|
lock->count = 1;
|
||||||
|
cb_data.lk = &lock->lk;
|
||||||
|
cb_data.repo = refs->base.repo;
|
||||||
|
|
||||||
if (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {
|
if (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {
|
||||||
unable_to_lock_message(ref_file.buf, errno, err);
|
unable_to_lock_message(ref_file.buf, errno, err);
|
||||||
goto error_return;
|
goto error_return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ struct ref_transaction;
|
||||||
* Return the length of time to retry acquiring a loose reference lock
|
* Return the length of time to retry acquiring a loose reference lock
|
||||||
* before giving up, in milliseconds:
|
* before giving up, in milliseconds:
|
||||||
*/
|
*/
|
||||||
long get_files_ref_lock_timeout_ms(void);
|
long get_files_ref_lock_timeout_ms(struct repository *repo);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return true iff refname is minimally safe. "Safe" here means that
|
* Return true iff refname is minimally safe. "Safe" here means that
|
||||||
|
|
|
||||||
|
|
@ -399,12 +399,12 @@ static struct ref_store *reftable_be_init(struct repository *repo,
|
||||||
default:
|
default:
|
||||||
BUG("unknown hash algorithm %d", repo->hash_algo->format_id);
|
BUG("unknown hash algorithm %d", repo->hash_algo->format_id);
|
||||||
}
|
}
|
||||||
refs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask);
|
refs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask);
|
||||||
refs->write_options.disable_auto_compact =
|
refs->write_options.disable_auto_compact =
|
||||||
!git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1);
|
!git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1);
|
||||||
refs->write_options.lock_timeout_ms = 100;
|
refs->write_options.lock_timeout_ms = 100;
|
||||||
|
|
||||||
repo_config(the_repository, reftable_be_config, &refs->write_options);
|
repo_config(repo, reftable_be_config, &refs->write_options);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It is somewhat unfortunate that we have to mirror the default block
|
* It is somewhat unfortunate that we have to mirror the default block
|
||||||
|
|
@ -486,7 +486,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
|
|
||||||
strbuf_addf(&sb, "%s/reftable", refs->base.gitdir);
|
strbuf_addf(&sb, "%s/reftable", refs->base.gitdir);
|
||||||
safe_create_dir(the_repository, sb.buf, 1);
|
safe_create_dir(ref_store->repo, sb.buf, 1);
|
||||||
strbuf_reset(&sb);
|
strbuf_reset(&sb);
|
||||||
|
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue