Skip to content

Commit f45ae8d

Browse files
shreyp135gitster
authored andcommitted
refs: remove the_hash_algo global state
refs.c uses the_hash_algo in multiple places, relying on global state for the object hash algorithm. Replace these uses with the appropriate repository-specific hash_algo. In transaction-related functions (ref_transaction_create, ref_transaction_delete, migrate_one_ref, and transaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo. In other cases, such as repo_get_submodule_ref_store(), use repo->hash_algo. Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d44b1f4 commit f45ae8d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

refs.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -3145,6 +3145,7 @@ struct migration_data {
31453145
static int migrate_one_ref(const struct reference *ref, void *cb_data)
31463146
{
31473147
struct migration_data *data = cb_data;
3148+
const struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;
31483149
struct strbuf symref_target = STRBUF_INIT;
31493150
int ret;
31503151

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

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

0 commit comments

Comments
 (0)