Skip to content

Commit 0a6e62e

Browse files
committed
Merge branch 'sp/refs-with-less-the-repository' into seen
* sp/refs-with-less-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()
2 parents 9f00115 + 9c88148 commit 0a6e62e

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

refs.c

Lines changed: 9 additions & 8 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

@@ -1472,7 +1472,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
14721472
return 1;
14731473
}
14741474
return ref_transaction_update(transaction, refname, new_oid,
1475-
null_oid(the_hash_algo), new_target, NULL, flags,
1475+
null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,
14761476
msg, err);
14771477
}
14781478

@@ -1491,7 +1491,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
14911491
if (old_target && !(flags & REF_NO_DEREF))
14921492
BUG("delete cannot operate on symrefs with deref mode");
14931493
return ref_transaction_update(transaction, refname,
1494-
null_oid(the_hash_algo), old_oid,
1494+
null_oid(transaction->ref_store->repo->hash_algo), old_oid,
14951495
NULL, old_target, flags,
14961496
msg, err);
14971497
}
@@ -2379,7 +2379,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
23792379
subrepo = xmalloc(sizeof(*subrepo));
23802380

23812381
if (repo_submodule_init(subrepo, repo, submodule,
2382-
null_oid(the_hash_algo))) {
2382+
null_oid(repo->hash_algo))) {
23832383
free(subrepo);
23842384
goto done;
23852385
}
@@ -2571,14 +2571,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_
25712571
strbuf_reset(buf);
25722572

25732573
if (!(update->flags & REF_HAVE_OLD))
2574-
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
2574+
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
25752575
else if (update->old_target)
25762576
strbuf_addf(buf, "ref:%s ", update->old_target);
25772577
else
25782578
strbuf_addf(buf, "%s ", oid_to_hex(&update->old_oid));
25792579

25802580
if (!(update->flags & REF_HAVE_NEW))
2581-
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
2581+
strbuf_addf(buf, "%s ", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));
25822582
else if (update->new_target)
25832583
strbuf_addf(buf, "ref:%s ", update->new_target);
25842584
else
@@ -3146,6 +3146,7 @@ struct migration_data {
31463146
static int migrate_one_ref(const struct reference *ref, void *cb_data)
31473147
{
31483148
struct migration_data *data = cb_data;
3149+
const struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;
31493150
struct strbuf symref_target = STRBUF_INIT;
31503151
int ret;
31513152

@@ -3154,7 +3155,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)
31543155
if (ret < 0)
31553156
goto done;
31563157

3157-
ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),
3158+
ret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),
31583159
symref_target.buf, NULL,
31593160
REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
31603161
if (ret < 0)

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

refs/reftable-backend.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ static struct ref_store *reftable_be_init(struct repository *repo,
399399
default:
400400
BUG("unknown hash algorithm %d", repo->hash_algo->format_id);
401401
}
402-
refs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask);
402+
refs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask);
403403
refs->write_options.disable_auto_compact =
404404
!git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1);
405405
refs->write_options.lock_timeout_ms = 100;
406406

407-
repo_config(the_repository, reftable_be_config, &refs->write_options);
407+
repo_config(repo, reftable_be_config, &refs->write_options);
408408

409409
/*
410410
* 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,
486486
struct strbuf sb = STRBUF_INIT;
487487

488488
strbuf_addf(&sb, "%s/reftable", refs->base.gitdir);
489-
safe_create_dir(the_repository, sb.buf, 1);
489+
safe_create_dir(ref_store->repo, sb.buf, 1);
490490
strbuf_reset(&sb);
491491

492492
strbuf_release(&sb);

0 commit comments

Comments
 (0)