summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-05-11 10:05:51 +0900
committerJunio C Hamano <gitster@pobox.com>2026-05-11 10:05:51 +0900
commit655096d1dccbedf51295d574df8d7746d6c5aedc (patch)
tree24ef2a0e2d6b7b8abea7b1829256b43cafef318f
parent94f057755b7941b321fd11fec1b2e3ca5313a4e0 (diff)
parent57c590feb96b2298e0966bea3ce88c72fca37bbd (diff)
downloadgit-655096d1dccbedf51295d574df8d7746d6c5aedc.tar.gz
git-655096d1dccbedf51295d574df8d7746d6c5aedc.zip
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()
-rw-r--r--refs.c17
-rw-r--r--refs/files-backend.c19
-rw-r--r--refs/refs-internal.h2
-rw-r--r--refs/reftable-backend.c6
4 files changed, 26 insertions, 18 deletions
diff --git a/refs.c b/refs.c
index bfcb9c7ac3..844785219d 100644
--- a/refs.c
+++ b/refs.c
@@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,
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;
@@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)
static int timeout_ms = 100;
if (!configured) {
- repo_config_get_int(the_repository, "core.filesreflocktimeout", &timeout_ms);
+ repo_config_get_int(repo, "core.filesreflocktimeout", &timeout_ms);
configured = 1;
}
@@ -1472,7 +1472,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
return 1;
}
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);
}
@@ -1491,7 +1491,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
if (old_target && !(flags & REF_NO_DEREF))
BUG("delete cannot operate on symrefs with deref mode");
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,
msg, err);
}
@@ -2379,7 +2379,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
subrepo = xmalloc(sizeof(*subrepo));
if (repo_submodule_init(subrepo, repo, submodule,
- null_oid(the_hash_algo))) {
+ null_oid(repo->hash_algo))) {
free(subrepo);
goto done;
}
@@ -2571,14 +2571,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_
strbuf_reset(buf);
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)
strbuf_addf(buf, "ref:%s ", update->old_target);
else
strbuf_addf(buf, "%s ", oid_to_hex(&update->old_oid));
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)
strbuf_addf(buf, "ref:%s ", update->new_target);
else
@@ -3146,6 +3146,7 @@ struct migration_data {
static int migrate_one_ref(const struct reference *ref, void *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;
int ret;
@@ -3154,7 +3155,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)
if (ret < 0)
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,
REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
if (ret < 0)
diff --git a/refs/files-backend.c b/refs/files-backend.c
index b3b0c25f84..bae3790845 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -792,7 +792,7 @@ retry:
if (hold_lock_file_for_update_timeout(
&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;
errno = 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);
}
+struct create_reflock_cb {
+ struct lock_file *lk;
+ struct repository *repo;
+};
+
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(
- lk, path, LOCK_NO_DEREF,
- get_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;
+ data->lk, path, LOCK_NO_DEREF,
+ 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 ref_lock *lock;
+ struct create_reflock_cb cb_data;
files_assert_main_repository(refs, "lock_ref_oid_basic");
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->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);
goto error_return;
}
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index d79e35fd26..e4cfd9e19e 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -43,7 +43,7 @@ struct ref_transaction;
* Return the length of time to retry acquiring a loose reference lock
* 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
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index daea30a5b4..4921b456ff 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -399,12 +399,12 @@ static struct ref_store *reftable_be_init(struct repository *repo,
default:
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 =
!git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1);
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
@@ -486,7 +486,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,
struct strbuf sb = STRBUF_INIT;
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_release(&sb);