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

[PATCH v3 0/5] replace the_repository with local repository instances

From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Date
Mar 29, 2026, 10:16 UTC
Message-ID
<20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com>
In-Reply-To
<20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com>

This series continues the effort to reduce reliance on the_repository global state by making repository context explicit across the refs subsystem. The patches focus on passing struct repository through various ref helpers and backends, and replacing uses of global state such as the_repository and the_hash_algo with the appropriate repository instance.

Patch 1/5: Making branch name helper functions (copy_branchname(), check_branch_ref(), validate_branchname(), and validate_new_branchname()) repository-aware. (built on top of jw/object-name-bitset-to-enum)

Patch 2/5: Updating get_files_ref_lock_timeout_ms() to take a repository and propagating it through files-backend, including callback paths.

Patch 3/5: Replacing uses of the_hash_algo in refs.c with the hash algorithm from the appropriate repository.

Patch 4/5: Removing remaining uses of the_repository in reftable-backend.c where a repository instance is already available.

Patch 5/5: Replacing the single instance of the_repository in packed-backend.c, thus dropping the USE_THE_REPOSITORY_VARIABLE macro.

Shreyansh Paliwal (5):
  refs: add struct repository parameter to branchname helpers
  refs: add struct repository parameter in
    get_files_ref_lock_timeout_ms()
  refs: remove the_hash_algo global state
  refs/reftable-backend: drop uses of the_repository
  refs/packed-backend: use ref_store->repo instead of the_repository
 branch.c                   | 15 ++++++++-------
 branch.h                   |  5 +++--
 builtin/branch.c           | 14 +++++++-------
 builtin/check-ref-format.c |  3 ++-
 builtin/checkout.c         |  6 +++---
 builtin/merge.c            |  2 +-
 builtin/worktree.c         | 10 +++++-----
 refs.c                     | 28 +++++++++++++---------------
 refs.h                     |  4 ++--
 refs/files-backend.c       | 19 +++++++++++++------
 refs/packed-backend.c      |  3 +--
 refs/refs-internal.h       |  2 +-
 refs/reftable-backend.c    |  6 +++---
 13 files changed, 62 insertions(+), 55 deletions(-)
---
Changes in v3:
 - Fixed an import
 - better readability in patch 3/5
Changes in v2:
 - Made struct repository the first argument in function parameters.
Range-diff against v2:
1:  c0182252c4 ! 1:  5844440b73 refs: make branchname helpers repository aware
    @@ Metadata
     Author: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
      ## Commit message ##
    -    refs: make branchname helpers repository aware
    +    refs: add struct repository parameter to branchname helpers
         copy_branchname() in refs.c relies on the_repository when calling
         repo_interpret_branch_name(), introducing an implicit dependency on global
    @@ builtin/branch.c: int cmd_branch(int argc,
      ## builtin/check-ref-format.c ##
     @@
    + /*
    +  * GIT - The information manager from hell
    +  */
    ++#define USE_THE_REPOSITORY_VARIABLE
    + #include "builtin.h"
      #include "refs.h"
      #include "setup.h"
    - #include "strbuf.h"
    -+#include "repository.c"
    -
    - static const char builtin_check_ref_format_usage[] =
    - "git check-ref-format [--normalize] [<options>] <refname>\n"
     @@ builtin/check-ref-format.c: static int check_ref_format_branch(const char *arg)
      	int nongit;
2:  857a8c40fe ! 2:  f7a9ea4204 refs: make get_files_ref_lock_timeout_ms() repostory aware
    @@ Metadata
     Author: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
      ## Commit message ##
    -    refs: make get_files_ref_lock_timeout_ms() repostory aware
    +    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
    @@ Commit message
         is used as a callback, introduce a small wrapper struct to pass both struct
         lock_file and struct repository through the callback data.
    -    This removes reliance on the_repository global and makes the timeout lookup
    -    operate on the correct repository context.
    +    This reduces reliance on the_repository global.
         Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
3:  46d5272aec ! 3:  00dba1a96a refs: remove the_hash_algo global state
    @@ refs.c: static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, v
      	else if (update->new_target)
      		strbuf_addf(buf, "ref:%s ", update->new_target);
      	else
    +@@ refs.c: 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;
    +
     @@ refs.c: 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(data->transaction->ref_store->repo->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)
4:  11aa886259 = 4:  5653c418e1 refs/reftable-backend: drop uses of the_repository
5:  c763732964 = 5:  18c1c67083 refs/packed-backend: use ref_store->repo instead of the_repository
--
2.53.0
Previous: Shreyansh PaliwalNext: Shreyansh Paliwal
Message 25 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.