Skip to content

Commit d44b1f4

Browse files
shreyp135gitster
authored andcommitted
refs: add struct repository parameter in get_files_ref_lock_timeout_ms()
get_files_ref_lock_timeout_ms() calls repo_config_get_int() using the_repository, as no repository instance is available in its scope. Add a struct repository parameter and use it instead of the_repository. Update all callers accordingly. In files-backend.c, lock_raw_ref() can obtain repository instance from the struct ref_transaction via transaction->ref_store->repo and pass it down. For create_reflock(), which is used as a callback, introduce a small wrapper struct to pass both struct lock_file and struct repository through the callback data. This reduces reliance on the_repository global. Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2565546 commit d44b1f4

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,15 +989,15 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,
989989
return REF_WORKTREE_SHARED;
990990
}
991991

992-
long get_files_ref_lock_timeout_ms(void)
992+
long get_files_ref_lock_timeout_ms(struct repository *repo)
993993
{
994994
static int configured = 0;
995995

996996
/* The default timeout is 100 ms: */
997997
static int timeout_ms = 100;
998998

999999
if (!configured) {
1000-
repo_config_get_int(the_repository, "core.filesreflocktimeout", &timeout_ms);
1000+
repo_config_get_int(repo, "core.filesreflocktimeout", &timeout_ms);
10011001
configured = 1;
10021002
}
10031003

refs/files-backend.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,
792792

793793
if (hold_lock_file_for_update_timeout(
794794
&lock->lk, ref_file.buf, LOCK_NO_DEREF,
795-
get_files_ref_lock_timeout_ms()) < 0) {
795+
get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {
796796
int myerr = errno;
797797
errno = 0;
798798
if (myerr == ENOENT && --attempts_remaining > 0) {
@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)
11901190
return remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);
11911191
}
11921192

1193+
struct create_reflock_cb {
1194+
struct lock_file *lk;
1195+
struct repository *repo;
1196+
};
1197+
11931198
static int create_reflock(const char *path, void *cb)
11941199
{
1195-
struct lock_file *lk = cb;
1196-
1200+
struct create_reflock_cb *data = cb;
11971201
return hold_lock_file_for_update_timeout(
1198-
lk, path, LOCK_NO_DEREF,
1199-
get_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;
1202+
data->lk, path, LOCK_NO_DEREF,
1203+
get_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;
12001204
}
12011205

12021206
/*
@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
12081212
{
12091213
struct strbuf ref_file = STRBUF_INIT;
12101214
struct ref_lock *lock;
1215+
struct create_reflock_cb cb_data;
12111216

12121217
files_assert_main_repository(refs, "lock_ref_oid_basic");
12131218
assert(err);
@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
12291234

12301235
lock->ref_name = xstrdup(refname);
12311236
lock->count = 1;
1237+
cb_data.lk = &lock->lk;
1238+
cb_data.repo = refs->base.repo;
12321239

1233-
if (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {
1240+
if (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {
12341241
unable_to_lock_message(ref_file.buf, errno, err);
12351242
goto error_return;
12361243
}

refs/refs-internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct ref_transaction;
4343
* Return the length of time to retry acquiring a loose reference lock
4444
* before giving up, in milliseconds:
4545
*/
46-
long get_files_ref_lock_timeout_ms(void);
46+
long get_files_ref_lock_timeout_ms(struct repository *repo);
4747

4848
/*
4949
* Return true iff refname is minimally safe. "Safe" here means that

0 commit comments

Comments
 (0)