git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 2/3] refs: remove the_hash_algo global state

From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Date
Apr 3, 2026, 12:08 UTC
Message-ID
<20260403120938.1142533-3-shreyanshpaliwalcmsmn@gmail.com>
In-Reply-To
<20260403120938.1142533-1-shreyanshpaliwalcmsmn@gmail.com>

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>
---
 refs.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/refs.c b/refs.c
index 214ebfd5ce..cb58e10dc6 100644
--- a/refs.c
+++ b/refs.c
@@ -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
@@ -3145,6 +3145,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;
 
@@ -3153,7 +3154,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)
-- 
2.53.0
Previous: Tian YuchenNext: Shreyansh Paliwal
Message 41 of 48 in “refs: reduce reliance on the_repository global state”
  1. 0/5 refs: reduce reliance on the_repository global stateShreyansh Paliwal, Mar 25, 2026
  2. 1/5 refs: make branchname helpers repository awareShreyansh Paliwal, Mar 25, 2026
  3. Patrick SteinhardtMar 27, 2026
  4. Shreyansh PaliwalMar 28, 2026
  5. 2/5 refs: make get_files_ref_lock_timeout_ms() repostory awareShreyansh Paliwal, Mar 25, 2026
  6. Patrick SteinhardtMar 27, 2026
  7. Burak Kaan KaraçayMar 27, 2026
  8. Shreyansh PaliwalMar 28, 2026
  9. 3/5 refs: remove the_hash_algo global stateShreyansh Paliwal, Mar 25, 2026
  10. 4/5 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Mar 25, 2026
  11. Patrick SteinhardtMar 27, 2026
  12. 5/5 refs/packed-backend: use ref_store->repo instead of the_repositoryShreyansh Paliwal, Mar 25, 2026
  13. 0/5 refs: reduce reliance on the_repository global stateShreyansh Paliwal, Mar 28, 2026
  14. 1/5 refs: make branchname helpers repository awareShreyansh Paliwal, Mar 28, 2026
  15. Tian YuchenMar 28, 2026
  16. Shreyansh PaliwalMar 29, 2026
  17. Tian YuchenMar 29, 2026
  18. 2/5 refs: make get_files_ref_lock_timeout_ms() repostory awareShreyansh Paliwal, Mar 28, 2026
  19. 3/5 refs: remove the_hash_algo global stateShreyansh Paliwal, Mar 28, 2026
  20. Tian YuchenMar 28, 2026
  21. 4/5 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Mar 28, 2026
  22. 5/5 refs/packed-backend: use ref_store->repo instead of the_repositoryShreyansh Paliwal, Mar 28, 2026
  23. Tian YuchenMar 28, 2026
  24. Shreyansh PaliwalMar 29, 2026
  25. 0/5 replace the_repository with local repository instancesShreyansh Paliwal, Mar 29, 2026
  26. 1/5 refs: add struct repository parameter to branchname helpersShreyansh Paliwal, Mar 29, 2026
  27. Patrick SteinhardtApr 2, 2026
  28. Burak Kaan KaraçayApr 2, 2026
  29. Tian YuchenApr 2, 2026
  30. Patrick SteinhardtApr 2, 2026
  31. Shreyansh PaliwalApr 3, 2026
  32. 2/5 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()Shreyansh Paliwal, Mar 29, 2026
  33. 3/5 refs: remove the_hash_algo global stateShreyansh Paliwal, Mar 29, 2026
  34. 4/5 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Mar 29, 2026
  35. Patrick SteinhardtApr 2, 2026
  36. Shreyansh PaliwalApr 3, 2026
  37. 5/5 refs/packed-backend: use ref_store->repo instead of the_repositoryShreyansh Paliwal, Mar 29, 2026
  38. 0/3 refs: reduce reliance on global stateShreyansh Paliwal, Apr 3, 2026
  39. 1/3 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()Shreyansh Paliwal, Apr 3, 2026
  40. Tian YuchenApr 3, 2026
  41. 2/3 refs: remove the_hash_algo global stateShreyansh Paliwal, Apr 3, 2026
  42. 3/3 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Apr 3, 2026
  43. 0/3 refs: reduce reliance on global stateShreyansh Paliwal, Apr 4, 2026
  44. 1/3 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()Shreyansh Paliwal, Apr 4, 2026
  45. 2/3 refs: remove the_hash_algo global stateShreyansh Paliwal, Apr 4, 2026
  46. 3/3 refs/reftable-backend: drop uses of the_repositoryShreyansh Paliwal, Apr 4, 2026
  47. Patrick SteinhardtApr 8, 2026
  48. Junio C HamanoApr 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.