{"thread":{"id":"65352","subject":"[PATCH 0/5] refs: reduce reliance on the_repository global state","startedAt":"2026-03-25T16:48:48Z","lastAt":"2026-04-08T17:10:00Z","messageCount":48,"participants":["Shreyansh Paliwal","Patrick Steinhardt","Burak Kaan Karaçay","Tian Yuchen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"539956","messageId":"20260325164833.1216577-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":null,"subject":"[PATCH 0/5] refs: reduce reliance on the_repository global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-25T16:44:17Z","receivedAt":"2026-03-25T16:48:48Z","isPatch":true,"body":"This series continues the effort to reduce reliance on the_repository\nglobal state by making repository context explicit across the refs\nsubsystem. The patches focus on passing struct repository through various\nref helpers and backends, and replacing uses of global state such as\nthe_repository and the_hash_algo with the appropriate repository instance.\n\nPatch 1/5: Making branch name helper functions (copy_branchname(),\ncheck_branch_ref(), validate_branchname(), and validate_new_branchname())\nrepository-aware. (built on top of jw/object-name-bitset-to-enum)\n\nPatch 2/5: Updating get_files_ref_lock_timeout_ms() to take a repository\nand propagating it through files-backend, including callback paths.\n\nPatch 3/5: Replacing uses of the_hash_algo in refs.c with the hash\nalgorithm from the appropriate repository.\n\nPatch 4/5: Removing remaining uses of the_repository in reftable-backend.c\nwhere a repository instance is already available.\n\nPatch 5/5: Replacing the single instance of the_repository in\npacked-backend.c, thus dropping the USE_THE_REPOSITORY_VARIABLE macro.\n\nShreyansh Paliwal (5):\n  refs: make branchname helpers repository aware\n  refs: make get_files_ref_lock_timeout_ms() repostory aware\n  refs: remove the_hash_algo global state\n  refs/reftable-backend: drop uses of the_repository\n  refs/packed-backend: use ref_store->repo instead of the_repository\n\n branch.c                   | 15 ++++++++-------\n branch.h                   |  5 +++--\n builtin/branch.c           | 14 +++++++-------\n builtin/check-ref-format.c |  3 ++-\n builtin/checkout.c         |  6 +++---\n builtin/merge.c            |  2 +-\n builtin/worktree.c         | 10 +++++-----\n refs.c                     | 28 +++++++++++++---------------\n refs.h                     |  5 +++--\n refs/files-backend.c       | 19 +++++++++++++------\n refs/packed-backend.c      |  3 +--\n refs/refs-internal.h       |  2 +-\n refs/reftable-backend.c    |  6 +++---\n 13 files changed, 63 insertions(+), 55 deletions(-)\n\n--\n2.53.0\n\n"},{"id":"539957","messageId":"20260325164833.1216577-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260325164833.1216577-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 1/5] refs: make branchname helpers repository aware","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-25T16:44:18Z","receivedAt":"2026-03-25T16:48:53Z","isPatch":true,"body":"copy_branchname() in refs.c relies on the_repository when calling\nrepo_interpret_branch_name(), introducing an implicit dependency on global\nstate. Add a struct repository parameter and use it instead.\n\nUpdate check_branch_ref() to take a repository parameter as well, since it\ncalls copy_branchname(). Propagate this change to higher-level helpers\nvalidate_branchname() and validate_new_branchname(), which also lack access\nto a repository instance. Most callers of these helpers reside in builtin\ncode and already operate on the_repository, so pass it explicitly at those\ncall sites (builtin/checkout and builtin/worktree) otherwise pass struct\nrepository where available.\n\nThis makes branch name handling explicitly repository-aware and aligns with\nongoing efforts to remove reliance on global state. This change builds on\ntop of jw/object-name-bitset-to-enum (2026-03-18), which introduced the\nenum interpret_branch_kind parameter to copy_branchname().\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n branch.c                   | 15 ++++++++-------\n branch.h                   |  5 +++--\n builtin/branch.c           | 14 +++++++-------\n builtin/check-ref-format.c |  3 ++-\n builtin/checkout.c         |  6 +++---\n builtin/merge.c            |  2 +-\n builtin/worktree.c         | 10 +++++-----\n refs.c                     |  9 +++++----\n refs.h                     |  5 +++--\n 9 files changed, 37 insertions(+), 32 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 243db7d0fc..65189823c3 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -370,16 +370,16 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_branchname(const char *name, struct strbuf *ref)\n+int validate_branchname(const char *name, struct strbuf *ref, struct repository *repo)\n {\n-\tif (check_branch_ref(ref, name)) {\n+\tif (check_branch_ref(ref, name, repo)) {\n \t\tint code = die_message(_(\"'%s' is not a valid branch name\"), name);\n \t\tadvise_if_enabled(ADVICE_REF_SYNTAX,\n \t\t\t\t  _(\"See 'git help check-ref-format'\"));\n \t\texit(code);\n \t}\n \n-\treturn refs_ref_exists(get_main_ref_store(the_repository), ref->buf);\n+\treturn refs_ref_exists(get_main_ref_store(repo), ref->buf);\n }\n \n static int initialized_checked_out_branches;\n@@ -468,10 +468,11 @@ const char *branch_checked_out(const char *refname)\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_new_branchname(const char *name, struct strbuf *ref, int force)\n+int validate_new_branchname(const char *name, struct strbuf *ref, int force,\n+\t\t\t    struct repository *repo)\n {\n \tconst char *path;\n-\tif (!validate_branchname(name, ref))\n+\tif (!validate_branchname(name, ref, repo))\n \t\treturn 0;\n \n \tif (!force)\n@@ -613,8 +614,8 @@ void create_branch(struct repository *r,\n \t\tBUG(\"'clobber_head_ok' can only be used with 'force'\");\n \n \tif (clobber_head_ok ?\n-\t\t\t  validate_branchname(name, &ref) :\n-\t\t\t  validate_new_branchname(name, &ref, force)) {\n+\t\t\t  validate_branchname(name, &ref, r) :\n+\t\t\t  validate_new_branchname(name, &ref, force, r)) {\n \t\tforcing = 1;\n \t}\n \ndiff --git a/branch.h b/branch.h\nindex 3dc6e2a0ff..3aa53eb243 100644\n--- a/branch.h\n+++ b/branch.h\n@@ -111,7 +111,7 @@ const char *branch_checked_out(const char *refname);\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_branchname(const char *name, struct strbuf *ref);\n+int validate_branchname(const char *name, struct strbuf *ref, struct repository *repo);\n \n /*\n  * Check if a branch 'name' can be created as a new branch; die otherwise.\n@@ -119,7 +119,8 @@ int validate_branchname(const char *name, struct strbuf *ref);\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_new_branchname(const char *name, struct strbuf *ref, int force);\n+int validate_new_branchname(const char *name, struct strbuf *ref, int force,\n+\t\t\t    struct repository *repo);\n \n /*\n  * Remove information about the merge state on the current\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 1572a4f9ef..9c86b9f525 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -259,7 +259,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\tchar *target = NULL;\n \t\tint flags = 0;\n \n-\t\tcopy_branchname(&bname, argv[i], allowed_interpret);\n+\t\tcopy_branchname(&bname, argv[i], allowed_interpret, the_repository);\n \t\tfree(name);\n \t\tname = mkpathdup(fmt, bname.buf);\n \n@@ -581,7 +581,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \tint recovery = 0, oldref_usage = 0;\n \tstruct worktree **worktrees = get_worktrees();\n \n-\tif (check_branch_ref(&oldref, oldname)) {\n+\tif (check_branch_ref(&oldref, oldname, the_repository)) {\n \t\t/*\n \t\t * Bad name --- this could be an attempt to rename a\n \t\t * ref that we used to allow to be created by accident.\n@@ -619,9 +619,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t * cause the worktree to become inconsistent with HEAD, so allow it.\n \t */\n \tif (!strcmp(oldname, newname))\n-\t\tvalidate_branchname(newname, &newref);\n+\t\tvalidate_branchname(newname, &newref, the_repository);\n \telse\n-\t\tvalidate_new_branchname(newname, &newref, force);\n+\t\tvalidate_new_branchname(newname, &newref, force, the_repository);\n \n \treject_rebase_or_bisect_branch(worktrees, oldref.buf);\n \n@@ -898,7 +898,7 @@ int cmd_branch(int argc,\n \t\t\t\tdie(_(\"cannot give description to detached HEAD\"));\n \t\t\tbranch_name = head;\n \t\t} else if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL, the_repository);\n \t\t\tbranch_name = buf.buf;\n \t\t} else {\n \t\t\tdie(_(\"cannot edit description of more than one branch\"));\n@@ -941,7 +941,7 @@ int cmd_branch(int argc,\n \t\tif (!argc)\n \t\t\tbranch = branch_get(NULL);\n \t\telse if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL, the_repository);\n \t\t\tbranch = branch_get(buf.buf);\n \t\t} else\n \t\t\tdie(_(\"too many arguments to set new upstream\"));\n@@ -971,7 +971,7 @@ int cmd_branch(int argc,\n \t\tif (!argc)\n \t\t\tbranch = branch_get(NULL);\n \t\telse if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL, the_repository);\n \t\t\tbranch = branch_get(buf.buf);\n \t\t} else\n \t\t\tdie(_(\"too many arguments to unset upstream\"));\ndiff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c\nindex 5d80afeec0..8222a289c9 100644\n--- a/builtin/check-ref-format.c\n+++ b/builtin/check-ref-format.c\n@@ -5,6 +5,7 @@\n #include \"refs.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n+#include \"repository.c\"\n \n static const char builtin_check_ref_format_usage[] =\n \"git check-ref-format [--normalize] [<options>] <refname>\\n\"\n@@ -42,7 +43,7 @@ static int check_ref_format_branch(const char *arg)\n \tint nongit;\n \n \tsetup_git_directory_gently(&nongit);\n-\tif (check_branch_ref(&sb, arg) ||\n+\tif (check_branch_ref(&sb, arg, the_repository) ||\n \t    !skip_prefix(sb.buf, \"refs/heads/\", &name))\n \t\tdie(\"'%s' is not a valid branch name\", arg);\n \tprintf(\"%s\\n\", name);\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex e031e61886..7570a5664f 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -743,7 +743,7 @@ static void setup_branch_path(struct branch_info *branch)\n \t\t\t   &branch->oid, &branch->refname, 0))\n \t\trepo_get_oid_committish(the_repository, branch->name, &branch->oid);\n \n-\tcopy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);\n+\tcopy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL, the_repository);\n \tif (strcmp(buf.buf, branch->name)) {\n \t\tfree(branch->name);\n \t\tbranch->name = xstrdup(buf.buf);\n@@ -2014,10 +2014,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \n \t\tif (opts->new_branch_force)\n-\t\t\topts->branch_exists = validate_branchname(opts->new_branch, &buf);\n+\t\t\topts->branch_exists = validate_branchname(opts->new_branch, &buf, the_repository);\n \t\telse\n \t\t\topts->branch_exists =\n-\t\t\t\tvalidate_new_branchname(opts->new_branch, &buf, 0);\n+\t\t\t\tvalidate_new_branchname(opts->new_branch, &buf, 0, the_repository);\n \t\tstrbuf_release(&buf);\n \t}\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 2cbce56f8d..854490afef 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -552,7 +552,7 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \tchar *found_ref = NULL;\n \tint len, early;\n \n-\tcopy_branchname(&bname, remote, 0);\n+\tcopy_branchname(&bname, remote, 0, the_repository);\n \tremote = bname.buf;\n \n \toidclr(&branch_head, the_repository->hash_algo);\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 4035b1cb06..6ec2f02bf0 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -415,7 +415,7 @@ static int make_worktree_orphan(const char * ref, const struct add_opts *opts,\n \tstruct strbuf symref = STRBUF_INIT;\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n \n-\tvalidate_new_branchname(ref, &symref, 0);\n+\tvalidate_new_branchname(ref, &symref, 0, the_repository);\n \tstrvec_pushl(&cp.args, \"symbolic-ref\", \"HEAD\", symref.buf, NULL);\n \tif (opts->quiet)\n \t\tstrvec_push(&cp.args, \"--quiet\");\n@@ -481,7 +481,7 @@ static int add_worktree(const char *path, const char *refname,\n \tworktrees = NULL;\n \n \t/* is 'refname' a branch or commit? */\n-\tif (!opts->detach && !check_branch_ref(&symref, refname) &&\n+\tif (!opts->detach && !check_branch_ref(&symref, refname, the_repository) &&\n \t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {\n \t\tis_branch = 1;\n \t\tif (!opts->force)\n@@ -649,7 +649,7 @@ static void print_preparing_worktree_line(int detach,\n \t\tfprintf_ln(stderr, _(\"Preparing worktree (new branch '%s')\"), new_branch);\n \t} else {\n \t\tstruct strbuf s = STRBUF_INIT;\n-\t\tif (!detach && !check_branch_ref(&s, branch) &&\n+\t\tif (!detach && !check_branch_ref(&s, branch, the_repository) &&\n \t\t    refs_ref_exists(get_main_ref_store(the_repository), s.buf))\n \t\t\tfprintf_ln(stderr, _(\"Preparing worktree (checking out '%s')\"),\n \t\t\t\t  branch);\n@@ -788,7 +788,7 @@ static char *dwim_branch(const char *path, char **new_branch)\n \tchar *branchname = xstrndup(s, n);\n \tstruct strbuf ref = STRBUF_INIT;\n \n-\tbranch_exists = !check_branch_ref(&ref, branchname) &&\n+\tbranch_exists = !check_branch_ref(&ref, branchname, the_repository) &&\n \t\t\trefs_ref_exists(get_main_ref_store(the_repository),\n \t\t\t\t\tref.buf);\n \tstrbuf_release(&ref);\n@@ -885,7 +885,7 @@ static int add(int ac, const char **av, const char *prefix,\n \t\tnew_branch = new_branch_force;\n \n \t\tif (!opts.force &&\n-\t\t    !check_branch_ref(&symref, new_branch) &&\n+\t\t    !check_branch_ref(&symref, new_branch, the_repository) &&\n \t\t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf))\n \t\t\tdie_if_checked_out(symref.buf, 0);\n \t\tstrbuf_release(&symref);\ndiff --git a/refs.c b/refs.c\nindex 685a0c247b..840965519e 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -744,13 +744,14 @@ static char *substitute_branch_name(struct repository *r,\n }\n \n void copy_branchname(struct strbuf *sb, const char *name,\n-\t\t     enum interpret_branch_kind allowed)\n+\t\t     enum interpret_branch_kind allowed,\n+\t\t     struct repository *repo)\n {\n \tint len = strlen(name);\n \tstruct interpret_branch_name_options options = {\n \t\t.allowed = allowed\n \t};\n-\tint used = repo_interpret_branch_name(the_repository, name, len, sb,\n+\tint used = repo_interpret_branch_name(repo, name, len, sb,\n \t\t\t\t\t      &options);\n \n \tif (used < 0)\n@@ -758,10 +759,10 @@ void copy_branchname(struct strbuf *sb, const char *name,\n \tstrbuf_add(sb, name + used, len - used);\n }\n \n-int check_branch_ref(struct strbuf *sb, const char *name)\n+int check_branch_ref(struct strbuf *sb, const char *name, struct repository *repo)\n {\n \tif (startup_info->have_repository)\n-\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n+\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL, repo);\n \telse\n \t\tstrbuf_addstr(sb, name);\n \ndiff --git a/refs.h b/refs.h\nindex d65de6ab5f..72b8ea609a 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -226,7 +226,8 @@ char *repo_default_branch_name(struct repository *r, int quiet);\n  * repo_interpret_branch_name() for details.\n  */\n void copy_branchname(struct strbuf *sb, const char *name,\n-\t\t     enum interpret_branch_kind allowed);\n+\t\t     enum interpret_branch_kind allowed,\n+\t\t     struct repository *repo);\n \n /*\n  * Like copy_branchname() above, but confirm that the result is\n@@ -234,7 +235,7 @@ void copy_branchname(struct strbuf *sb, const char *name,\n  *\n  * The return value is \"0\" if the result is valid, and \"-1\" otherwise.\n  */\n-int check_branch_ref(struct strbuf *sb, const char *name);\n+int check_branch_ref(struct strbuf *sb, const char *name, struct repository *repo);\n \n /*\n  * Similar for a tag name in refs/tags/.\n-- \n2.53.0\n\n"},{"id":"539958","messageId":"20260325164833.1216577-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260325164833.1216577-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-25T16:44:19Z","receivedAt":"2026-03-25T16:48:56Z","isPatch":true,"body":"get_files_ref_lock_timeout_ms() calls repo_config_get_int() using\nthe_repository, as no repository instance is available in its scope. Add a\nstruct repository parameter and use it instead of the_repository.\n\nUpdate all callers accordingly. In files-backend.c, lock_raw_ref() can\nobtain repository instance from the struct ref_transaction via\ntransaction->ref_store->repo and pass it down. For create_reflock(), which\nis used as a callback, introduce a small wrapper struct to pass both struct\nlock_file and struct repository through the callback data.\n\nThis removes reliance on the_repository global and makes the timeout lookup\noperate on the correct repository context.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c               |  4 ++--\n refs/files-backend.c | 19 +++++++++++++------\n refs/refs-internal.h |  2 +-\n 3 files changed, 16 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 840965519e..e7256b3a84 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -990,7 +990,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,\n \treturn REF_WORKTREE_SHARED;\n }\n \n-long get_files_ref_lock_timeout_ms(void)\n+long get_files_ref_lock_timeout_ms(struct repository *repo)\n {\n \tstatic int configured = 0;\n \n@@ -998,7 +998,7 @@ long get_files_ref_lock_timeout_ms(void)\n \tstatic int timeout_ms = 100;\n \n \tif (!configured) {\n-\t\trepo_config_get_int(the_repository, \"core.filesreflocktimeout\", &timeout_ms);\n+\t\trepo_config_get_int(repo, \"core.filesreflocktimeout\", &timeout_ms);\n \t\tconfigured = 1;\n \t}\n \ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 7ce0d57478..ee8dd771a4 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -792,7 +792,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,\n \n \tif (hold_lock_file_for_update_timeout(\n \t\t\t    &lock->lk, ref_file.buf, LOCK_NO_DEREF,\n-\t\t\t    get_files_ref_lock_timeout_ms()) < 0) {\n+\t\t\t    get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {\n \t\tint myerr = errno;\n \t\terrno = 0;\n \t\tif (myerr == ENOENT && --attempts_remaining > 0) {\n@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)\n \treturn remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);\n }\n \n+struct create_reflock_cb {\n+    struct lock_file *lk;\n+    struct repository *repo;\n+};\n+\n static int create_reflock(const char *path, void *cb)\n {\n-\tstruct lock_file *lk = cb;\n-\n+\tstruct create_reflock_cb *data = cb;\n \treturn hold_lock_file_for_update_timeout(\n-\t\t\tlk, path, LOCK_NO_DEREF,\n-\t\t\tget_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;\n+\t\t\tdata->lk, path, LOCK_NO_DEREF,\n+\t\t\tget_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;\n }\n \n /*\n@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n {\n \tstruct strbuf ref_file = STRBUF_INIT;\n \tstruct ref_lock *lock;\n+\tstruct create_reflock_cb cb_data;\n \n \tfiles_assert_main_repository(refs, \"lock_ref_oid_basic\");\n \tassert(err);\n@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n \n \tlock->ref_name = xstrdup(refname);\n \tlock->count = 1;\n+\tcb_data.lk = &lock->lk;\n+\tcb_data.repo = refs->base.repo;\n \n-\tif (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {\n+\tif (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {\n \t\tunable_to_lock_message(ref_file.buf, errno, err);\n \t\tgoto error_return;\n \t}\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex d79e35fd26..e4cfd9e19e 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -43,7 +43,7 @@ struct ref_transaction;\n  * Return the length of time to retry acquiring a loose reference lock\n  * before giving up, in milliseconds:\n  */\n-long get_files_ref_lock_timeout_ms(void);\n+long get_files_ref_lock_timeout_ms(struct repository *repo);\n \n /*\n  * Return true iff refname is minimally safe. \"Safe\" here means that\n-- \n2.53.0\n"},{"id":"539959","messageId":"20260325164833.1216577-4-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260325164833.1216577-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 3/5] refs: remove the_hash_algo global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-25T16:44:20Z","receivedAt":"2026-03-25T16:48:59Z","isPatch":true,"body":"refs.c uses the_hash_algo in multiple places, relying on global state for\nthe object hash algorithm. Replace these uses with the appropriate\nrepository-specific hash_algo. In transaction-related functions\n(ref_transaction_create, ref_transaction_delete, migrate_one_ref, and\ntransaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo.\nIn other cases, such as repo_get_submodule_ref_store(), use\nrepo->hash_algo.\n\nThis removes implicit reliance on global state. With no remaining uses of\nthe_repository in this file, drop USE_THE_REPOSITORY_VARIABLE and the\ndependency on environment.h.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c | 15 ++++++---------\n 1 file changed, 6 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex e7256b3a84..7762babf5f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2,13 +2,10 @@\n  * The backend-independent part of the reference module.\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n #include \"config.h\"\n-#include \"environment.h\"\n #include \"strmap.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n@@ -1473,7 +1470,7 @@ int ref_transaction_create(struct ref_transaction *transaction,\n \t\treturn 1;\n \t}\n \treturn ref_transaction_update(transaction, refname, new_oid,\n-\t\t\t\t      null_oid(the_hash_algo), new_target, NULL, flags,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,\n \t\t\t\t      msg, err);\n }\n \n@@ -1492,7 +1489,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,\n \tif (old_target && !(flags & REF_NO_DEREF))\n \t\tBUG(\"delete cannot operate on symrefs with deref mode\");\n \treturn ref_transaction_update(transaction, refname,\n-\t\t\t\t      null_oid(the_hash_algo), old_oid,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), old_oid,\n \t\t\t\t      NULL, old_target, flags,\n \t\t\t\t      msg, err);\n }\n@@ -2380,7 +2377,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,\n \tsubrepo = xmalloc(sizeof(*subrepo));\n \n \tif (repo_submodule_init(subrepo, repo, submodule,\n-\t\t\t\tnull_oid(the_hash_algo))) {\n+\t\t\t\tnull_oid(repo->hash_algo))) {\n \t\tfree(subrepo);\n \t\tgoto done;\n \t}\n@@ -2572,14 +2569,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_\n \tstrbuf_reset(buf);\n \n \tif (!(update->flags & REF_HAVE_OLD))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->old_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->old_target);\n \telse\n \t\tstrbuf_addf(buf, \"%s \", oid_to_hex(&update->old_oid));\n \n \tif (!(update->flags & REF_HAVE_NEW))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->new_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->new_target);\n \telse\n@@ -3154,7 +3151,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)\n \t\tif (ret < 0)\n \t\t\tgoto done;\n \n-\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n+\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(data->transaction->ref_store->repo->hash_algo),\n \t\t\t\t\t     symref_target.buf, NULL,\n \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n \t\tif (ret < 0)\n-- \n2.53.0\n\n"},{"id":"539960","messageId":"20260325164833.1216577-5-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260325164833.1216577-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 4/5] refs/reftable-backend: drop uses of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-25T16:44:21Z","receivedAt":"2026-03-25T16:49:02Z","isPatch":true,"body":"reftable_be_init() and reftable_be_create_on_disk() use the_repository even\nthough a repository instance is already available, either directly or via\nstruct ref_store.\n\nReplace these uses with the appropriate local repository instance (repo or\nref_store->repo) to avoid relying on global state.\n\nNote that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\nis_bare_repository() is still there in the file.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/reftable-backend.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex b124404663..7c8a992fcb 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -404,13 +404,13 @@ static struct ref_store *reftable_be_init(struct repository *repo,\n \tdefault:\n \t\tBUG(\"unknown hash algorithm %d\", repo->hash_algo->format_id);\n \t}\n-\trefs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask);\n+\trefs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask);\n \trefs->write_options.disable_auto_compact =\n \t\t!git_env_bool(\"GIT_TEST_REFTABLE_AUTOCOMPACTION\", 1);\n \trefs->write_options.lock_timeout_ms = 100;\n \trefs->write_options.fsync = reftable_be_fsync;\n \n-\trepo_config(the_repository, reftable_be_config, &refs->write_options);\n+\trepo_config(repo, reftable_be_config, &refs->write_options);\n \n \t/*\n \t * It is somewhat unfortunate that we have to mirror the default block\n@@ -492,7 +492,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,\n \tstruct strbuf sb = STRBUF_INIT;\n \n \tstrbuf_addf(&sb, \"%s/reftable\", refs->base.gitdir);\n-\tsafe_create_dir(the_repository, sb.buf, 1);\n+\tsafe_create_dir(ref_store->repo, sb.buf, 1);\n \tstrbuf_reset(&sb);\n \n \tstrbuf_release(&sb);\n-- \n2.53.0\n"},{"id":"539961","messageId":"20260325164833.1216577-6-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260325164833.1216577-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH 5/5] refs/packed-backend: use ref_store->repo instead of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-25T16:44:22Z","receivedAt":"2026-03-25T16:49:05Z","isPatch":true,"body":"In refs/packed-backend.c, repo_config_get_int() is called using the global\nthe_repository, even though a repository instance is available via struct\nref_store.\n\nReplace the use of the_repository with ref_store->repo to make the code\nexplicitly repository-aware. With no remaining users of the_repository in\nthis file, drop the USE_THE_REPOSITORY_VARIABLE macro.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/packed-backend.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex 23ed62984b..ebc10dab4d 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"../git-compat-util.h\"\n@@ -1223,7 +1222,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)\n \tstatic int timeout_value = 1000;\n \n \tif (!timeout_configured) {\n-\t\trepo_config_get_int(the_repository, \"core.packedrefstimeout\", &timeout_value);\n+\t\trepo_config_get_int(ref_store->repo, \"core.packedrefstimeout\", &timeout_value);\n \t\ttimeout_configured = 1;\n \t}\n \n-- \n2.53.0\n\n"},{"id":"540165","messageId":"acY2pZnCSEf5hcWZ@pks.im","threadId":"65352","inReplyTo":"20260325164833.1216577-2-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH 1/5] refs: make branchname helpers repository aware","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-03-27T07:49:57Z","receivedAt":"2026-03-27T07:50:05Z","isPatch":true,"body":"On Wed, Mar 25, 2026 at 10:14:18PM +0530, Shreyansh Paliwal wrote:\n> diff --git a/branch.h b/branch.h\n> index 3dc6e2a0ff..3aa53eb243 100644\n> --- a/branch.h\n> +++ b/branch.h\n> @@ -111,7 +111,7 @@ const char *branch_checked_out(const char *refname);\n>   * Return 1 if the named branch already exists; return 0 otherwise.\n>   * Fill ref with the full refname for the branch.\n>   */\n> -int validate_branchname(const char *name, struct strbuf *ref);\n> +int validate_branchname(const char *name, struct strbuf *ref, struct repository *repo);\n>  \n>  /*\n>   * Check if a branch 'name' can be created as a new branch; die otherwise.\n> @@ -119,7 +119,8 @@ int validate_branchname(const char *name, struct strbuf *ref);\n>   * Return 1 if the named branch already exists; return 0 otherwise.\n>   * Fill ref with the full refname for the branch.\n>   */\n> -int validate_new_branchname(const char *name, struct strbuf *ref, int force);\n> +int validate_new_branchname(const char *name, struct strbuf *ref, int force,\n> +\t\t\t    struct repository *repo);\n>  \n>  /*\n>   * Remove information about the merge state on the current\n\nIt's more customary in our code base to have the repository be the first\nparameter. Other than that this patch looks good to me.\n\nPatrick\n"},{"id":"540166","messageId":"acY2rALGa-CdYK1J@pks.im","threadId":"65352","inReplyTo":"20260325164833.1216577-3-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-03-27T07:50:04Z","receivedAt":"2026-03-27T07:50:09Z","isPatch":true,"body":"On Wed, Mar 25, 2026 at 10:14:19PM +0530, Shreyansh Paliwal wrote:\n> diff --git a/refs/files-backend.c b/refs/files-backend.c\n> index 7ce0d57478..ee8dd771a4 100644\n> --- a/refs/files-backend.c\n> +++ b/refs/files-backend.c\n> @@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)\n>  \treturn remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);\n>  }\n>  \n> +struct create_reflock_cb {\n> +    struct lock_file *lk;\n> +    struct repository *repo;\n> +};\n> +\n>  static int create_reflock(const char *path, void *cb)\n>  {\n> -\tstruct lock_file *lk = cb;\n> -\n> +\tstruct create_reflock_cb *data = cb;\n>  \treturn hold_lock_file_for_update_timeout(\n> -\t\t\tlk, path, LOCK_NO_DEREF,\n> -\t\t\tget_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;\n> +\t\t\tdata->lk, path, LOCK_NO_DEREF,\n> +\t\t\tget_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;\n>  }\n>  \n>  /*\n\nMakes sense. This function is used as a callback to\n`raceproof_create_file()`, and that callsite is adapted accordingly to\npass the new struct as payload.\n\nPatrick\n"},{"id":"540167","messageId":"acY2suRJ4OlNHYu7@pks.im","threadId":"65352","inReplyTo":"20260325164833.1216577-5-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH 4/5] refs/reftable-backend: drop uses of the_repository","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-03-27T07:50:10Z","receivedAt":"2026-03-27T07:50:15Z","isPatch":true,"body":"On Wed, Mar 25, 2026 at 10:14:21PM +0530, Shreyansh Paliwal wrote:\n> reftable_be_init() and reftable_be_create_on_disk() use the_repository even\n> though a repository instance is already available, either directly or via\n> struct ref_store.\n> \n> Replace these uses with the appropriate local repository instance (repo or\n> ref_store->repo) to avoid relying on global state.\n> \n> Note that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\n> is_bare_repository() is still there in the file.\n\nYeah, `is_bare_repository()` is a blocker in many files :(\n\nPatrick\n"},{"id":"540173","messageId":"DHDGF1CL2QHP.101BB8D2101N8@gmail.com","threadId":"65352","inReplyTo":"20260325164833.1216577-3-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware","fromName":"Burak Kaan Karaçay","fromEmail":"bkkaracay@gmail.com","sentAt":"2026-03-27T09:23:59Z","receivedAt":"2026-03-27T09:24:03Z","isPatch":true,"body":"On Wed Mar 25, 2026 at 7:44 PM +03, Shreyansh Paliwal wrote:\n> -long get_files_ref_lock_timeout_ms(void)\n> +long get_files_ref_lock_timeout_ms(struct repository *repo)\n>  {\n>  \tstatic int configured = 0;\n>  \n> @@ -998,7 +998,7 @@ long get_files_ref_lock_timeout_ms(void)\n>  \tstatic int timeout_ms = 100;\n>  \n>  \tif (!configured) {\n> -\t\trepo_config_get_int(the_repository, \"core.filesreflocktimeout\", &timeout_ms);\n> +\t\trepo_config_get_int(repo, \"core.filesreflocktimeout\", &timeout_ms);\n>  \t\tconfigured = 1;\n>  \t}\n>  \n\nLooks like the existing code uses static local variables for\nperformance. They can behave unexpectedly in multi-repo cases.\n\nI think moving the config into 'repo-settings' should be considered. The\nconfig is already lazy-parsed, migrating it shouldn't be a problem.\n\nBest,\nBurak Kaan Karaçay \n"},{"id":"540265","messageId":"CAPYXD65H87wfffuvGWZtnvn19-2kwQFc1bzLHpyw-3X8QC9qvQ@mail.gmail.com","threadId":"65352","inReplyTo":"acY2pZnCSEf5hcWZ@pks.im","subject":"Re: [PATCH 1/5] refs: make branchname helpers repository aware","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T12:45:30Z","receivedAt":"2026-03-28T12:45:42Z","isPatch":true,"body":"On Fri, Mar 27, 2026 at 1:20 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Wed, Mar 25, 2026 at 10:14:18PM +0530, Shreyansh Paliwal wrote:\n> > diff --git a/branch.h b/branch.h\n> > index 3dc6e2a0ff..3aa53eb243 100644\n> > --- a/branch.h\n> > +++ b/branch.h\n> > @@ -111,7 +111,7 @@ const char *branch_checked_out(const char *refname);\n> >   * Return 1 if the named branch already exists; return 0 otherwise.\n> >   * Fill ref with the full refname for the branch.\n> >   */\n> > -int validate_branchname(const char *name, struct strbuf *ref);\n> > +int validate_branchname(const char *name, struct strbuf *ref, struct repository *repo);\n> >\n> >  /*\n> >   * Check if a branch 'name' can be created as a new branch; die otherwise.\n> > @@ -119,7 +119,8 @@ int validate_branchname(const char *name, struct strbuf *ref);\n> >   * Return 1 if the named branch already exists; return 0 otherwise.\n> >   * Fill ref with the full refname for the branch.\n> >   */\n> > -int validate_new_branchname(const char *name, struct strbuf *ref, int force);\n> > +int validate_new_branchname(const char *name, struct strbuf *ref, int force,\n> > +                         struct repository *repo);\n> >\n> >  /*\n> >   * Remove information about the merge state on the current\n>\n> It's more customary in our code base to have the repository be the first\n> parameter. Other than that this patch looks good to me.\n\nGot it. I will send a reroll for that.\nThanks for reviewing.\n"},{"id":"540266","messageId":"CAPYXD67BV5-FjvGVv1gcV2Fp8H3d815EZO0PVDWPfq=hJYP=Mg@mail.gmail.com","threadId":"65352","inReplyTo":"DHDGF1CL2QHP.101BB8D2101N8@gmail.com","subject":"Re: [PATCH 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T12:51:58Z","receivedAt":"2026-03-28T12:52:10Z","isPatch":true,"body":"On Fri, Mar 27, 2026 at 2:54 PM Burak Kaan Karaçay <bkkaracay@gmail.com> wrote:\n>\n> On Wed Mar 25, 2026 at 7:44 PM +03, Shreyansh Paliwal wrote:\n> > -long get_files_ref_lock_timeout_ms(void)\n> > +long get_files_ref_lock_timeout_ms(struct repository *repo)\n> >  {\n> >       static int configured = 0;\n> >\n> > @@ -998,7 +998,7 @@ long get_files_ref_lock_timeout_ms(void)\n> >       static int timeout_ms = 100;\n> >\n> >       if (!configured) {\n> > -             repo_config_get_int(the_repository, \"core.filesreflocktimeout\", &timeout_ms);\n> > +             repo_config_get_int(repo, \"core.filesreflocktimeout\", &timeout_ms);\n> >               configured = 1;\n> >       }\n> >\n>\n> Looks like the existing code uses static local variables for\n> performance. They can behave unexpectedly in multi-repo cases.\n>\n> I think moving the config into 'repo-settings' should be considered. The\n> config is already lazy-parsed, migrating it shouldn't be a problem.\n\nYup, I agree that would be a logical change.\nWe can take that up in a follow-up patch to this. Thanks.\n"},{"id":"540271","messageId":"20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260325164833.1216577-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v2 0/5] refs: reduce reliance on the_repository global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T14:09:31Z","receivedAt":"2026-03-28T14:12:25Z","isPatch":true,"body":"This series continues the effort to reduce reliance on the_repository\nglobal state by making repository context explicit across the refs\nsubsystem. The patches focus on passing struct repository through various\nref helpers and backends, and replacing uses of global state such as\nthe_repository and the_hash_algo with the appropriate repository instance.\n\nPatch 1/5: Making branch name helper functions (copy_branchname(),\ncheck_branch_ref(), validate_branchname(), and validate_new_branchname())\nrepository-aware. (built on top of jw/object-name-bitset-to-enum)\n\nPatch 2/5: Updating get_files_ref_lock_timeout_ms() to take a repository\nand propagating it through files-backend, including callback paths.\n\nPatch 3/5: Replacing uses of the_hash_algo in refs.c with the hash\nalgorithm from the appropriate repository.\n\nPatch 4/5: Removing remaining uses of the_repository in reftable-backend.c\nwhere a repository instance is already available.\n\nPatch 5/5: Replacing the single instance of the_repository in\npacked-backend.c, thus dropping the USE_THE_REPOSITORY_VARIABLE macro.\n\nShreyansh Paliwal (5):\n  refs: make branchname helpers repository aware\n  refs: make get_files_ref_lock_timeout_ms() repostory aware\n  refs: remove the_hash_algo global state\n  refs/reftable-backend: drop uses of the_repository\n  refs/packed-backend: use ref_store->repo instead of the_repository\n\n branch.c                   | 15 ++++++++-------\n branch.h                   |  5 +++--\n builtin/branch.c           | 14 +++++++-------\n builtin/check-ref-format.c |  3 ++-\n builtin/checkout.c         |  6 +++---\n builtin/merge.c            |  2 +-\n builtin/worktree.c         | 10 +++++-----\n refs.c                     | 27 ++++++++++++---------------\n refs.h                     |  4 ++--\n refs/files-backend.c       | 19 +++++++++++++------\n refs/packed-backend.c      |  3 +--\n refs/refs-internal.h       |  2 +-\n refs/reftable-backend.c    |  6 +++---\n 13 files changed, 61 insertions(+), 55 deletions(-)\n\n---\nChanges in v2:\n - Made struct repository the first argument in function parameters.\n\nRange-diff against v1:\n1:  68ca12412b ! 1:  c0182252c4 refs: make branchname helpers repository aware\n    @@ branch.c: int read_branch_desc(struct strbuf *buf, const char *branch_name)\n       * Fill ref with the full refname for the branch.\n       */\n     -int validate_branchname(const char *name, struct strbuf *ref)\n    -+int validate_branchname(const char *name, struct strbuf *ref, struct repository *repo)\n    ++int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref)\n      {\n     -\tif (check_branch_ref(ref, name)) {\n    -+\tif (check_branch_ref(ref, name, repo)) {\n    ++\tif (check_branch_ref(repo, ref, name)) {\n      \t\tint code = die_message(_(\"'%s' is not a valid branch name\"), name);\n      \t\tadvise_if_enabled(ADVICE_REF_SYNTAX,\n      \t\t\t\t  _(\"See 'git help check-ref-format'\"));\n    @@ branch.c: const char *branch_checked_out(const char *refname)\n       * Fill ref with the full refname for the branch.\n       */\n     -int validate_new_branchname(const char *name, struct strbuf *ref, int force)\n    -+int validate_new_branchname(const char *name, struct strbuf *ref, int force,\n    -+\t\t\t    struct repository *repo)\n    ++int validate_new_branchname(struct repository *repo, const char *name,\n    ++\t\t\t    struct strbuf *ref, int force)\n      {\n      \tconst char *path;\n     -\tif (!validate_branchname(name, ref))\n    -+\tif (!validate_branchname(name, ref, repo))\n    ++\tif (!validate_branchname(repo, name, ref))\n      \t\treturn 0;\n\n      \tif (!force)\n    @@ branch.c: void create_branch(struct repository *r,\n      \tif (clobber_head_ok ?\n     -\t\t\t  validate_branchname(name, &ref) :\n     -\t\t\t  validate_new_branchname(name, &ref, force)) {\n    -+\t\t\t  validate_branchname(name, &ref, r) :\n    -+\t\t\t  validate_new_branchname(name, &ref, force, r)) {\n    ++\t\t\t  validate_branchname(r, name, &ref) :\n    ++\t\t\t  validate_new_branchname(r, name, &ref, force)) {\n      \t\tforcing = 1;\n      \t}\n\n    @@ branch.h: const char *branch_checked_out(const char *refname);\n       * Fill ref with the full refname for the branch.\n       */\n     -int validate_branchname(const char *name, struct strbuf *ref);\n    -+int validate_branchname(const char *name, struct strbuf *ref, struct repository *repo);\n    ++int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref);\n\n      /*\n       * Check if a branch 'name' can be created as a new branch; die otherwise.\n    @@ branch.h: int validate_branchname(const char *name, struct strbuf *ref);\n       * Fill ref with the full refname for the branch.\n       */\n     -int validate_new_branchname(const char *name, struct strbuf *ref, int force);\n    -+int validate_new_branchname(const char *name, struct strbuf *ref, int force,\n    -+\t\t\t    struct repository *repo);\n    ++int validate_new_branchname(struct repository *repo, const char *name,\n    ++\t\t\t    struct strbuf *ref, int force);\n\n      /*\n       * Remove information about the merge state on the current\n    @@ builtin/branch.c: static int delete_branches(int argc, const char **argv, int fo\n      \t\tint flags = 0;\n\n     -\t\tcopy_branchname(&bname, argv[i], allowed_interpret);\n    -+\t\tcopy_branchname(&bname, argv[i], allowed_interpret, the_repository);\n    ++\t\tcopy_branchname(the_repository, &bname, argv[i], allowed_interpret);\n      \t\tfree(name);\n      \t\tname = mkpathdup(fmt, bname.buf);\n\n    @@ builtin/branch.c: static void copy_or_rename_branch(const char *oldname, const c\n      \tstruct worktree **worktrees = get_worktrees();\n\n     -\tif (check_branch_ref(&oldref, oldname)) {\n    -+\tif (check_branch_ref(&oldref, oldname, the_repository)) {\n    ++\tif (check_branch_ref(the_repository, &oldref, oldname)) {\n      \t\t/*\n      \t\t * Bad name --- this could be an attempt to rename a\n      \t\t * ref that we used to allow to be created by accident.\n    @@ builtin/branch.c: static void copy_or_rename_branch(const char *oldname, const c\n      \t */\n      \tif (!strcmp(oldname, newname))\n     -\t\tvalidate_branchname(newname, &newref);\n    -+\t\tvalidate_branchname(newname, &newref, the_repository);\n    ++\t\tvalidate_branchname(the_repository, newname, &newref);\n      \telse\n     -\t\tvalidate_new_branchname(newname, &newref, force);\n    -+\t\tvalidate_new_branchname(newname, &newref, force, the_repository);\n    ++\t\tvalidate_new_branchname(the_repository, newname, &newref, force);\n\n      \treject_rebase_or_bisect_branch(worktrees, oldref.buf);\n\n    @@ builtin/branch.c: int cmd_branch(int argc,\n      \t\t\tbranch_name = head;\n      \t\t} else if (argc == 1) {\n     -\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    -+\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL, the_repository);\n    ++\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n      \t\t\tbranch_name = buf.buf;\n      \t\t} else {\n      \t\t\tdie(_(\"cannot edit description of more than one branch\"));\n    @@ builtin/branch.c: int cmd_branch(int argc,\n      \t\t\tbranch = branch_get(NULL);\n      \t\telse if (argc == 1) {\n     -\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    -+\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL, the_repository);\n    ++\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n      \t\t\tbranch = branch_get(buf.buf);\n      \t\t} else\n      \t\t\tdie(_(\"too many arguments to set new upstream\"));\n    @@ builtin/branch.c: int cmd_branch(int argc,\n      \t\t\tbranch = branch_get(NULL);\n      \t\telse if (argc == 1) {\n     -\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    -+\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL, the_repository);\n    ++\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n      \t\t\tbranch = branch_get(buf.buf);\n      \t\t} else\n      \t\t\tdie(_(\"too many arguments to unset upstream\"));\n    @@ builtin/check-ref-format.c: static int check_ref_format_branch(const char *arg)\n\n      \tsetup_git_directory_gently(&nongit);\n     -\tif (check_branch_ref(&sb, arg) ||\n    -+\tif (check_branch_ref(&sb, arg, the_repository) ||\n    ++\tif (check_branch_ref(the_repository, &sb, arg) ||\n      \t    !skip_prefix(sb.buf, \"refs/heads/\", &name))\n      \t\tdie(\"'%s' is not a valid branch name\", arg);\n      \tprintf(\"%s\\n\", name);\n    @@ builtin/checkout.c: static void setup_branch_path(struct branch_info *branch)\n      \t\trepo_get_oid_committish(the_repository, branch->name, &branch->oid);\n\n     -\tcopy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);\n    -+\tcopy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL, the_repository);\n    ++\tcopy_branchname(the_repository, &buf, branch->name, INTERPRET_BRANCH_LOCAL);\n      \tif (strcmp(buf.buf, branch->name)) {\n      \t\tfree(branch->name);\n      \t\tbranch->name = xstrdup(buf.buf);\n    @@ builtin/checkout.c: static int checkout_main(int argc, const char **argv, const\n\n      \t\tif (opts->new_branch_force)\n     -\t\t\topts->branch_exists = validate_branchname(opts->new_branch, &buf);\n    -+\t\t\topts->branch_exists = validate_branchname(opts->new_branch, &buf, the_repository);\n    ++\t\t\topts->branch_exists = validate_branchname(the_repository, opts->new_branch, &buf);\n      \t\telse\n      \t\t\topts->branch_exists =\n     -\t\t\t\tvalidate_new_branchname(opts->new_branch, &buf, 0);\n    -+\t\t\t\tvalidate_new_branchname(opts->new_branch, &buf, 0, the_repository);\n    ++\t\t\t\tvalidate_new_branchname(the_repository, opts->new_branch, &buf, 0);\n      \t\tstrbuf_release(&buf);\n      \t}\n\n    @@ builtin/merge.c: static void merge_name(const char *remote, struct strbuf *msg)\n      \tint len, early;\n\n     -\tcopy_branchname(&bname, remote, 0);\n    -+\tcopy_branchname(&bname, remote, 0, the_repository);\n    ++\tcopy_branchname(the_repository, &bname, remote, 0);\n      \tremote = bname.buf;\n\n      \toidclr(&branch_head, the_repository->hash_algo);\n    @@ builtin/worktree.c: static int make_worktree_orphan(const char * ref, const stru\n      \tstruct child_process cp = CHILD_PROCESS_INIT;\n\n     -\tvalidate_new_branchname(ref, &symref, 0);\n    -+\tvalidate_new_branchname(ref, &symref, 0, the_repository);\n    ++\tvalidate_new_branchname(the_repository, ref, &symref, 0);\n      \tstrvec_pushl(&cp.args, \"symbolic-ref\", \"HEAD\", symref.buf, NULL);\n      \tif (opts->quiet)\n      \t\tstrvec_push(&cp.args, \"--quiet\");\n    @@ builtin/worktree.c: static int add_worktree(const char *path, const char *refnam\n\n      \t/* is 'refname' a branch or commit? */\n     -\tif (!opts->detach && !check_branch_ref(&symref, refname) &&\n    -+\tif (!opts->detach && !check_branch_ref(&symref, refname, the_repository) &&\n    ++\tif (!opts->detach && !check_branch_ref(the_repository, &symref, refname) &&\n      \t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {\n      \t\tis_branch = 1;\n      \t\tif (!opts->force)\n    @@ builtin/worktree.c: static void print_preparing_worktree_line(int detach,\n      \t} else {\n      \t\tstruct strbuf s = STRBUF_INIT;\n     -\t\tif (!detach && !check_branch_ref(&s, branch) &&\n    -+\t\tif (!detach && !check_branch_ref(&s, branch, the_repository) &&\n    ++\t\tif (!detach && !check_branch_ref(the_repository, &s, branch) &&\n      \t\t    refs_ref_exists(get_main_ref_store(the_repository), s.buf))\n      \t\t\tfprintf_ln(stderr, _(\"Preparing worktree (checking out '%s')\"),\n      \t\t\t\t  branch);\n    @@ builtin/worktree.c: static char *dwim_branch(const char *path, char **new_branch\n      \tstruct strbuf ref = STRBUF_INIT;\n\n     -\tbranch_exists = !check_branch_ref(&ref, branchname) &&\n    -+\tbranch_exists = !check_branch_ref(&ref, branchname, the_repository) &&\n    ++\tbranch_exists = !check_branch_ref(the_repository, &ref, branchname) &&\n      \t\t\trefs_ref_exists(get_main_ref_store(the_repository),\n      \t\t\t\t\tref.buf);\n      \tstrbuf_release(&ref);\n    @@ builtin/worktree.c: static int add(int ac, const char **av, const char *prefix,\n\n      \t\tif (!opts.force &&\n     -\t\t    !check_branch_ref(&symref, new_branch) &&\n    -+\t\t    !check_branch_ref(&symref, new_branch, the_repository) &&\n    ++\t\t    !check_branch_ref(the_repository, &symref, new_branch) &&\n      \t\t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf))\n      \t\t\tdie_if_checked_out(symref.buf, 0);\n      \t\tstrbuf_release(&symref);\n\n      ## refs.c ##\n     @@ refs.c: static char *substitute_branch_name(struct repository *r,\n    + \treturn NULL;\n      }\n\n    - void copy_branchname(struct strbuf *sb, const char *name,\n    --\t\t     enum interpret_branch_kind allowed)\n    -+\t\t     enum interpret_branch_kind allowed,\n    -+\t\t     struct repository *repo)\n    +-void copy_branchname(struct strbuf *sb, const char *name,\n    ++void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n    + \t\t     enum interpret_branch_kind allowed)\n      {\n      \tint len = strlen(name);\n      \tstruct interpret_branch_name_options options = {\n    @@ refs.c: void copy_branchname(struct strbuf *sb, const char *name,\n      }\n\n     -int check_branch_ref(struct strbuf *sb, const char *name)\n    -+int check_branch_ref(struct strbuf *sb, const char *name, struct repository *repo)\n    ++int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n      {\n      \tif (startup_info->have_repository)\n     -\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n    -+\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL, repo);\n    ++\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n      \telse\n      \t\tstrbuf_addstr(sb, name);\n\n\n      ## refs.h ##\n     @@ refs.h: char *repo_default_branch_name(struct repository *r, int quiet);\n    +  * If \"allowed\" is non-zero, restrict the set of allowed expansions. See\n       * repo_interpret_branch_name() for details.\n       */\n    - void copy_branchname(struct strbuf *sb, const char *name,\n    --\t\t     enum interpret_branch_kind allowed);\n    -+\t\t     enum interpret_branch_kind allowed,\n    -+\t\t     struct repository *repo);\n    +-void copy_branchname(struct strbuf *sb, const char *name,\n    ++void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n    + \t\t     enum interpret_branch_kind allowed);\n\n      /*\n    -  * Like copy_branchname() above, but confirm that the result is\n     @@ refs.h: void copy_branchname(struct strbuf *sb, const char *name,\n       *\n       * The return value is \"0\" if the result is valid, and \"-1\" otherwise.\n       */\n     -int check_branch_ref(struct strbuf *sb, const char *name);\n    -+int check_branch_ref(struct strbuf *sb, const char *name, struct repository *repo);\n    ++int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name);\n\n      /*\n       * Similar for a tag name in refs/tags/.\n2:  9bfbfc38b8 = 2:  857a8c40fe refs: make get_files_ref_lock_timeout_ms() repostory aware\n3:  6f9854845e = 3:  46d5272aec refs: remove the_hash_algo global state\n4:  1c02f780d1 = 4:  11aa886259 refs/reftable-backend: drop uses of the_repository\n5:  33946503e1 = 5:  c763732964 refs/packed-backend: use ref_store->repo instead of the_repository\n--\n2.53.0\n\n"},{"id":"540272","messageId":"20260328141146.1095115-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v2 1/5] refs: make branchname helpers repository aware","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T14:09:32Z","receivedAt":"2026-03-28T14:12:29Z","isPatch":true,"body":"copy_branchname() in refs.c relies on the_repository when calling\nrepo_interpret_branch_name(), introducing an implicit dependency on global\nstate. Add a struct repository parameter and use it instead.\n\nUpdate check_branch_ref() to take a repository parameter as well, since it\ncalls copy_branchname(). Propagate this change to higher-level helpers\nvalidate_branchname() and validate_new_branchname(), which also lack access\nto a repository instance. Most callers of these helpers reside in builtin\ncode and already operate on the_repository, so pass it explicitly at those\ncall sites (builtin/checkout and builtin/worktree) otherwise pass struct\nrepository where available.\n\nThis makes branch name handling explicitly repository-aware and aligns with\nongoing efforts to remove reliance on global state. This change builds on\ntop of jw/object-name-bitset-to-enum (2026-03-18), which introduced the\nenum interpret_branch_kind parameter to copy_branchname().\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n branch.c                   | 15 ++++++++-------\n branch.h                   |  5 +++--\n builtin/branch.c           | 14 +++++++-------\n builtin/check-ref-format.c |  3 ++-\n builtin/checkout.c         |  6 +++---\n builtin/merge.c            |  2 +-\n builtin/worktree.c         | 10 +++++-----\n refs.c                     |  8 ++++----\n refs.h                     |  4 ++--\n 9 files changed, 35 insertions(+), 32 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 243db7d0fc..63a9c0c238 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -370,16 +370,16 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_branchname(const char *name, struct strbuf *ref)\n+int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref)\n {\n-\tif (check_branch_ref(ref, name)) {\n+\tif (check_branch_ref(repo, ref, name)) {\n \t\tint code = die_message(_(\"'%s' is not a valid branch name\"), name);\n \t\tadvise_if_enabled(ADVICE_REF_SYNTAX,\n \t\t\t\t  _(\"See 'git help check-ref-format'\"));\n \t\texit(code);\n \t}\n \n-\treturn refs_ref_exists(get_main_ref_store(the_repository), ref->buf);\n+\treturn refs_ref_exists(get_main_ref_store(repo), ref->buf);\n }\n \n static int initialized_checked_out_branches;\n@@ -468,10 +468,11 @@ const char *branch_checked_out(const char *refname)\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_new_branchname(const char *name, struct strbuf *ref, int force)\n+int validate_new_branchname(struct repository *repo, const char *name,\n+\t\t\t    struct strbuf *ref, int force)\n {\n \tconst char *path;\n-\tif (!validate_branchname(name, ref))\n+\tif (!validate_branchname(repo, name, ref))\n \t\treturn 0;\n \n \tif (!force)\n@@ -613,8 +614,8 @@ void create_branch(struct repository *r,\n \t\tBUG(\"'clobber_head_ok' can only be used with 'force'\");\n \n \tif (clobber_head_ok ?\n-\t\t\t  validate_branchname(name, &ref) :\n-\t\t\t  validate_new_branchname(name, &ref, force)) {\n+\t\t\t  validate_branchname(r, name, &ref) :\n+\t\t\t  validate_new_branchname(r, name, &ref, force)) {\n \t\tforcing = 1;\n \t}\n \ndiff --git a/branch.h b/branch.h\nindex 3dc6e2a0ff..b41176ee7f 100644\n--- a/branch.h\n+++ b/branch.h\n@@ -111,7 +111,7 @@ const char *branch_checked_out(const char *refname);\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_branchname(const char *name, struct strbuf *ref);\n+int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref);\n \n /*\n  * Check if a branch 'name' can be created as a new branch; die otherwise.\n@@ -119,7 +119,8 @@ int validate_branchname(const char *name, struct strbuf *ref);\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_new_branchname(const char *name, struct strbuf *ref, int force);\n+int validate_new_branchname(struct repository *repo, const char *name,\n+\t\t\t    struct strbuf *ref, int force);\n \n /*\n  * Remove information about the merge state on the current\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 1572a4f9ef..ea4109f893 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -259,7 +259,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\tchar *target = NULL;\n \t\tint flags = 0;\n \n-\t\tcopy_branchname(&bname, argv[i], allowed_interpret);\n+\t\tcopy_branchname(the_repository, &bname, argv[i], allowed_interpret);\n \t\tfree(name);\n \t\tname = mkpathdup(fmt, bname.buf);\n \n@@ -581,7 +581,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \tint recovery = 0, oldref_usage = 0;\n \tstruct worktree **worktrees = get_worktrees();\n \n-\tif (check_branch_ref(&oldref, oldname)) {\n+\tif (check_branch_ref(the_repository, &oldref, oldname)) {\n \t\t/*\n \t\t * Bad name --- this could be an attempt to rename a\n \t\t * ref that we used to allow to be created by accident.\n@@ -619,9 +619,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t * cause the worktree to become inconsistent with HEAD, so allow it.\n \t */\n \tif (!strcmp(oldname, newname))\n-\t\tvalidate_branchname(newname, &newref);\n+\t\tvalidate_branchname(the_repository, newname, &newref);\n \telse\n-\t\tvalidate_new_branchname(newname, &newref, force);\n+\t\tvalidate_new_branchname(the_repository, newname, &newref, force);\n \n \treject_rebase_or_bisect_branch(worktrees, oldref.buf);\n \n@@ -898,7 +898,7 @@ int cmd_branch(int argc,\n \t\t\t\tdie(_(\"cannot give description to detached HEAD\"));\n \t\t\tbranch_name = head;\n \t\t} else if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n \t\t\tbranch_name = buf.buf;\n \t\t} else {\n \t\t\tdie(_(\"cannot edit description of more than one branch\"));\n@@ -941,7 +941,7 @@ int cmd_branch(int argc,\n \t\tif (!argc)\n \t\t\tbranch = branch_get(NULL);\n \t\telse if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n \t\t\tbranch = branch_get(buf.buf);\n \t\t} else\n \t\t\tdie(_(\"too many arguments to set new upstream\"));\n@@ -971,7 +971,7 @@ int cmd_branch(int argc,\n \t\tif (!argc)\n \t\t\tbranch = branch_get(NULL);\n \t\telse if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n \t\t\tbranch = branch_get(buf.buf);\n \t\t} else\n \t\t\tdie(_(\"too many arguments to unset upstream\"));\ndiff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c\nindex 5d80afeec0..28e77102d3 100644\n--- a/builtin/check-ref-format.c\n+++ b/builtin/check-ref-format.c\n@@ -5,6 +5,7 @@\n #include \"refs.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n+#include \"repository.c\"\n \n static const char builtin_check_ref_format_usage[] =\n \"git check-ref-format [--normalize] [<options>] <refname>\\n\"\n@@ -42,7 +43,7 @@ static int check_ref_format_branch(const char *arg)\n \tint nongit;\n \n \tsetup_git_directory_gently(&nongit);\n-\tif (check_branch_ref(&sb, arg) ||\n+\tif (check_branch_ref(the_repository, &sb, arg) ||\n \t    !skip_prefix(sb.buf, \"refs/heads/\", &name))\n \t\tdie(\"'%s' is not a valid branch name\", arg);\n \tprintf(\"%s\\n\", name);\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex e031e61886..93ad894dc2 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -743,7 +743,7 @@ static void setup_branch_path(struct branch_info *branch)\n \t\t\t   &branch->oid, &branch->refname, 0))\n \t\trepo_get_oid_committish(the_repository, branch->name, &branch->oid);\n \n-\tcopy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);\n+\tcopy_branchname(the_repository, &buf, branch->name, INTERPRET_BRANCH_LOCAL);\n \tif (strcmp(buf.buf, branch->name)) {\n \t\tfree(branch->name);\n \t\tbranch->name = xstrdup(buf.buf);\n@@ -2014,10 +2014,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \n \t\tif (opts->new_branch_force)\n-\t\t\topts->branch_exists = validate_branchname(opts->new_branch, &buf);\n+\t\t\topts->branch_exists = validate_branchname(the_repository, opts->new_branch, &buf);\n \t\telse\n \t\t\topts->branch_exists =\n-\t\t\t\tvalidate_new_branchname(opts->new_branch, &buf, 0);\n+\t\t\t\tvalidate_new_branchname(the_repository, opts->new_branch, &buf, 0);\n \t\tstrbuf_release(&buf);\n \t}\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 2cbce56f8d..3f4b9dc47a 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -552,7 +552,7 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \tchar *found_ref = NULL;\n \tint len, early;\n \n-\tcopy_branchname(&bname, remote, 0);\n+\tcopy_branchname(the_repository, &bname, remote, 0);\n \tremote = bname.buf;\n \n \toidclr(&branch_head, the_repository->hash_algo);\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 4035b1cb06..a5e116d8f9 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -415,7 +415,7 @@ static int make_worktree_orphan(const char * ref, const struct add_opts *opts,\n \tstruct strbuf symref = STRBUF_INIT;\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n \n-\tvalidate_new_branchname(ref, &symref, 0);\n+\tvalidate_new_branchname(the_repository, ref, &symref, 0);\n \tstrvec_pushl(&cp.args, \"symbolic-ref\", \"HEAD\", symref.buf, NULL);\n \tif (opts->quiet)\n \t\tstrvec_push(&cp.args, \"--quiet\");\n@@ -481,7 +481,7 @@ static int add_worktree(const char *path, const char *refname,\n \tworktrees = NULL;\n \n \t/* is 'refname' a branch or commit? */\n-\tif (!opts->detach && !check_branch_ref(&symref, refname) &&\n+\tif (!opts->detach && !check_branch_ref(the_repository, &symref, refname) &&\n \t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {\n \t\tis_branch = 1;\n \t\tif (!opts->force)\n@@ -649,7 +649,7 @@ static void print_preparing_worktree_line(int detach,\n \t\tfprintf_ln(stderr, _(\"Preparing worktree (new branch '%s')\"), new_branch);\n \t} else {\n \t\tstruct strbuf s = STRBUF_INIT;\n-\t\tif (!detach && !check_branch_ref(&s, branch) &&\n+\t\tif (!detach && !check_branch_ref(the_repository, &s, branch) &&\n \t\t    refs_ref_exists(get_main_ref_store(the_repository), s.buf))\n \t\t\tfprintf_ln(stderr, _(\"Preparing worktree (checking out '%s')\"),\n \t\t\t\t  branch);\n@@ -788,7 +788,7 @@ static char *dwim_branch(const char *path, char **new_branch)\n \tchar *branchname = xstrndup(s, n);\n \tstruct strbuf ref = STRBUF_INIT;\n \n-\tbranch_exists = !check_branch_ref(&ref, branchname) &&\n+\tbranch_exists = !check_branch_ref(the_repository, &ref, branchname) &&\n \t\t\trefs_ref_exists(get_main_ref_store(the_repository),\n \t\t\t\t\tref.buf);\n \tstrbuf_release(&ref);\n@@ -885,7 +885,7 @@ static int add(int ac, const char **av, const char *prefix,\n \t\tnew_branch = new_branch_force;\n \n \t\tif (!opts.force &&\n-\t\t    !check_branch_ref(&symref, new_branch) &&\n+\t\t    !check_branch_ref(the_repository, &symref, new_branch) &&\n \t\t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf))\n \t\t\tdie_if_checked_out(symref.buf, 0);\n \t\tstrbuf_release(&symref);\ndiff --git a/refs.c b/refs.c\nindex 685a0c247b..5cdc8858c5 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -743,14 +743,14 @@ static char *substitute_branch_name(struct repository *r,\n \treturn NULL;\n }\n \n-void copy_branchname(struct strbuf *sb, const char *name,\n+void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n \t\t     enum interpret_branch_kind allowed)\n {\n \tint len = strlen(name);\n \tstruct interpret_branch_name_options options = {\n \t\t.allowed = allowed\n \t};\n-\tint used = repo_interpret_branch_name(the_repository, name, len, sb,\n+\tint used = repo_interpret_branch_name(repo, name, len, sb,\n \t\t\t\t\t      &options);\n \n \tif (used < 0)\n@@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,\n \tstrbuf_add(sb, name + used, len - used);\n }\n \n-int check_branch_ref(struct strbuf *sb, const char *name)\n+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n {\n \tif (startup_info->have_repository)\n-\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n+\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n \telse\n \t\tstrbuf_addstr(sb, name);\n \ndiff --git a/refs.h b/refs.h\nindex d65de6ab5f..5407a4c4d6 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -225,7 +225,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);\n  * If \"allowed\" is non-zero, restrict the set of allowed expansions. See\n  * repo_interpret_branch_name() for details.\n  */\n-void copy_branchname(struct strbuf *sb, const char *name,\n+void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n \t\t     enum interpret_branch_kind allowed);\n \n /*\n@@ -234,7 +234,7 @@ void copy_branchname(struct strbuf *sb, const char *name,\n  *\n  * The return value is \"0\" if the result is valid, and \"-1\" otherwise.\n  */\n-int check_branch_ref(struct strbuf *sb, const char *name);\n+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name);\n \n /*\n  * Similar for a tag name in refs/tags/.\n-- \n2.53.0\n\n"},{"id":"540273","messageId":"20260328141146.1095115-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v2 2/5] refs: make get_files_ref_lock_timeout_ms() repostory aware","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T14:09:33Z","receivedAt":"2026-03-28T14:12:33Z","isPatch":true,"body":"get_files_ref_lock_timeout_ms() calls repo_config_get_int() using\nthe_repository, as no repository instance is available in its scope. Add a\nstruct repository parameter and use it instead of the_repository.\n\nUpdate all callers accordingly. In files-backend.c, lock_raw_ref() can\nobtain repository instance from the struct ref_transaction via\ntransaction->ref_store->repo and pass it down. For create_reflock(), which\nis used as a callback, introduce a small wrapper struct to pass both struct\nlock_file and struct repository through the callback data.\n\nThis removes reliance on the_repository global and makes the timeout lookup\noperate on the correct repository context.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c               |  4 ++--\n refs/files-backend.c | 19 +++++++++++++------\n refs/refs-internal.h |  2 +-\n 3 files changed, 16 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 5cdc8858c5..2f8c8427cd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,\n \treturn REF_WORKTREE_SHARED;\n }\n \n-long get_files_ref_lock_timeout_ms(void)\n+long get_files_ref_lock_timeout_ms(struct repository *repo)\n {\n \tstatic int configured = 0;\n \n@@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)\n \tstatic int timeout_ms = 100;\n \n \tif (!configured) {\n-\t\trepo_config_get_int(the_repository, \"core.filesreflocktimeout\", &timeout_ms);\n+\t\trepo_config_get_int(repo, \"core.filesreflocktimeout\", &timeout_ms);\n \t\tconfigured = 1;\n \t}\n \ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 7ce0d57478..ee8dd771a4 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -792,7 +792,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,\n \n \tif (hold_lock_file_for_update_timeout(\n \t\t\t    &lock->lk, ref_file.buf, LOCK_NO_DEREF,\n-\t\t\t    get_files_ref_lock_timeout_ms()) < 0) {\n+\t\t\t    get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {\n \t\tint myerr = errno;\n \t\terrno = 0;\n \t\tif (myerr == ENOENT && --attempts_remaining > 0) {\n@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)\n \treturn remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);\n }\n \n+struct create_reflock_cb {\n+    struct lock_file *lk;\n+    struct repository *repo;\n+};\n+\n static int create_reflock(const char *path, void *cb)\n {\n-\tstruct lock_file *lk = cb;\n-\n+\tstruct create_reflock_cb *data = cb;\n \treturn hold_lock_file_for_update_timeout(\n-\t\t\tlk, path, LOCK_NO_DEREF,\n-\t\t\tget_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;\n+\t\t\tdata->lk, path, LOCK_NO_DEREF,\n+\t\t\tget_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;\n }\n \n /*\n@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n {\n \tstruct strbuf ref_file = STRBUF_INIT;\n \tstruct ref_lock *lock;\n+\tstruct create_reflock_cb cb_data;\n \n \tfiles_assert_main_repository(refs, \"lock_ref_oid_basic\");\n \tassert(err);\n@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n \n \tlock->ref_name = xstrdup(refname);\n \tlock->count = 1;\n+\tcb_data.lk   = &lock->lk;\n+\tcb_data.repo = refs->base.repo;\n \n-\tif (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {\n+\tif (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {\n \t\tunable_to_lock_message(ref_file.buf, errno, err);\n \t\tgoto error_return;\n \t}\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex d79e35fd26..e4cfd9e19e 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -43,7 +43,7 @@ struct ref_transaction;\n  * Return the length of time to retry acquiring a loose reference lock\n  * before giving up, in milliseconds:\n  */\n-long get_files_ref_lock_timeout_ms(void);\n+long get_files_ref_lock_timeout_ms(struct repository *repo);\n \n /*\n  * Return true iff refname is minimally safe. \"Safe\" here means that\n-- \n2.53.0\n"},{"id":"540274","messageId":"20260328141146.1095115-4-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v2 3/5] refs: remove the_hash_algo global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T14:09:34Z","receivedAt":"2026-03-28T14:12:36Z","isPatch":true,"body":"refs.c uses the_hash_algo in multiple places, relying on global state for\nthe object hash algorithm. Replace these uses with the appropriate\nrepository-specific hash_algo. In transaction-related functions\n(ref_transaction_create, ref_transaction_delete, migrate_one_ref, and\ntransaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo.\nIn other cases, such as repo_get_submodule_ref_store(), use\nrepo->hash_algo.\n\nThis removes implicit reliance on global state. With no remaining uses of\nthe_repository in this file, drop USE_THE_REPOSITORY_VARIABLE and the\ndependency on environment.h.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c | 15 ++++++---------\n 1 file changed, 6 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 2f8c8427cd..54ca87eda9 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2,13 +2,10 @@\n  * The backend-independent part of the reference module.\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n #include \"config.h\"\n-#include \"environment.h\"\n #include \"strmap.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n@@ -1472,7 +1469,7 @@ int ref_transaction_create(struct ref_transaction *transaction,\n \t\treturn 1;\n \t}\n \treturn ref_transaction_update(transaction, refname, new_oid,\n-\t\t\t\t      null_oid(the_hash_algo), new_target, NULL, flags,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,\n \t\t\t\t      msg, err);\n }\n \n@@ -1491,7 +1488,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,\n \tif (old_target && !(flags & REF_NO_DEREF))\n \t\tBUG(\"delete cannot operate on symrefs with deref mode\");\n \treturn ref_transaction_update(transaction, refname,\n-\t\t\t\t      null_oid(the_hash_algo), old_oid,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), old_oid,\n \t\t\t\t      NULL, old_target, flags,\n \t\t\t\t      msg, err);\n }\n@@ -2379,7 +2376,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,\n \tsubrepo = xmalloc(sizeof(*subrepo));\n \n \tif (repo_submodule_init(subrepo, repo, submodule,\n-\t\t\t\tnull_oid(the_hash_algo))) {\n+\t\t\t\tnull_oid(repo->hash_algo))) {\n \t\tfree(subrepo);\n \t\tgoto done;\n \t}\n@@ -2571,14 +2568,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_\n \tstrbuf_reset(buf);\n \n \tif (!(update->flags & REF_HAVE_OLD))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->old_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->old_target);\n \telse\n \t\tstrbuf_addf(buf, \"%s \", oid_to_hex(&update->old_oid));\n \n \tif (!(update->flags & REF_HAVE_NEW))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->new_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->new_target);\n \telse\n@@ -3153,7 +3150,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)\n \t\tif (ret < 0)\n \t\t\tgoto done;\n \n-\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n+\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(data->transaction->ref_store->repo->hash_algo),\n \t\t\t\t\t     symref_target.buf, NULL,\n \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n \t\tif (ret < 0)\n-- \n2.53.0\n\n"},{"id":"540275","messageId":"20260328141146.1095115-5-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v2 4/5] refs/reftable-backend: drop uses of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T14:09:35Z","receivedAt":"2026-03-28T14:12:39Z","isPatch":true,"body":"reftable_be_init() and reftable_be_create_on_disk() use the_repository even\nthough a repository instance is already available, either directly or via\nstruct ref_store.\n\nReplace these uses with the appropriate local repository instance (repo or\nref_store->repo) to avoid relying on global state.\n\nNote that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\nis_bare_repository() is still there in the file.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/reftable-backend.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex b124404663..7c8a992fcb 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -404,13 +404,13 @@ static struct ref_store *reftable_be_init(struct repository *repo,\n \tdefault:\n \t\tBUG(\"unknown hash algorithm %d\", repo->hash_algo->format_id);\n \t}\n-\trefs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask);\n+\trefs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask);\n \trefs->write_options.disable_auto_compact =\n \t\t!git_env_bool(\"GIT_TEST_REFTABLE_AUTOCOMPACTION\", 1);\n \trefs->write_options.lock_timeout_ms = 100;\n \trefs->write_options.fsync = reftable_be_fsync;\n \n-\trepo_config(the_repository, reftable_be_config, &refs->write_options);\n+\trepo_config(repo, reftable_be_config, &refs->write_options);\n \n \t/*\n \t * It is somewhat unfortunate that we have to mirror the default block\n@@ -492,7 +492,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,\n \tstruct strbuf sb = STRBUF_INIT;\n \n \tstrbuf_addf(&sb, \"%s/reftable\", refs->base.gitdir);\n-\tsafe_create_dir(the_repository, sb.buf, 1);\n+\tsafe_create_dir(ref_store->repo, sb.buf, 1);\n \tstrbuf_reset(&sb);\n \n \tstrbuf_release(&sb);\n-- \n2.53.0\n\n"},{"id":"540276","messageId":"20260328141146.1095115-6-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v2 5/5] refs/packed-backend: use ref_store->repo instead of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-28T14:09:36Z","receivedAt":"2026-03-28T14:12:42Z","isPatch":true,"body":"In refs/packed-backend.c, repo_config_get_int() is called using the global\nthe_repository, even though a repository instance is available via struct\nref_store.\n\nReplace the use of the_repository with ref_store->repo to make the code\nexplicitly repository-aware. With no remaining users of the_repository in\nthis file, drop the USE_THE_REPOSITORY_VARIABLE macro.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/packed-backend.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex 23ed62984b..ebc10dab4d 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"../git-compat-util.h\"\n@@ -1223,7 +1222,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)\n \tstatic int timeout_value = 1000;\n \n \tif (!timeout_configured) {\n-\t\trepo_config_get_int(the_repository, \"core.packedrefstimeout\", &timeout_value);\n+\t\trepo_config_get_int(ref_store->repo, \"core.packedrefstimeout\", &timeout_value);\n \t\ttimeout_configured = 1;\n \t}\n \n-- \n2.53.0\n\n"},{"id":"540279","messageId":"c3f032e4-d50b-4e35-846f-5f5da95f82a6@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-2-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH v2 1/5] refs: make branchname helpers repository aware","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-03-28T16:54:20Z","receivedAt":"2026-03-28T16:54:25Z","isPatch":true,"body":"Hi Shreyansh,\n\nOn 3/28/26 22:09, Shreyansh Paliwal wrote:\n\n\n> @@ -5,6 +5,7 @@\n>   #include \"refs.h\"\n>   #include \"setup.h\"\n>   #include \"strbuf.h\"\n> +#include \"repository.c\"\n\nI'm surprised that it doesn't cause any errors. Or maybe you haven't \nbuild it yet?\n\n\n---\n\n\n> -int check_branch_ref(struct strbuf *sb, const char *name)\n> +int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n>   {\n>   \tif (startup_info->have_repository)\n> -\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n> +\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n>   \telse\n>   \t\tstrbuf_addstr(sb, name);\n>   \n\nstartup_info itself is a global variable, isn't it?\n\nI think a more appropriate approach is something like:\n\n\tif (repo && repo->gitdir)\n\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n\nI dunno, just a thought.\n\n\n---\n\n\nRegards, Yuchen\n\n"},{"id":"540280","messageId":"3ac6eb2a-4bd9-44e2-acef-cc80799925f5@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-4-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH v2 3/5] refs: remove the_hash_algo global state","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-03-28T17:03:50Z","receivedAt":"2026-03-28T17:03:54Z","isPatch":true,"body":"On 3/28/26 22:09, Shreyansh Paliwal wrote:\n\n> @@ -3153,7 +3150,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)\n>   \t\tif (ret < 0)\n>   \t\t\tgoto done;\n>   \n> -\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n> +\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(data->transaction->ref_store->repo->hash_algo),\n>   \t\t\t\t\t     symref_target.buf, NULL,\n>   \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n>   \t\tif (ret < 0)\n\nI have no objection to the logic itself at all, but this line of code \nlooks too long. ;)\n\nIf I were you, I would write:\n\n\tconst struct git_hash_algo *algo = \ndata->transaction->ref_store->repo->hash_algo;\n\nthen:\n\tnull_oid(algo)\n\nJust wanted to remind you to pay attention to readability. There’s no \nneed to reply to this email.\n\n\nThanks, Yuchen\n\n"},{"id":"540281","messageId":"b2c143af-22c0-4266-b641-5ccdeb221251@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-6-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH v2 5/5] refs/packed-backend: use ref_store->repo instead of the_repository","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-03-28T17:08:24Z","receivedAt":"2026-03-28T17:08:29Z","isPatch":true,"body":"On 3/28/26 22:09, Shreyansh Paliwal wrote:\n> In refs/packed-backend.c, repo_config_get_int() is called using the global\n> the_repository, even though a repository instance is available via struct\n> ref_store.\n> \n> Replace the use of the_repository with ref_store->repo to make the code\n> explicitly repository-aware. With no remaining users of the_repository in\n> this file, drop the USE_THE_REPOSITORY_VARIABLE macro.\n> \n> Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n> ---\n>   refs/packed-backend.c | 3 +--\n>   1 file changed, 1 insertion(+), 2 deletions(-)\n> \n> diff --git a/refs/packed-backend.c b/refs/packed-backend.c\n> index 23ed62984b..ebc10dab4d 100644\n> --- a/refs/packed-backend.c\n> +++ b/refs/packed-backend.c\n> @@ -1,4 +1,3 @@\n> -#define USE_THE_REPOSITORY_VARIABLE\n>   #define DISABLE_SIGN_COMPARE_WARNINGS\n>   \n>   #include \"../git-compat-util.h\"\n> @@ -1223,7 +1222,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)\n>   \tstatic int timeout_value = 1000;\n\nBurak already pointed out the issue with the static keyword in patch 3 \nof v1. Notice that it's here as well.\n\n>   \n>   \tif (!timeout_configured) {\n> -\t\trepo_config_get_int(the_repository, \"core.packedrefstimeout\", &timeout_value);\n> +\t\trepo_config_get_int(ref_store->repo, \"core.packedrefstimeout\", &timeout_value);\n>   \t\ttimeout_configured = 1;\n>   \t}\n>   \n\nRegards, Yuchen\n"},{"id":"540317","messageId":"CAPYXD64CoBYAhJwzZxU_i3qL+a-gXKNAg2kBVz_u=mGysOKTcw@mail.gmail.com","threadId":"65352","inReplyTo":"b2c143af-22c0-4266-b641-5ccdeb221251@gmail.com","subject":"Re: [PATCH v2 5/5] refs/packed-backend: use ref_store->repo instead of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T09:54:53Z","receivedAt":"2026-03-29T09:55:05Z","isPatch":true,"body":"On Sat, Mar 28, 2026 at 10:38 PM Tian Yuchen <a3205153416@gmail.com> wrote:\n>\n> On 3/28/26 22:09, Shreyansh Paliwal wrote:\n> > In refs/packed-backend.c, repo_config_get_int() is called using the global\n> > the_repository, even though a repository instance is available via struct\n> > ref_store.\n> >\n> > Replace the use of the_repository with ref_store->repo to make the code\n> > explicitly repository-aware. With no remaining users of the_repository in\n> > this file, drop the USE_THE_REPOSITORY_VARIABLE macro.\n> >\n> > Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n> > ---\n> >   refs/packed-backend.c | 3 +--\n> >   1 file changed, 1 insertion(+), 2 deletions(-)\n> >\n> > diff --git a/refs/packed-backend.c b/refs/packed-backend.c\n> > index 23ed62984b..ebc10dab4d 100644\n> > --- a/refs/packed-backend.c\n> > +++ b/refs/packed-backend.c\n> > @@ -1,4 +1,3 @@\n> > -#define USE_THE_REPOSITORY_VARIABLE\n> >   #define DISABLE_SIGN_COMPARE_WARNINGS\n> >\n> >   #include \"../git-compat-util.h\"\n> > @@ -1223,7 +1222,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)\n> >       static int timeout_value = 1000;\n>\n> Burak already pointed out the issue with the static keyword in patch 3\n> of v1. Notice that it's here as well.\n\nHi Yuchen,\n\nI have acknowledged this in a previous reply to Burak. As stated there,\nthis is a valid issue and would require moving the config into\nrepo-settings struct.\nIn this patch, I focused on removing the dependency on\n'the_repository' while preserving existing behavior. Global state\nremoval and multi-repo correctness is an incremental process,\nso I would prefer to handle this in a follow-up change.\nI'll also update the patch title in the next version to better reflect\nthe scope of the change.\nBtw, I forgot to cc the other recipients previously, so it might have ended\nin your inbox twice :)\n\nThanks,\nShreyansh\n"},{"id":"540318","messageId":"CAPYXD64H654k0RoKDiU91dsj0Fr9mf+f46Vfe54K+zueMzh+0A@mail.gmail.com","threadId":"65352","inReplyTo":"c3f032e4-d50b-4e35-846f-5f5da95f82a6@gmail.com","subject":"Re: [PATCH v2 1/5] refs: make branchname helpers repository aware","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T09:55:34Z","receivedAt":"2026-03-29T09:55:46Z","isPatch":true,"body":"On Sat, Mar 28, 2026 at 10:24 PM Tian Yuchen <a3205153416@gmail.com> wrote:\n>\n> Hi Shreyansh,\n>\n> On 3/28/26 22:09, Shreyansh Paliwal wrote:\n>\n>\n> > @@ -5,6 +5,7 @@\n> >   #include \"refs.h\"\n> >   #include \"setup.h\"\n> >   #include \"strbuf.h\"\n> > +#include \"repository.c\"\n>\n> I'm surprised that it doesn't cause any errors. Or maybe you haven't\n> build it yet?\n>\n\nThanks for pointing this out. Apparently it didn't raise any errors in the\nbuild or test suite. Will send a reroll.\n\n>\n> ---\n>\n>\n> > -int check_branch_ref(struct strbuf *sb, const char *name)\n> > +int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n> >   {\n> >       if (startup_info->have_repository)\n> > -             copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n> > +             copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n> >       else\n> >               strbuf_addstr(sb, name);\n> >\n>\n> startup_info itself is a global variable, isn't it?\n>\n> I think a more appropriate approach is something like:\n>\n>         if (repo && repo->gitdir)\n>                 copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n>\n> I dunno, just a thought.\n\nI hadn’t considered this as it is outside my scope of this patch series.\nWhile the change makes sense, I am not very sure whether it could cause\nany behavioral change or not.\nThanks.\n"},{"id":"540319","messageId":"20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260328141146.1095115-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v3 0/5] replace the_repository with local repository instances","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T10:16:38Z","receivedAt":"2026-03-29T10:18:08Z","isPatch":true,"body":"This series continues the effort to reduce reliance on the_repository\nglobal state by making repository context explicit across the refs\nsubsystem. The patches focus on passing struct repository through various\nref helpers and backends, and replacing uses of global state such as\nthe_repository and the_hash_algo with the appropriate repository instance.\n\nPatch 1/5: Making branch name helper functions (copy_branchname(),\ncheck_branch_ref(), validate_branchname(), and validate_new_branchname())\nrepository-aware. (built on top of jw/object-name-bitset-to-enum)\n\nPatch 2/5: Updating get_files_ref_lock_timeout_ms() to take a repository\nand propagating it through files-backend, including callback paths.\n\nPatch 3/5: Replacing uses of the_hash_algo in refs.c with the hash\nalgorithm from the appropriate repository.\n\nPatch 4/5: Removing remaining uses of the_repository in reftable-backend.c\nwhere a repository instance is already available.\n\nPatch 5/5: Replacing the single instance of the_repository in\npacked-backend.c, thus dropping the USE_THE_REPOSITORY_VARIABLE macro.\n\nShreyansh Paliwal (5):\n  refs: add struct repository parameter to branchname helpers\n  refs: add struct repository parameter in\n    get_files_ref_lock_timeout_ms()\n  refs: remove the_hash_algo global state\n  refs/reftable-backend: drop uses of the_repository\n  refs/packed-backend: use ref_store->repo instead of the_repository\n\n branch.c                   | 15 ++++++++-------\n branch.h                   |  5 +++--\n builtin/branch.c           | 14 +++++++-------\n builtin/check-ref-format.c |  3 ++-\n builtin/checkout.c         |  6 +++---\n builtin/merge.c            |  2 +-\n builtin/worktree.c         | 10 +++++-----\n refs.c                     | 28 +++++++++++++---------------\n refs.h                     |  4 ++--\n refs/files-backend.c       | 19 +++++++++++++------\n refs/packed-backend.c      |  3 +--\n refs/refs-internal.h       |  2 +-\n refs/reftable-backend.c    |  6 +++---\n 13 files changed, 62 insertions(+), 55 deletions(-)\n\n---\nChanges in v3:\n - Fixed an import\n - better readability in patch 3/5\n\nChanges in v2:\n - Made struct repository the first argument in function parameters.\n\nRange-diff against v2:\n1:  c0182252c4 ! 1:  5844440b73 refs: make branchname helpers repository aware\n    @@ Metadata\n     Author: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n\n      ## Commit message ##\n    -    refs: make branchname helpers repository aware\n    +    refs: add struct repository parameter to branchname helpers\n\n         copy_branchname() in refs.c relies on the_repository when calling\n         repo_interpret_branch_name(), introducing an implicit dependency on global\n    @@ builtin/branch.c: int cmd_branch(int argc,\n\n      ## builtin/check-ref-format.c ##\n     @@\n    + /*\n    +  * GIT - The information manager from hell\n    +  */\n    ++#define USE_THE_REPOSITORY_VARIABLE\n    + #include \"builtin.h\"\n      #include \"refs.h\"\n      #include \"setup.h\"\n    - #include \"strbuf.h\"\n    -+#include \"repository.c\"\n    -\n    - static const char builtin_check_ref_format_usage[] =\n    - \"git check-ref-format [--normalize] [<options>] <refname>\\n\"\n     @@ builtin/check-ref-format.c: static int check_ref_format_branch(const char *arg)\n      \tint nongit;\n\n2:  857a8c40fe ! 2:  f7a9ea4204 refs: make get_files_ref_lock_timeout_ms() repostory aware\n    @@ Metadata\n     Author: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n\n      ## Commit message ##\n    -    refs: make get_files_ref_lock_timeout_ms() repostory aware\n    +    refs: add struct repository parameter in get_files_ref_lock_timeout_ms()\n\n         get_files_ref_lock_timeout_ms() calls repo_config_get_int() using\n         the_repository, as no repository instance is available in its scope. Add a\n    @@ Commit message\n         is used as a callback, introduce a small wrapper struct to pass both struct\n         lock_file and struct repository through the callback data.\n\n    -    This removes reliance on the_repository global and makes the timeout lookup\n    -    operate on the correct repository context.\n    +    This reduces reliance on the_repository global.\n\n         Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n\n3:  46d5272aec ! 3:  00dba1a96a refs: remove the_hash_algo global state\n    @@ refs.c: static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, v\n      \telse if (update->new_target)\n      \t\tstrbuf_addf(buf, \"ref:%s \", update->new_target);\n      \telse\n    +@@ refs.c: struct migration_data {\n    + static int migrate_one_ref(const struct reference *ref, void *cb_data)\n    + {\n    + \tstruct migration_data *data = cb_data;\n    ++\tconst struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;\n    + \tstruct strbuf symref_target = STRBUF_INIT;\n    + \tint ret;\n    +\n     @@ refs.c: static int migrate_one_ref(const struct reference *ref, void *cb_data)\n      \t\tif (ret < 0)\n      \t\t\tgoto done;\n\n     -\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n    -+\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(data->transaction->ref_store->repo->hash_algo),\n    ++\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),\n      \t\t\t\t\t     symref_target.buf, NULL,\n      \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n      \t\tif (ret < 0)\n4:  11aa886259 = 4:  5653c418e1 refs/reftable-backend: drop uses of the_repository\n5:  c763732964 = 5:  18c1c67083 refs/packed-backend: use ref_store->repo instead of the_repository\n--\n2.53.0\n"},{"id":"540320","messageId":"20260329101725.1092900-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v3 1/5] refs: add struct repository parameter to branchname helpers","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T10:16:39Z","receivedAt":"2026-03-29T10:18:11Z","isPatch":true,"body":"copy_branchname() in refs.c relies on the_repository when calling\nrepo_interpret_branch_name(), introducing an implicit dependency on global\nstate. Add a struct repository parameter and use it instead.\n\nUpdate check_branch_ref() to take a repository parameter as well, since it\ncalls copy_branchname(). Propagate this change to higher-level helpers\nvalidate_branchname() and validate_new_branchname(), which also lack access\nto a repository instance. Most callers of these helpers reside in builtin\ncode and already operate on the_repository, so pass it explicitly at those\ncall sites (builtin/checkout and builtin/worktree) otherwise pass struct\nrepository where available.\n\nThis makes branch name handling explicitly repository-aware and aligns with\nongoing efforts to remove reliance on global state. This change builds on\ntop of jw/object-name-bitset-to-enum (2026-03-18), which introduced the\nenum interpret_branch_kind parameter to copy_branchname().\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n branch.c                   | 15 ++++++++-------\n branch.h                   |  5 +++--\n builtin/branch.c           | 14 +++++++-------\n builtin/check-ref-format.c |  3 ++-\n builtin/checkout.c         |  6 +++---\n builtin/merge.c            |  2 +-\n builtin/worktree.c         | 10 +++++-----\n refs.c                     |  8 ++++----\n refs.h                     |  4 ++--\n 9 files changed, 35 insertions(+), 32 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 243db7d0fc..63a9c0c238 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -370,16 +370,16 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_branchname(const char *name, struct strbuf *ref)\n+int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref)\n {\n-\tif (check_branch_ref(ref, name)) {\n+\tif (check_branch_ref(repo, ref, name)) {\n \t\tint code = die_message(_(\"'%s' is not a valid branch name\"), name);\n \t\tadvise_if_enabled(ADVICE_REF_SYNTAX,\n \t\t\t\t  _(\"See 'git help check-ref-format'\"));\n \t\texit(code);\n \t}\n \n-\treturn refs_ref_exists(get_main_ref_store(the_repository), ref->buf);\n+\treturn refs_ref_exists(get_main_ref_store(repo), ref->buf);\n }\n \n static int initialized_checked_out_branches;\n@@ -468,10 +468,11 @@ const char *branch_checked_out(const char *refname)\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_new_branchname(const char *name, struct strbuf *ref, int force)\n+int validate_new_branchname(struct repository *repo, const char *name,\n+\t\t\t    struct strbuf *ref, int force)\n {\n \tconst char *path;\n-\tif (!validate_branchname(name, ref))\n+\tif (!validate_branchname(repo, name, ref))\n \t\treturn 0;\n \n \tif (!force)\n@@ -613,8 +614,8 @@ void create_branch(struct repository *r,\n \t\tBUG(\"'clobber_head_ok' can only be used with 'force'\");\n \n \tif (clobber_head_ok ?\n-\t\t\t  validate_branchname(name, &ref) :\n-\t\t\t  validate_new_branchname(name, &ref, force)) {\n+\t\t\t  validate_branchname(r, name, &ref) :\n+\t\t\t  validate_new_branchname(r, name, &ref, force)) {\n \t\tforcing = 1;\n \t}\n \ndiff --git a/branch.h b/branch.h\nindex 3dc6e2a0ff..b41176ee7f 100644\n--- a/branch.h\n+++ b/branch.h\n@@ -111,7 +111,7 @@ const char *branch_checked_out(const char *refname);\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_branchname(const char *name, struct strbuf *ref);\n+int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref);\n \n /*\n  * Check if a branch 'name' can be created as a new branch; die otherwise.\n@@ -119,7 +119,8 @@ int validate_branchname(const char *name, struct strbuf *ref);\n  * Return 1 if the named branch already exists; return 0 otherwise.\n  * Fill ref with the full refname for the branch.\n  */\n-int validate_new_branchname(const char *name, struct strbuf *ref, int force);\n+int validate_new_branchname(struct repository *repo, const char *name,\n+\t\t\t    struct strbuf *ref, int force);\n \n /*\n  * Remove information about the merge state on the current\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 1572a4f9ef..ea4109f893 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -259,7 +259,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\tchar *target = NULL;\n \t\tint flags = 0;\n \n-\t\tcopy_branchname(&bname, argv[i], allowed_interpret);\n+\t\tcopy_branchname(the_repository, &bname, argv[i], allowed_interpret);\n \t\tfree(name);\n \t\tname = mkpathdup(fmt, bname.buf);\n \n@@ -581,7 +581,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \tint recovery = 0, oldref_usage = 0;\n \tstruct worktree **worktrees = get_worktrees();\n \n-\tif (check_branch_ref(&oldref, oldname)) {\n+\tif (check_branch_ref(the_repository, &oldref, oldname)) {\n \t\t/*\n \t\t * Bad name --- this could be an attempt to rename a\n \t\t * ref that we used to allow to be created by accident.\n@@ -619,9 +619,9 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int\n \t * cause the worktree to become inconsistent with HEAD, so allow it.\n \t */\n \tif (!strcmp(oldname, newname))\n-\t\tvalidate_branchname(newname, &newref);\n+\t\tvalidate_branchname(the_repository, newname, &newref);\n \telse\n-\t\tvalidate_new_branchname(newname, &newref, force);\n+\t\tvalidate_new_branchname(the_repository, newname, &newref, force);\n \n \treject_rebase_or_bisect_branch(worktrees, oldref.buf);\n \n@@ -898,7 +898,7 @@ int cmd_branch(int argc,\n \t\t\t\tdie(_(\"cannot give description to detached HEAD\"));\n \t\t\tbranch_name = head;\n \t\t} else if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n \t\t\tbranch_name = buf.buf;\n \t\t} else {\n \t\t\tdie(_(\"cannot edit description of more than one branch\"));\n@@ -941,7 +941,7 @@ int cmd_branch(int argc,\n \t\tif (!argc)\n \t\t\tbranch = branch_get(NULL);\n \t\telse if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n \t\t\tbranch = branch_get(buf.buf);\n \t\t} else\n \t\t\tdie(_(\"too many arguments to set new upstream\"));\n@@ -971,7 +971,7 @@ int cmd_branch(int argc,\n \t\tif (!argc)\n \t\t\tbranch = branch_get(NULL);\n \t\telse if (argc == 1) {\n-\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n \t\t\tbranch = branch_get(buf.buf);\n \t\t} else\n \t\t\tdie(_(\"too many arguments to unset upstream\"));\ndiff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c\nindex 5d80afeec0..b7ba098363 100644\n--- a/builtin/check-ref-format.c\n+++ b/builtin/check-ref-format.c\n@@ -1,6 +1,7 @@\n /*\n  * GIT - The information manager from hell\n  */\n+#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"refs.h\"\n #include \"setup.h\"\n@@ -42,7 +43,7 @@ static int check_ref_format_branch(const char *arg)\n \tint nongit;\n \n \tsetup_git_directory_gently(&nongit);\n-\tif (check_branch_ref(&sb, arg) ||\n+\tif (check_branch_ref(the_repository, &sb, arg) ||\n \t    !skip_prefix(sb.buf, \"refs/heads/\", &name))\n \t\tdie(\"'%s' is not a valid branch name\", arg);\n \tprintf(\"%s\\n\", name);\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex e031e61886..93ad894dc2 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -743,7 +743,7 @@ static void setup_branch_path(struct branch_info *branch)\n \t\t\t   &branch->oid, &branch->refname, 0))\n \t\trepo_get_oid_committish(the_repository, branch->name, &branch->oid);\n \n-\tcopy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);\n+\tcopy_branchname(the_repository, &buf, branch->name, INTERPRET_BRANCH_LOCAL);\n \tif (strcmp(buf.buf, branch->name)) {\n \t\tfree(branch->name);\n \t\tbranch->name = xstrdup(buf.buf);\n@@ -2014,10 +2014,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,\n \t\tstruct strbuf buf = STRBUF_INIT;\n \n \t\tif (opts->new_branch_force)\n-\t\t\topts->branch_exists = validate_branchname(opts->new_branch, &buf);\n+\t\t\topts->branch_exists = validate_branchname(the_repository, opts->new_branch, &buf);\n \t\telse\n \t\t\topts->branch_exists =\n-\t\t\t\tvalidate_new_branchname(opts->new_branch, &buf, 0);\n+\t\t\t\tvalidate_new_branchname(the_repository, opts->new_branch, &buf, 0);\n \t\tstrbuf_release(&buf);\n \t}\n \ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 2cbce56f8d..3f4b9dc47a 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -552,7 +552,7 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \tchar *found_ref = NULL;\n \tint len, early;\n \n-\tcopy_branchname(&bname, remote, 0);\n+\tcopy_branchname(the_repository, &bname, remote, 0);\n \tremote = bname.buf;\n \n \toidclr(&branch_head, the_repository->hash_algo);\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 4035b1cb06..a5e116d8f9 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -415,7 +415,7 @@ static int make_worktree_orphan(const char * ref, const struct add_opts *opts,\n \tstruct strbuf symref = STRBUF_INIT;\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n \n-\tvalidate_new_branchname(ref, &symref, 0);\n+\tvalidate_new_branchname(the_repository, ref, &symref, 0);\n \tstrvec_pushl(&cp.args, \"symbolic-ref\", \"HEAD\", symref.buf, NULL);\n \tif (opts->quiet)\n \t\tstrvec_push(&cp.args, \"--quiet\");\n@@ -481,7 +481,7 @@ static int add_worktree(const char *path, const char *refname,\n \tworktrees = NULL;\n \n \t/* is 'refname' a branch or commit? */\n-\tif (!opts->detach && !check_branch_ref(&symref, refname) &&\n+\tif (!opts->detach && !check_branch_ref(the_repository, &symref, refname) &&\n \t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {\n \t\tis_branch = 1;\n \t\tif (!opts->force)\n@@ -649,7 +649,7 @@ static void print_preparing_worktree_line(int detach,\n \t\tfprintf_ln(stderr, _(\"Preparing worktree (new branch '%s')\"), new_branch);\n \t} else {\n \t\tstruct strbuf s = STRBUF_INIT;\n-\t\tif (!detach && !check_branch_ref(&s, branch) &&\n+\t\tif (!detach && !check_branch_ref(the_repository, &s, branch) &&\n \t\t    refs_ref_exists(get_main_ref_store(the_repository), s.buf))\n \t\t\tfprintf_ln(stderr, _(\"Preparing worktree (checking out '%s')\"),\n \t\t\t\t  branch);\n@@ -788,7 +788,7 @@ static char *dwim_branch(const char *path, char **new_branch)\n \tchar *branchname = xstrndup(s, n);\n \tstruct strbuf ref = STRBUF_INIT;\n \n-\tbranch_exists = !check_branch_ref(&ref, branchname) &&\n+\tbranch_exists = !check_branch_ref(the_repository, &ref, branchname) &&\n \t\t\trefs_ref_exists(get_main_ref_store(the_repository),\n \t\t\t\t\tref.buf);\n \tstrbuf_release(&ref);\n@@ -885,7 +885,7 @@ static int add(int ac, const char **av, const char *prefix,\n \t\tnew_branch = new_branch_force;\n \n \t\tif (!opts.force &&\n-\t\t    !check_branch_ref(&symref, new_branch) &&\n+\t\t    !check_branch_ref(the_repository, &symref, new_branch) &&\n \t\t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf))\n \t\t\tdie_if_checked_out(symref.buf, 0);\n \t\tstrbuf_release(&symref);\ndiff --git a/refs.c b/refs.c\nindex 685a0c247b..5cdc8858c5 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -743,14 +743,14 @@ static char *substitute_branch_name(struct repository *r,\n \treturn NULL;\n }\n \n-void copy_branchname(struct strbuf *sb, const char *name,\n+void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n \t\t     enum interpret_branch_kind allowed)\n {\n \tint len = strlen(name);\n \tstruct interpret_branch_name_options options = {\n \t\t.allowed = allowed\n \t};\n-\tint used = repo_interpret_branch_name(the_repository, name, len, sb,\n+\tint used = repo_interpret_branch_name(repo, name, len, sb,\n \t\t\t\t\t      &options);\n \n \tif (used < 0)\n@@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,\n \tstrbuf_add(sb, name + used, len - used);\n }\n \n-int check_branch_ref(struct strbuf *sb, const char *name)\n+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n {\n \tif (startup_info->have_repository)\n-\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n+\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n \telse\n \t\tstrbuf_addstr(sb, name);\n \ndiff --git a/refs.h b/refs.h\nindex d65de6ab5f..5407a4c4d6 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -225,7 +225,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);\n  * If \"allowed\" is non-zero, restrict the set of allowed expansions. See\n  * repo_interpret_branch_name() for details.\n  */\n-void copy_branchname(struct strbuf *sb, const char *name,\n+void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n \t\t     enum interpret_branch_kind allowed);\n \n /*\n@@ -234,7 +234,7 @@ void copy_branchname(struct strbuf *sb, const char *name,\n  *\n  * The return value is \"0\" if the result is valid, and \"-1\" otherwise.\n  */\n-int check_branch_ref(struct strbuf *sb, const char *name);\n+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name);\n \n /*\n  * Similar for a tag name in refs/tags/.\n-- \n2.53.0\n\n"},{"id":"540321","messageId":"20260329101725.1092900-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v3 2/5] refs: add struct repository parameter in get_files_ref_lock_timeout_ms()","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T10:16:40Z","receivedAt":"2026-03-29T10:18:14Z","isPatch":true,"body":"get_files_ref_lock_timeout_ms() calls repo_config_get_int() using\nthe_repository, as no repository instance is available in its scope. Add a\nstruct repository parameter and use it instead of the_repository.\n\nUpdate all callers accordingly. In files-backend.c, lock_raw_ref() can\nobtain repository instance from the struct ref_transaction via\ntransaction->ref_store->repo and pass it down. For create_reflock(), which\nis used as a callback, introduce a small wrapper struct to pass both struct\nlock_file and struct repository through the callback data.\n\nThis reduces reliance on the_repository global.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c               |  4 ++--\n refs/files-backend.c | 19 +++++++++++++------\n refs/refs-internal.h |  2 +-\n 3 files changed, 16 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 5cdc8858c5..2f8c8427cd 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,\n \treturn REF_WORKTREE_SHARED;\n }\n \n-long get_files_ref_lock_timeout_ms(void)\n+long get_files_ref_lock_timeout_ms(struct repository *repo)\n {\n \tstatic int configured = 0;\n \n@@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)\n \tstatic int timeout_ms = 100;\n \n \tif (!configured) {\n-\t\trepo_config_get_int(the_repository, \"core.filesreflocktimeout\", &timeout_ms);\n+\t\trepo_config_get_int(repo, \"core.filesreflocktimeout\", &timeout_ms);\n \t\tconfigured = 1;\n \t}\n \ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 7ce0d57478..ee8dd771a4 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -792,7 +792,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,\n \n \tif (hold_lock_file_for_update_timeout(\n \t\t\t    &lock->lk, ref_file.buf, LOCK_NO_DEREF,\n-\t\t\t    get_files_ref_lock_timeout_ms()) < 0) {\n+\t\t\t    get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {\n \t\tint myerr = errno;\n \t\terrno = 0;\n \t\tif (myerr == ENOENT && --attempts_remaining > 0) {\n@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)\n \treturn remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);\n }\n \n+struct create_reflock_cb {\n+    struct lock_file *lk;\n+    struct repository *repo;\n+};\n+\n static int create_reflock(const char *path, void *cb)\n {\n-\tstruct lock_file *lk = cb;\n-\n+\tstruct create_reflock_cb *data = cb;\n \treturn hold_lock_file_for_update_timeout(\n-\t\t\tlk, path, LOCK_NO_DEREF,\n-\t\t\tget_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;\n+\t\t\tdata->lk, path, LOCK_NO_DEREF,\n+\t\t\tget_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;\n }\n \n /*\n@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n {\n \tstruct strbuf ref_file = STRBUF_INIT;\n \tstruct ref_lock *lock;\n+\tstruct create_reflock_cb cb_data;\n \n \tfiles_assert_main_repository(refs, \"lock_ref_oid_basic\");\n \tassert(err);\n@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n \n \tlock->ref_name = xstrdup(refname);\n \tlock->count = 1;\n+\tcb_data.lk   = &lock->lk;\n+\tcb_data.repo = refs->base.repo;\n \n-\tif (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {\n+\tif (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {\n \t\tunable_to_lock_message(ref_file.buf, errno, err);\n \t\tgoto error_return;\n \t}\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex d79e35fd26..e4cfd9e19e 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -43,7 +43,7 @@ struct ref_transaction;\n  * Return the length of time to retry acquiring a loose reference lock\n  * before giving up, in milliseconds:\n  */\n-long get_files_ref_lock_timeout_ms(void);\n+long get_files_ref_lock_timeout_ms(struct repository *repo);\n \n /*\n  * Return true iff refname is minimally safe. \"Safe\" here means that\n-- \n2.53.0\n\n"},{"id":"540322","messageId":"20260329101725.1092900-4-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v3 3/5] refs: remove the_hash_algo global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T10:16:41Z","receivedAt":"2026-03-29T10:18:16Z","isPatch":true,"body":"refs.c uses the_hash_algo in multiple places, relying on global state for\nthe object hash algorithm. Replace these uses with the appropriate\nrepository-specific hash_algo. In transaction-related functions\n(ref_transaction_create, ref_transaction_delete, migrate_one_ref, and\ntransaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo.\nIn other cases, such as repo_get_submodule_ref_store(), use\nrepo->hash_algo.\n\nThis removes implicit reliance on global state. With no remaining uses of\nthe_repository in this file, drop USE_THE_REPOSITORY_VARIABLE and the\ndependency on environment.h.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c | 16 +++++++---------\n 1 file changed, 7 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 2f8c8427cd..d3abce0318 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2,13 +2,10 @@\n  * The backend-independent part of the reference module.\n  */\n \n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n #include \"config.h\"\n-#include \"environment.h\"\n #include \"strmap.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n@@ -1472,7 +1469,7 @@ int ref_transaction_create(struct ref_transaction *transaction,\n \t\treturn 1;\n \t}\n \treturn ref_transaction_update(transaction, refname, new_oid,\n-\t\t\t\t      null_oid(the_hash_algo), new_target, NULL, flags,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,\n \t\t\t\t      msg, err);\n }\n \n@@ -1491,7 +1488,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,\n \tif (old_target && !(flags & REF_NO_DEREF))\n \t\tBUG(\"delete cannot operate on symrefs with deref mode\");\n \treturn ref_transaction_update(transaction, refname,\n-\t\t\t\t      null_oid(the_hash_algo), old_oid,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), old_oid,\n \t\t\t\t      NULL, old_target, flags,\n \t\t\t\t      msg, err);\n }\n@@ -2379,7 +2376,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,\n \tsubrepo = xmalloc(sizeof(*subrepo));\n \n \tif (repo_submodule_init(subrepo, repo, submodule,\n-\t\t\t\tnull_oid(the_hash_algo))) {\n+\t\t\t\tnull_oid(repo->hash_algo))) {\n \t\tfree(subrepo);\n \t\tgoto done;\n \t}\n@@ -2571,14 +2568,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_\n \tstrbuf_reset(buf);\n \n \tif (!(update->flags & REF_HAVE_OLD))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->old_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->old_target);\n \telse\n \t\tstrbuf_addf(buf, \"%s \", oid_to_hex(&update->old_oid));\n \n \tif (!(update->flags & REF_HAVE_NEW))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->new_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->new_target);\n \telse\n@@ -3145,6 +3142,7 @@ struct migration_data {\n static int migrate_one_ref(const struct reference *ref, void *cb_data)\n {\n \tstruct migration_data *data = cb_data;\n+\tconst struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;\n \tstruct strbuf symref_target = STRBUF_INIT;\n \tint ret;\n \n@@ -3153,7 +3151,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)\n \t\tif (ret < 0)\n \t\t\tgoto done;\n \n-\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n+\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),\n \t\t\t\t\t     symref_target.buf, NULL,\n \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n \t\tif (ret < 0)\n-- \n2.53.0\n\n"},{"id":"540323","messageId":"20260329101725.1092900-5-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v3 4/5] refs/reftable-backend: drop uses of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T10:16:42Z","receivedAt":"2026-03-29T10:18:19Z","isPatch":true,"body":"reftable_be_init() and reftable_be_create_on_disk() use the_repository even\nthough a repository instance is already available, either directly or via\nstruct ref_store.\n\nReplace these uses with the appropriate local repository instance (repo or\nref_store->repo) to avoid relying on global state.\n\nNote that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\nis_bare_repository() is still there in the file.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/reftable-backend.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex b124404663..7c8a992fcb 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -404,13 +404,13 @@ static struct ref_store *reftable_be_init(struct repository *repo,\n \tdefault:\n \t\tBUG(\"unknown hash algorithm %d\", repo->hash_algo->format_id);\n \t}\n-\trefs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask);\n+\trefs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask);\n \trefs->write_options.disable_auto_compact =\n \t\t!git_env_bool(\"GIT_TEST_REFTABLE_AUTOCOMPACTION\", 1);\n \trefs->write_options.lock_timeout_ms = 100;\n \trefs->write_options.fsync = reftable_be_fsync;\n \n-\trepo_config(the_repository, reftable_be_config, &refs->write_options);\n+\trepo_config(repo, reftable_be_config, &refs->write_options);\n \n \t/*\n \t * It is somewhat unfortunate that we have to mirror the default block\n@@ -492,7 +492,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,\n \tstruct strbuf sb = STRBUF_INIT;\n \n \tstrbuf_addf(&sb, \"%s/reftable\", refs->base.gitdir);\n-\tsafe_create_dir(the_repository, sb.buf, 1);\n+\tsafe_create_dir(ref_store->repo, sb.buf, 1);\n \tstrbuf_reset(&sb);\n \n \tstrbuf_release(&sb);\n-- \n2.53.0\n\n"},{"id":"540324","messageId":"20260329101725.1092900-6-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v3 5/5] refs/packed-backend: use ref_store->repo instead of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-29T10:16:43Z","receivedAt":"2026-03-29T10:18:22Z","isPatch":true,"body":"In refs/packed-backend.c, repo_config_get_int() is called using the global\nthe_repository, even though a repository instance is available via struct\nref_store.\n\nReplace the use of the_repository with ref_store->repo to make the code\nexplicitly repository-aware. With no remaining users of the_repository in\nthis file, drop the USE_THE_REPOSITORY_VARIABLE macro.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/packed-backend.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex 23ed62984b..ebc10dab4d 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #define DISABLE_SIGN_COMPARE_WARNINGS\n \n #include \"../git-compat-util.h\"\n@@ -1223,7 +1222,7 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)\n \tstatic int timeout_value = 1000;\n \n \tif (!timeout_configured) {\n-\t\trepo_config_get_int(the_repository, \"core.packedrefstimeout\", &timeout_value);\n+\t\trepo_config_get_int(ref_store->repo, \"core.packedrefstimeout\", &timeout_value);\n \t\ttimeout_configured = 1;\n \t}\n \n-- \n2.53.0\n\n"},{"id":"540330","messageId":"8dc0961c-cdc9-4ffa-997c-1120dc26e0e2@gmail.com","threadId":"65352","inReplyTo":"CAPYXD64H654k0RoKDiU91dsj0Fr9mf+f46Vfe54K+zueMzh+0A@mail.gmail.com","subject":"Re: [PATCH v2 1/5] refs: make branchname helpers repository aware","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-03-29T15:37:25Z","receivedAt":"2026-03-29T15:37:30Z","isPatch":true,"body":"Hi,\n\nOn 3/29/26 17:55, Shreyansh Paliwal wrote:\n\n> \n> Thanks for pointing this out. Apparently it didn't raise any errors in the\n> build or test suite. Will send a reroll.\n\nOh, then that’s likely because the static libraries have some kind of \non-demand\nlinking mechanism or something. Interesting.\n  > I hadn’t considered this as it is outside my scope of this patch series.\n> While the change makes sense, I am not very sure whether it could cause\n> any behavioral change or not.\n> Thanks.\n\nThat's certainly true, I also think it’s better not to make drastic \nchanges. ;)\n\nRegards, Yuchen\n\n"},{"id":"540729","messageId":"ac4aZRveWXjOtxgB@pks.im","threadId":"65352","inReplyTo":"20260329101725.1092900-2-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-04-02T07:27:33Z","receivedAt":"2026-04-02T07:27:39Z","isPatch":true,"body":"On Sun, Mar 29, 2026 at 03:46:39PM +0530, Shreyansh Paliwal wrote:\n> diff --git a/refs.c b/refs.c\n> index 685a0c247b..5cdc8858c5 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,\n>  \tstrbuf_add(sb, name + used, len - used);\n>  }\n>  \n> -int check_branch_ref(struct strbuf *sb, const char *name)\n> +int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n>  {\n>  \tif (startup_info->have_repository)\n> -\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n> +\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n>  \telse\n>  \t\tstrbuf_addstr(sb, name);\n>  \n\nI have to agree with Tian's comment on v2, this part here looks wrong. I\ndon't think we should depend on `startup_info` here, but we should\nexclusively rely on whether or not the caller has passed in a\nrepository. And that will likely require a bit more scrutiny to figure\nout whether there are any callers that shouldn't pass in a repository\nbecause it's not initialized.\n\nAlternatively, we could go with Tian's suggestion of checking for `repo\n&& repo->gitdir`.\n\nPatrick\n"},{"id":"540730","messageId":"ac4aa-qLWwoZ9uPZ@pks.im","threadId":"65352","inReplyTo":"20260329101725.1092900-5-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH v3 4/5] refs/reftable-backend: drop uses of the_repository","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-04-02T07:27:39Z","receivedAt":"2026-04-02T07:27:43Z","isPatch":true,"body":"On Sun, Mar 29, 2026 at 03:46:42PM +0530, Shreyansh Paliwal wrote:\n> reftable_be_init() and reftable_be_create_on_disk() use the_repository even\n> though a repository instance is already available, either directly or via\n> struct ref_store.\n> \n> Replace these uses with the appropriate local repository instance (repo or\n> ref_store->repo) to avoid relying on global state.\n> \n> Note that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\n> is_bare_repository() is still there in the file.\n\nI've got a patch series cooking now that'll eventually de-globalize\n`is_bare_repository()`. So there's light at the end of the tunnel here :)\n\nPatrick\n"},{"id":"540777","messageId":"ac6K5UnVdw67Rfpy@gmail.com","threadId":"65352","inReplyTo":"ac4aZRveWXjOtxgB@pks.im","subject":"Re: [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers","fromName":"Burak Kaan Karaçay","fromEmail":"bkkaracay@gmail.com","sentAt":"2026-04-02T17:03:45Z","receivedAt":"2026-04-02T17:03:59Z","isPatch":true,"body":"Hi,\n\nOn Thu, Apr 02, 2026 at 09:27:33AM +0200, Patrick Steinhardt wrote:\n>On Sun, Mar 29, 2026 at 03:46:39PM +0530, Shreyansh Paliwal wrote:\n>> diff --git a/refs.c b/refs.c\n>> index 685a0c247b..5cdc8858c5 100644\n>> --- a/refs.c\n>> +++ b/refs.c\n>> @@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,\n>>  \tstrbuf_add(sb, name + used, len - used);\n>>  }\n>>\n>> -int check_branch_ref(struct strbuf *sb, const char *name)\n>> +int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n>>  {\n>>  \tif (startup_info->have_repository)\n>> -\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n>> +\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n>>  \telse\n>>  \t\tstrbuf_addstr(sb, name);\n>>\n>\n>I have to agree with Tian's comment on v2, this part here looks wrong. I\n>don't think we should depend on `startup_info` here, but we should\n>exclusively rely on whether or not the caller has passed in a\n>repository. And that will likely require a bit more scrutiny to figure\n>out whether there are any callers that shouldn't pass in a repository\n>because it's not initialized.\n>\n>Alternatively, we could go with Tian's suggestion of checking for `repo\n>&& repo->gitdir`.\n>\n>Patrick\n\nThis approach actually leads to a bug and segfault in a specific edge\ncase when running 'git check-ref-format'. The current tests don't cover\nthis scenario, but they can be extended to catch it.\n\nIf GIT_DIR is set to a non-existent path,\n'startup_info->have_repository' becomes '0' but 'repo->gitdir' still\nholds the invalid path. As a result, the code enters the first condition\nand crashes. The case can be tested with this command:\n\n$ git --git-dir='non-existing' check-ref-format --branch @{-1}\n\nModifying the behavior of 'repo->gitdir' might solve the issue, but I\nbelive that falls outside the scope of this patch. After a quick search,\nI found a prophecy from Peff about the 'startup_info->have_repository':\n\n[1] https://lore.kernel.org/git/20190806124954.GA13649@sigill.intra.peff.net/\n\nThanks,\nBurak Kaan Karaçay\n"},{"id":"540780","messageId":"7d8ec377-0555-48d8-b016-6794329932a1@gmail.com","threadId":"65352","inReplyTo":"ac6K5UnVdw67Rfpy@gmail.com","subject":"Re: [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-04-02T17:48:56Z","receivedAt":"2026-04-02T17:49:01Z","isPatch":true,"body":"On 4/3/26 01:03, Burak Kaan Karaçay wrote:\n> Hi,\n> \n> On Thu, Apr 02, 2026 at 09:27:33AM +0200, Patrick Steinhardt wrote:\n>> On Sun, Mar 29, 2026 at 03:46:39PM +0530, Shreyansh Paliwal wrote:\n>>> diff --git a/refs.c b/refs.c\n>>> index 685a0c247b..5cdc8858c5 100644\n>>> --- a/refs.c\n>>> +++ b/refs.c\n>>> @@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const \n>>> char *name,\n>>>      strbuf_add(sb, name + used, len - used);\n>>>  }\n>>>\n>>> -int check_branch_ref(struct strbuf *sb, const char *name)\n>>> +int check_branch_ref(struct repository *repo, struct strbuf *sb, \n>>> const char *name)\n>>>  {\n>>>      if (startup_info->have_repository)\n>>> -        copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n>>> +        copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n>>>      else\n>>>          strbuf_addstr(sb, name);\n>>>\n>>\n>> I have to agree with Tian's comment on v2, this part here looks wrong. I\n>> don't think we should depend on `startup_info` here, but we should\n>> exclusively rely on whether or not the caller has passed in a\n>> repository. And that will likely require a bit more scrutiny to figure\n>> out whether there are any callers that shouldn't pass in a repository\n>> because it's not initialized.\n>>\n>> Alternatively, we could go with Tian's suggestion of checking for `repo\n>> && repo->gitdir`.\n>>\n>> Patrick\n> \n> This approach actually leads to a bug and segfault in a specific edge\n> case when running 'git check-ref-format'. The current tests don't cover\n> this scenario, but they can be extended to catch it.\n> \n> If GIT_DIR is set to a non-existent path,\n> 'startup_info->have_repository' becomes '0' but 'repo->gitdir' still\n> holds the invalid path. As a result, the code enters the first condition\n> and crashes. The case can be tested with this command:\n> \n> $ git --git-dir='non-existing' check-ref-format --branch @{-1}\n> \n> Modifying the behavior of 'repo->gitdir' might solve the issue, but I\n> belive that falls outside the scope of this patch. After a quick search,\n> I found a prophecy from Peff about the 'startup_info->have_repository':\n> \n> [1] https://lore.kernel.org/ \n> git/20190806124954.GA13649@sigill.intra.peff.net/\n> \n> Thanks,\n> Burak Kaan Karaçay\n\nYou’re absolutely right.\n\nActually, I’d already spotted the error when I wrote that bit of code, \nwhich is why I said 'I dunno' - simply to give an idea of what I was \ntrying to achieve. It looks like we’ll have to go with a much uglier \nsolution. ;)\n\nOne possible approach (albeit temporary and useless) is to wrap the code \nin a macro or an inline function (in repository.h, I guess?):\n\n> static inline int repo_has_repository(struct repository *repo)\n> {\n> \t/*  \n >\t* NEEDSWORK...\n>\t*/> \tif (repo == the_repository)\n> \t\treturn startup_info->have_repository;\n> \n> \treturn repo && repo->gitdir;\n> }\n\nThis will remove a large amount of startup_info->have_repository...But \nthat doesn’t solve anything, just as stuffing rubbish into a bin doesn’t \nchange the fact that it’s rubbish. The 'startup_info->have_repository' \nstill requires a significant amount of effort to refactor.\n\nSo still, I dunno.\n\nRegards, Yuchen\n"},{"id":"540785","messageId":"ac68ME2j5CXzVgxF@pks.im","threadId":"65352","inReplyTo":"ac6K5UnVdw67Rfpy@gmail.com","subject":"Re: [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-04-02T18:57:52Z","receivedAt":"2026-04-02T18:58:05Z","isPatch":true,"body":"On Thu, Apr 02, 2026 at 08:03:45PM +0300, Burak Kaan Karaçay wrote:\n> Hi,\n> \n> On Thu, Apr 02, 2026 at 09:27:33AM +0200, Patrick Steinhardt wrote:\n> > On Sun, Mar 29, 2026 at 03:46:39PM +0530, Shreyansh Paliwal wrote:\n> > > diff --git a/refs.c b/refs.c\n> > > index 685a0c247b..5cdc8858c5 100644\n> > > --- a/refs.c\n> > > +++ b/refs.c\n> > > @@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,\n> > >  \tstrbuf_add(sb, name + used, len - used);\n> > >  }\n> > > \n> > > -int check_branch_ref(struct strbuf *sb, const char *name)\n> > > +int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n> > >  {\n> > >  \tif (startup_info->have_repository)\n> > > -\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n> > > +\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n> > >  \telse\n> > >  \t\tstrbuf_addstr(sb, name);\n> > > \n> > \n> > I have to agree with Tian's comment on v2, this part here looks wrong. I\n> > don't think we should depend on `startup_info` here, but we should\n> > exclusively rely on whether or not the caller has passed in a\n> > repository. And that will likely require a bit more scrutiny to figure\n> > out whether there are any callers that shouldn't pass in a repository\n> > because it's not initialized.\n> > \n> > Alternatively, we could go with Tian's suggestion of checking for `repo\n> > && repo->gitdir`.\n> > \n> > Patrick\n> \n> This approach actually leads to a bug and segfault in a specific edge\n> case when running 'git check-ref-format'. The current tests don't cover\n> this scenario, but they can be extended to catch it.\n\n> If GIT_DIR is set to a non-existent path,\n> 'startup_info->have_repository' becomes '0' but 'repo->gitdir' still\n> holds the invalid path. As a result, the code enters the first condition\n> and crashes. The case can be tested with this command:\n> \n> $ git --git-dir='non-existing' check-ref-format --branch @{-1}\n> \n> Modifying the behavior of 'repo->gitdir' might solve the issue, but I\n> belive that falls outside the scope of this patch. After a quick search,\n> I found a prophecy from Peff about the 'startup_info->have_repository':\n> \n> [1] https://lore.kernel.org/git/20190806124954.GA13649@sigill.intra.peff.net/\n\nIf we cannot make it work in this patch series, the next question is\nwhether we actually want to give the false sense of `check_branch_ref()`\nbeing independent of global state, or whether we want to leave it as-is\nfor now and then do a follow-up patch series where we fix the issue and\nadapt the interface.\n\nPatrick\n"},{"id":"540847","messageId":"CAPYXD646gcj-fmy0fqZUrKsSt1=+ZW4iRsVuJoLf0yUyUddigQ@mail.gmail.com","threadId":"65352","inReplyTo":"ac68ME2j5CXzVgxF@pks.im","subject":"Re: [PATCH v3 1/5] refs: add struct repository parameter to branchname helpers","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-03T10:39:02Z","receivedAt":"2026-04-03T10:39:16Z","isPatch":true,"body":"On Fri, Apr 3, 2026 at 12:28 AM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Thu, Apr 02, 2026 at 08:03:45PM +0300, Burak Kaan Karaçay wrote:\n> > Hi,\n> >\n> > On Thu, Apr 02, 2026 at 09:27:33AM +0200, Patrick Steinhardt wrote:\n> > > On Sun, Mar 29, 2026 at 03:46:39PM +0530, Shreyansh Paliwal wrote:\n> > > > diff --git a/refs.c b/refs.c\n> > > > index 685a0c247b..5cdc8858c5 100644\n> > > > --- a/refs.c\n> > > > +++ b/refs.c\n> > > > @@ -758,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,\n> > > >   strbuf_add(sb, name + used, len - used);\n> > > >  }\n> > > >\n> > > > -int check_branch_ref(struct strbuf *sb, const char *name)\n> > > > +int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n> > > >  {\n> > > >   if (startup_info->have_repository)\n> > > > -         copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n> > > > +         copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n> > > >   else\n> > > >           strbuf_addstr(sb, name);\n> > > >\n> > >\n> > > I have to agree with Tian's comment on v2, this part here looks wrong. I\n> > > don't think we should depend on `startup_info` here, but we should\n> > > exclusively rely on whether or not the caller has passed in a\n> > > repository. And that will likely require a bit more scrutiny to figure\n> > > out whether there are any callers that shouldn't pass in a repository\n> > > because it's not initialized.\n> > >\n> > > Alternatively, we could go with Tian's suggestion of checking for `repo\n> > > && repo->gitdir`.\n> > >\n> > > Patrick\n> >\n> > This approach actually leads to a bug and segfault in a specific edge\n> > case when running 'git check-ref-format'. The current tests don't cover\n> > this scenario, but they can be extended to catch it.\n>\n> > If GIT_DIR is set to a non-existent path,\n> > 'startup_info->have_repository' becomes '0' but 'repo->gitdir' still\n> > holds the invalid path. As a result, the code enters the first condition\n> > and crashes. The case can be tested with this command:\n> >\n> > $ git --git-dir='non-existing' check-ref-format --branch @{-1}\n> >\n> > Modifying the behavior of 'repo->gitdir' might solve the issue, but I\n> > belive that falls outside the scope of this patch. After a quick search,\n> > I found a prophecy from Peff about the 'startup_info->have_repository':\n> >\n> > [1] https://lore.kernel.org/git/20190806124954.GA13649@sigill.intra.peff.net/\n>\n> If we cannot make it work in this patch series, the next question is\n> whether we actually want to give the false sense of `check_branch_ref()`\n> being independent of global state, or whether we want to leave it as-is\n> for now and then do a follow-up patch series where we fix the issue and\n> adapt the interface.\n\nI think it makes sense to drop patch 1/5 from this series for now, which\nintroduces changes to the branch name helper functions.\nIt would be much better to address this separately after replacing\nstartup_info->have_repository.\nFor now, I'll reroll the series with the remaining patches and send this\npart later as an rfc.\n\nThanks everyone,\nShreyansh\n"},{"id":"540848","messageId":"CAPYXD64sR3D9Qhdf4a2O91ENwFO+dLirWRrneG0+ykoUexEGzQ@mail.gmail.com","threadId":"65352","inReplyTo":"ac4aa-qLWwoZ9uPZ@pks.im","subject":"Re: [PATCH v3 4/5] refs/reftable-backend: drop uses of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-03T10:43:21Z","receivedAt":"2026-04-03T10:43:32Z","isPatch":true,"body":"On Thu, Apr 2, 2026 at 12:57 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Sun, Mar 29, 2026 at 03:46:42PM +0530, Shreyansh Paliwal wrote:\n> > reftable_be_init() and reftable_be_create_on_disk() use the_repository even\n> > though a repository instance is already available, either directly or via\n> > struct ref_store.\n> >\n> > Replace these uses with the appropriate local repository instance (repo or\n> > ref_store->repo) to avoid relying on global state.\n> >\n> > Note that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\n> > is_bare_repository() is still there in the file.\n>\n> I've got a patch series cooking now that'll eventually de-globalize\n> `is_bare_repository()`. So there's light at the end of the tunnel here :)\n\nThat's great to hear, thanks for the heads-up :)\n"},{"id":"540851","messageId":"20260403120938.1142533-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260329101725.1092900-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v4 0/3] refs: reduce reliance on global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-03T12:08:57Z","receivedAt":"2026-04-03T12:10:09Z","isPatch":true,"body":"This series continues the effort to reduce reliance on the_repository\nglobal state by making repository context explicit across the refs\nsubsystem. The patches focus on passing struct repository through various\nref helpers and backends, and replacing uses of global state such as\nthe_repository and the_hash_algo with the appropriate repository instance.\n\nPatch 1/3: Updating get_files_ref_lock_timeout_ms() to take a repository\nand propagating it through files-backend, including callback paths.\n\nPatch 2/3:Replacing uses of the_hash_algo in refs.c with the hash\nalgorithm from the appropriate repository.\n\nPatch 3/3:Removing remaining uses of the_repository in reftable-backend.c\nwhere a repository instance is already available.\n\nShreyansh Paliwal (3):\n  refs: add struct repository parameter in\n    get_files_ref_lock_timeout_ms()\n  refs: remove the_hash_algo global state\n  refs/reftable-backend: drop uses of the_repository\n\n refs.c                  | 17 +++++++++--------\n refs/files-backend.c    | 19 +++++++++++++------\n refs/refs-internal.h    |  2 +-\n refs/reftable-backend.c |  6 +++---\n 4 files changed, 26 insertions(+), 18 deletions(-)\n\n---\nChanges in v4:\n - Dropped patches 1/5 and 5/5, as they require further refactoring and\n   discussion. I will send them separately as a follow-up.\n\nChanges in v3:\n - Fixed an import\n - better readability in patch 3/5\n\nChanges in v2:\n - Made struct repository the first argument in function parameters.\n\nRange-diff against v3:\n2:  f7a9ea4204 = 1:  11c134b3f5 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()\n1:  5844440b73 ! 2:  d144e879ad refs: add struct repository parameter to branchname helpers\n    @@ Metadata\n     Author: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n\n      ## Commit message ##\n    -    refs: add struct repository parameter to branchname helpers\n    +    refs: remove the_hash_algo global state\n\n    -    copy_branchname() in refs.c relies on the_repository when calling\n    -    repo_interpret_branch_name(), introducing an implicit dependency on global\n    -    state. Add a struct repository parameter and use it instead.\n    -\n    -    Update check_branch_ref() to take a repository parameter as well, since it\n    -    calls copy_branchname(). Propagate this change to higher-level helpers\n    -    validate_branchname() and validate_new_branchname(), which also lack access\n    -    to a repository instance. Most callers of these helpers reside in builtin\n    -    code and already operate on the_repository, so pass it explicitly at those\n    -    call sites (builtin/checkout and builtin/worktree) otherwise pass struct\n    -    repository where available.\n    -\n    -    This makes branch name handling explicitly repository-aware and aligns with\n    -    ongoing efforts to remove reliance on global state. This change builds on\n    -    top of jw/object-name-bitset-to-enum (2026-03-18), which introduced the\n    -    enum interpret_branch_kind parameter to copy_branchname().\n    +    refs.c uses the_hash_algo in multiple places, relying on global state for\n    +    the object hash algorithm. Replace these uses with the appropriate\n    +    repository-specific hash_algo. In transaction-related functions\n    +    (ref_transaction_create, ref_transaction_delete, migrate_one_ref, and\n    +    transaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo.\n    +    In other cases, such as repo_get_submodule_ref_store(), use\n    +    repo->hash_algo.\n\n         Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n\n    - ## branch.c ##\n    -@@ branch.c: int read_branch_desc(struct strbuf *buf, const char *branch_name)\n    -  * Return 1 if the named branch already exists; return 0 otherwise.\n    -  * Fill ref with the full refname for the branch.\n    -  */\n    --int validate_branchname(const char *name, struct strbuf *ref)\n    -+int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref)\n    - {\n    --\tif (check_branch_ref(ref, name)) {\n    -+\tif (check_branch_ref(repo, ref, name)) {\n    - \t\tint code = die_message(_(\"'%s' is not a valid branch name\"), name);\n    - \t\tadvise_if_enabled(ADVICE_REF_SYNTAX,\n    - \t\t\t\t  _(\"See 'git help check-ref-format'\"));\n    - \t\texit(code);\n    + ## refs.c ##\n    +@@ refs.c: int ref_transaction_create(struct ref_transaction *transaction,\n    + \t\treturn 1;\n      \t}\n    -\n    --\treturn refs_ref_exists(get_main_ref_store(the_repository), ref->buf);\n    -+\treturn refs_ref_exists(get_main_ref_store(repo), ref->buf);\n    + \treturn ref_transaction_update(transaction, refname, new_oid,\n    +-\t\t\t\t      null_oid(the_hash_algo), new_target, NULL, flags,\n    ++\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,\n    + \t\t\t\t      msg, err);\n      }\n\n    - static int initialized_checked_out_branches;\n    -@@ branch.c: const char *branch_checked_out(const char *refname)\n    -  * Return 1 if the named branch already exists; return 0 otherwise.\n    -  * Fill ref with the full refname for the branch.\n    -  */\n    --int validate_new_branchname(const char *name, struct strbuf *ref, int force)\n    -+int validate_new_branchname(struct repository *repo, const char *name,\n    -+\t\t\t    struct strbuf *ref, int force)\n    - {\n    - \tconst char *path;\n    --\tif (!validate_branchname(name, ref))\n    -+\tif (!validate_branchname(repo, name, ref))\n    - \t\treturn 0;\n    -\n    - \tif (!force)\n    -@@ branch.c: void create_branch(struct repository *r,\n    - \t\tBUG(\"'clobber_head_ok' can only be used with 'force'\");\n    -\n    - \tif (clobber_head_ok ?\n    --\t\t\t  validate_branchname(name, &ref) :\n    --\t\t\t  validate_new_branchname(name, &ref, force)) {\n    -+\t\t\t  validate_branchname(r, name, &ref) :\n    -+\t\t\t  validate_new_branchname(r, name, &ref, force)) {\n    - \t\tforcing = 1;\n    +@@ refs.c: int ref_transaction_delete(struct ref_transaction *transaction,\n    + \tif (old_target && !(flags & REF_NO_DEREF))\n    + \t\tBUG(\"delete cannot operate on symrefs with deref mode\");\n    + \treturn ref_transaction_update(transaction, refname,\n    +-\t\t\t\t      null_oid(the_hash_algo), old_oid,\n    ++\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), old_oid,\n    + \t\t\t\t      NULL, old_target, flags,\n    + \t\t\t\t      msg, err);\n    + }\n    +@@ refs.c: struct ref_store *repo_get_submodule_ref_store(struct repository *repo,\n    + \tsubrepo = xmalloc(sizeof(*subrepo));\n    +\n    + \tif (repo_submodule_init(subrepo, repo, submodule,\n    +-\t\t\t\tnull_oid(the_hash_algo))) {\n    ++\t\t\t\tnull_oid(repo->hash_algo))) {\n    + \t\tfree(subrepo);\n    + \t\tgoto done;\n      \t}\n    -\n    -\n    - ## branch.h ##\n    -@@ branch.h: const char *branch_checked_out(const char *refname);\n    -  * Return 1 if the named branch already exists; return 0 otherwise.\n    -  * Fill ref with the full refname for the branch.\n    -  */\n    --int validate_branchname(const char *name, struct strbuf *ref);\n    -+int validate_branchname(struct repository *repo, const char *name, struct strbuf *ref);\n    -\n    - /*\n    -  * Check if a branch 'name' can be created as a new branch; die otherwise.\n    -@@ branch.h: int validate_branchname(const char *name, struct strbuf *ref);\n    -  * Return 1 if the named branch already exists; return 0 otherwise.\n    -  * Fill ref with the full refname for the branch.\n    -  */\n    --int validate_new_branchname(const char *name, struct strbuf *ref, int force);\n    -+int validate_new_branchname(struct repository *repo, const char *name,\n    -+\t\t\t    struct strbuf *ref, int force);\n    -\n    - /*\n    -  * Remove information about the merge state on the current\n    -\n    - ## builtin/branch.c ##\n    -@@ builtin/branch.c: static int delete_branches(int argc, const char **argv, int force, int kinds,\n    - \t\tchar *target = NULL;\n    - \t\tint flags = 0;\n    -\n    --\t\tcopy_branchname(&bname, argv[i], allowed_interpret);\n    -+\t\tcopy_branchname(the_repository, &bname, argv[i], allowed_interpret);\n    - \t\tfree(name);\n    - \t\tname = mkpathdup(fmt, bname.buf);\n    -\n    -@@ builtin/branch.c: static void copy_or_rename_branch(const char *oldname, const char *newname, int\n    - \tint recovery = 0, oldref_usage = 0;\n    - \tstruct worktree **worktrees = get_worktrees();\n    -\n    --\tif (check_branch_ref(&oldref, oldname)) {\n    -+\tif (check_branch_ref(the_repository, &oldref, oldname)) {\n    - \t\t/*\n    - \t\t * Bad name --- this could be an attempt to rename a\n    - \t\t * ref that we used to allow to be created by accident.\n    -@@ builtin/branch.c: static void copy_or_rename_branch(const char *oldname, const char *newname, int\n    - \t * cause the worktree to become inconsistent with HEAD, so allow it.\n    - \t */\n    - \tif (!strcmp(oldname, newname))\n    --\t\tvalidate_branchname(newname, &newref);\n    -+\t\tvalidate_branchname(the_repository, newname, &newref);\n    +@@ refs.c: static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_\n    + \tstrbuf_reset(buf);\n    +\n    + \tif (!(update->flags & REF_HAVE_OLD))\n    +-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n    ++\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n    + \telse if (update->old_target)\n    + \t\tstrbuf_addf(buf, \"ref:%s \", update->old_target);\n      \telse\n    --\t\tvalidate_new_branchname(newname, &newref, force);\n    -+\t\tvalidate_new_branchname(the_repository, newname, &newref, force);\n    -\n    - \treject_rebase_or_bisect_branch(worktrees, oldref.buf);\n    + \t\tstrbuf_addf(buf, \"%s \", oid_to_hex(&update->old_oid));\n\n    -@@ builtin/branch.c: int cmd_branch(int argc,\n    - \t\t\t\tdie(_(\"cannot give description to detached HEAD\"));\n    - \t\t\tbranch_name = head;\n    - \t\t} else if (argc == 1) {\n    --\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    -+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    - \t\t\tbranch_name = buf.buf;\n    - \t\t} else {\n    - \t\t\tdie(_(\"cannot edit description of more than one branch\"));\n    -@@ builtin/branch.c: int cmd_branch(int argc,\n    - \t\tif (!argc)\n    - \t\t\tbranch = branch_get(NULL);\n    - \t\telse if (argc == 1) {\n    --\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    -+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    - \t\t\tbranch = branch_get(buf.buf);\n    - \t\t} else\n    - \t\t\tdie(_(\"too many arguments to set new upstream\"));\n    -@@ builtin/branch.c: int cmd_branch(int argc,\n    - \t\tif (!argc)\n    - \t\t\tbranch = branch_get(NULL);\n    - \t\telse if (argc == 1) {\n    --\t\t\tcopy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    -+\t\t\tcopy_branchname(the_repository, &buf, argv[0], INTERPRET_BRANCH_LOCAL);\n    - \t\t\tbranch = branch_get(buf.buf);\n    - \t\t} else\n    - \t\t\tdie(_(\"too many arguments to unset upstream\"));\n    -\n    - ## builtin/check-ref-format.c ##\n    -@@\n    - /*\n    -  * GIT - The information manager from hell\n    -  */\n    -+#define USE_THE_REPOSITORY_VARIABLE\n    - #include \"builtin.h\"\n    - #include \"refs.h\"\n    - #include \"setup.h\"\n    -@@ builtin/check-ref-format.c: static int check_ref_format_branch(const char *arg)\n    - \tint nongit;\n    -\n    - \tsetup_git_directory_gently(&nongit);\n    --\tif (check_branch_ref(&sb, arg) ||\n    -+\tif (check_branch_ref(the_repository, &sb, arg) ||\n    - \t    !skip_prefix(sb.buf, \"refs/heads/\", &name))\n    - \t\tdie(\"'%s' is not a valid branch name\", arg);\n    - \tprintf(\"%s\\n\", name);\n    -\n    - ## builtin/checkout.c ##\n    -@@ builtin/checkout.c: static void setup_branch_path(struct branch_info *branch)\n    - \t\t\t   &branch->oid, &branch->refname, 0))\n    - \t\trepo_get_oid_committish(the_repository, branch->name, &branch->oid);\n    -\n    --\tcopy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);\n    -+\tcopy_branchname(the_repository, &buf, branch->name, INTERPRET_BRANCH_LOCAL);\n    - \tif (strcmp(buf.buf, branch->name)) {\n    - \t\tfree(branch->name);\n    - \t\tbranch->name = xstrdup(buf.buf);\n    -@@ builtin/checkout.c: static int checkout_main(int argc, const char **argv, const char *prefix,\n    - \t\tstruct strbuf buf = STRBUF_INIT;\n    -\n    - \t\tif (opts->new_branch_force)\n    --\t\t\topts->branch_exists = validate_branchname(opts->new_branch, &buf);\n    -+\t\t\topts->branch_exists = validate_branchname(the_repository, opts->new_branch, &buf);\n    - \t\telse\n    - \t\t\topts->branch_exists =\n    --\t\t\t\tvalidate_new_branchname(opts->new_branch, &buf, 0);\n    -+\t\t\t\tvalidate_new_branchname(the_repository, opts->new_branch, &buf, 0);\n    - \t\tstrbuf_release(&buf);\n    - \t}\n    -\n    -\n    - ## builtin/merge.c ##\n    -@@ builtin/merge.c: static void merge_name(const char *remote, struct strbuf *msg)\n    - \tchar *found_ref = NULL;\n    - \tint len, early;\n    -\n    --\tcopy_branchname(&bname, remote, 0);\n    -+\tcopy_branchname(the_repository, &bname, remote, 0);\n    - \tremote = bname.buf;\n    -\n    - \toidclr(&branch_head, the_repository->hash_algo);\n    -\n    - ## builtin/worktree.c ##\n    -@@ builtin/worktree.c: static int make_worktree_orphan(const char * ref, const struct add_opts *opts,\n    - \tstruct strbuf symref = STRBUF_INIT;\n    - \tstruct child_process cp = CHILD_PROCESS_INIT;\n    -\n    --\tvalidate_new_branchname(ref, &symref, 0);\n    -+\tvalidate_new_branchname(the_repository, ref, &symref, 0);\n    - \tstrvec_pushl(&cp.args, \"symbolic-ref\", \"HEAD\", symref.buf, NULL);\n    - \tif (opts->quiet)\n    - \t\tstrvec_push(&cp.args, \"--quiet\");\n    -@@ builtin/worktree.c: static int add_worktree(const char *path, const char *refname,\n    - \tworktrees = NULL;\n    -\n    - \t/* is 'refname' a branch or commit? */\n    --\tif (!opts->detach && !check_branch_ref(&symref, refname) &&\n    -+\tif (!opts->detach && !check_branch_ref(the_repository, &symref, refname) &&\n    - \t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {\n    - \t\tis_branch = 1;\n    - \t\tif (!opts->force)\n    -@@ builtin/worktree.c: static void print_preparing_worktree_line(int detach,\n    - \t\tfprintf_ln(stderr, _(\"Preparing worktree (new branch '%s')\"), new_branch);\n    - \t} else {\n    - \t\tstruct strbuf s = STRBUF_INIT;\n    --\t\tif (!detach && !check_branch_ref(&s, branch) &&\n    -+\t\tif (!detach && !check_branch_ref(the_repository, &s, branch) &&\n    - \t\t    refs_ref_exists(get_main_ref_store(the_repository), s.buf))\n    - \t\t\tfprintf_ln(stderr, _(\"Preparing worktree (checking out '%s')\"),\n    - \t\t\t\t  branch);\n    -@@ builtin/worktree.c: static char *dwim_branch(const char *path, char **new_branch)\n    - \tchar *branchname = xstrndup(s, n);\n    - \tstruct strbuf ref = STRBUF_INIT;\n    -\n    --\tbranch_exists = !check_branch_ref(&ref, branchname) &&\n    -+\tbranch_exists = !check_branch_ref(the_repository, &ref, branchname) &&\n    - \t\t\trefs_ref_exists(get_main_ref_store(the_repository),\n    - \t\t\t\t\tref.buf);\n    - \tstrbuf_release(&ref);\n    -@@ builtin/worktree.c: static int add(int ac, const char **av, const char *prefix,\n    - \t\tnew_branch = new_branch_force;\n    -\n    - \t\tif (!opts.force &&\n    --\t\t    !check_branch_ref(&symref, new_branch) &&\n    -+\t\t    !check_branch_ref(the_repository, &symref, new_branch) &&\n    - \t\t    refs_ref_exists(get_main_ref_store(the_repository), symref.buf))\n    - \t\t\tdie_if_checked_out(symref.buf, 0);\n    - \t\tstrbuf_release(&symref);\n    -\n    - ## refs.c ##\n    -@@ refs.c: static char *substitute_branch_name(struct repository *r,\n    - \treturn NULL;\n    - }\n    -\n    --void copy_branchname(struct strbuf *sb, const char *name,\n    -+void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n    - \t\t     enum interpret_branch_kind allowed)\n    - {\n    - \tint len = strlen(name);\n    - \tstruct interpret_branch_name_options options = {\n    - \t\t.allowed = allowed\n    - \t};\n    --\tint used = repo_interpret_branch_name(the_repository, name, len, sb,\n    -+\tint used = repo_interpret_branch_name(repo, name, len, sb,\n    - \t\t\t\t\t      &options);\n    -\n    - \tif (used < 0)\n    -@@ refs.c: void copy_branchname(struct strbuf *sb, const char *name,\n    - \tstrbuf_add(sb, name + used, len - used);\n    - }\n    -\n    --int check_branch_ref(struct strbuf *sb, const char *name)\n    -+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)\n    - {\n    - \tif (startup_info->have_repository)\n    --\t\tcopy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);\n    -+\t\tcopy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);\n    + \tif (!(update->flags & REF_HAVE_NEW))\n    +-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n    ++\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n    + \telse if (update->new_target)\n    + \t\tstrbuf_addf(buf, \"ref:%s \", update->new_target);\n      \telse\n    - \t\tstrbuf_addstr(sb, name);\n    -\n    -\n    - ## refs.h ##\n    -@@ refs.h: char *repo_default_branch_name(struct repository *r, int quiet);\n    -  * If \"allowed\" is non-zero, restrict the set of allowed expansions. See\n    -  * repo_interpret_branch_name() for details.\n    -  */\n    --void copy_branchname(struct strbuf *sb, const char *name,\n    -+void copy_branchname(struct repository *repo, struct strbuf *sb, const char *name,\n    - \t\t     enum interpret_branch_kind allowed);\n    -\n    - /*\n    -@@ refs.h: void copy_branchname(struct strbuf *sb, const char *name,\n    -  *\n    -  * The return value is \"0\" if the result is valid, and \"-1\" otherwise.\n    -  */\n    --int check_branch_ref(struct strbuf *sb, const char *name);\n    -+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name);\n    -\n    - /*\n    -  * Similar for a tag name in refs/tags/.\n    +@@ refs.c: struct migration_data {\n    + static int migrate_one_ref(const struct reference *ref, void *cb_data)\n    + {\n    + \tstruct migration_data *data = cb_data;\n    ++\tconst struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;\n    + \tstruct strbuf symref_target = STRBUF_INIT;\n    + \tint ret;\n    +\n    +@@ refs.c: static int migrate_one_ref(const struct reference *ref, void *cb_data)\n    + \t\tif (ret < 0)\n    + \t\t\tgoto done;\n    +\n    +-\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n    ++\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),\n    + \t\t\t\t\t     symref_target.buf, NULL,\n    + \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n    + \t\tif (ret < 0)\n3:  00dba1a96a < -:  ---------- refs: remove the_hash_algo global state\n4:  5653c418e1 = 3:  76c14eb320 refs/reftable-backend: drop uses of the_repository\n5:  18c1c67083 < -:  ---------- refs/packed-backend: use ref_store->repo instead of the_repository\n--\n2.53.0\n\n"},{"id":"540852","messageId":"20260403120938.1142533-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260403120938.1142533-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v4 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms()","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-03T12:08:58Z","receivedAt":"2026-04-03T12:10:14Z","isPatch":true,"body":"get_files_ref_lock_timeout_ms() calls repo_config_get_int() using\nthe_repository, as no repository instance is available in its scope. Add a\nstruct repository parameter and use it instead of the_repository.\n\nUpdate all callers accordingly. In files-backend.c, lock_raw_ref() can\nobtain repository instance from the struct ref_transaction via\ntransaction->ref_store->repo and pass it down. For create_reflock(), which\nis used as a callback, introduce a small wrapper struct to pass both struct\nlock_file and struct repository through the callback data.\n\nThis reduces reliance on the_repository global.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c               |  4 ++--\n refs/files-backend.c | 19 +++++++++++++------\n refs/refs-internal.h |  2 +-\n 3 files changed, 16 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 685a0c247b..214ebfd5ce 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,\n \treturn REF_WORKTREE_SHARED;\n }\n \n-long get_files_ref_lock_timeout_ms(void)\n+long get_files_ref_lock_timeout_ms(struct repository *repo)\n {\n \tstatic int configured = 0;\n \n@@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)\n \tstatic int timeout_ms = 100;\n \n \tif (!configured) {\n-\t\trepo_config_get_int(the_repository, \"core.filesreflocktimeout\", &timeout_ms);\n+\t\trepo_config_get_int(repo, \"core.filesreflocktimeout\", &timeout_ms);\n \t\tconfigured = 1;\n \t}\n \ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 7ce0d57478..ee8dd771a4 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -792,7 +792,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,\n \n \tif (hold_lock_file_for_update_timeout(\n \t\t\t    &lock->lk, ref_file.buf, LOCK_NO_DEREF,\n-\t\t\t    get_files_ref_lock_timeout_ms()) < 0) {\n+\t\t\t    get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {\n \t\tint myerr = errno;\n \t\terrno = 0;\n \t\tif (myerr == ENOENT && --attempts_remaining > 0) {\n@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)\n \treturn remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);\n }\n \n+struct create_reflock_cb {\n+    struct lock_file *lk;\n+    struct repository *repo;\n+};\n+\n static int create_reflock(const char *path, void *cb)\n {\n-\tstruct lock_file *lk = cb;\n-\n+\tstruct create_reflock_cb *data = cb;\n \treturn hold_lock_file_for_update_timeout(\n-\t\t\tlk, path, LOCK_NO_DEREF,\n-\t\t\tget_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;\n+\t\t\tdata->lk, path, LOCK_NO_DEREF,\n+\t\t\tget_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;\n }\n \n /*\n@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n {\n \tstruct strbuf ref_file = STRBUF_INIT;\n \tstruct ref_lock *lock;\n+\tstruct create_reflock_cb cb_data;\n \n \tfiles_assert_main_repository(refs, \"lock_ref_oid_basic\");\n \tassert(err);\n@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n \n \tlock->ref_name = xstrdup(refname);\n \tlock->count = 1;\n+\tcb_data.lk   = &lock->lk;\n+\tcb_data.repo = refs->base.repo;\n \n-\tif (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {\n+\tif (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {\n \t\tunable_to_lock_message(ref_file.buf, errno, err);\n \t\tgoto error_return;\n \t}\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex d79e35fd26..e4cfd9e19e 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -43,7 +43,7 @@ struct ref_transaction;\n  * Return the length of time to retry acquiring a loose reference lock\n  * before giving up, in milliseconds:\n  */\n-long get_files_ref_lock_timeout_ms(void);\n+long get_files_ref_lock_timeout_ms(struct repository *repo);\n \n /*\n  * Return true iff refname is minimally safe. \"Safe\" here means that\n-- \n2.53.0\n\n"},{"id":"540853","messageId":"20260403120938.1142533-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260403120938.1142533-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v4 2/3] refs: remove the_hash_algo global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-03T12:08:59Z","receivedAt":"2026-04-03T12:10:19Z","isPatch":true,"body":"refs.c uses the_hash_algo in multiple places, relying on global state for\nthe object hash algorithm. Replace these uses with the appropriate\nrepository-specific hash_algo. In transaction-related functions\n(ref_transaction_create, ref_transaction_delete, migrate_one_ref, and\ntransaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo.\nIn other cases, such as repo_get_submodule_ref_store(), use\nrepo->hash_algo.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 214ebfd5ce..cb58e10dc6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1472,7 +1472,7 @@ int ref_transaction_create(struct ref_transaction *transaction,\n \t\treturn 1;\n \t}\n \treturn ref_transaction_update(transaction, refname, new_oid,\n-\t\t\t\t      null_oid(the_hash_algo), new_target, NULL, flags,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,\n \t\t\t\t      msg, err);\n }\n \n@@ -1491,7 +1491,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,\n \tif (old_target && !(flags & REF_NO_DEREF))\n \t\tBUG(\"delete cannot operate on symrefs with deref mode\");\n \treturn ref_transaction_update(transaction, refname,\n-\t\t\t\t      null_oid(the_hash_algo), old_oid,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), old_oid,\n \t\t\t\t      NULL, old_target, flags,\n \t\t\t\t      msg, err);\n }\n@@ -2379,7 +2379,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,\n \tsubrepo = xmalloc(sizeof(*subrepo));\n \n \tif (repo_submodule_init(subrepo, repo, submodule,\n-\t\t\t\tnull_oid(the_hash_algo))) {\n+\t\t\t\tnull_oid(repo->hash_algo))) {\n \t\tfree(subrepo);\n \t\tgoto done;\n \t}\n@@ -2571,14 +2571,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_\n \tstrbuf_reset(buf);\n \n \tif (!(update->flags & REF_HAVE_OLD))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->old_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->old_target);\n \telse\n \t\tstrbuf_addf(buf, \"%s \", oid_to_hex(&update->old_oid));\n \n \tif (!(update->flags & REF_HAVE_NEW))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->new_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->new_target);\n \telse\n@@ -3145,6 +3145,7 @@ struct migration_data {\n static int migrate_one_ref(const struct reference *ref, void *cb_data)\n {\n \tstruct migration_data *data = cb_data;\n+\tconst struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;\n \tstruct strbuf symref_target = STRBUF_INIT;\n \tint ret;\n \n@@ -3153,7 +3154,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)\n \t\tif (ret < 0)\n \t\t\tgoto done;\n \n-\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n+\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),\n \t\t\t\t\t     symref_target.buf, NULL,\n \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n \t\tif (ret < 0)\n-- \n2.53.0\n\n"},{"id":"540854","messageId":"20260403120938.1142533-4-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260403120938.1142533-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v4 3/3] refs/reftable-backend: drop uses of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-03T12:09:00Z","receivedAt":"2026-04-03T12:10:24Z","isPatch":true,"body":"reftable_be_init() and reftable_be_create_on_disk() use the_repository even\nthough a repository instance is already available, either directly or via\nstruct ref_store.\n\nReplace these uses with the appropriate local repository instance (repo or\nref_store->repo) to avoid relying on global state.\n\nNote that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\nis_bare_repository() is still there in the file.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/reftable-backend.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex b124404663..7c8a992fcb 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -404,13 +404,13 @@ static struct ref_store *reftable_be_init(struct repository *repo,\n \tdefault:\n \t\tBUG(\"unknown hash algorithm %d\", repo->hash_algo->format_id);\n \t}\n-\trefs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask);\n+\trefs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask);\n \trefs->write_options.disable_auto_compact =\n \t\t!git_env_bool(\"GIT_TEST_REFTABLE_AUTOCOMPACTION\", 1);\n \trefs->write_options.lock_timeout_ms = 100;\n \trefs->write_options.fsync = reftable_be_fsync;\n \n-\trepo_config(the_repository, reftable_be_config, &refs->write_options);\n+\trepo_config(repo, reftable_be_config, &refs->write_options);\n \n \t/*\n \t * It is somewhat unfortunate that we have to mirror the default block\n@@ -492,7 +492,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,\n \tstruct strbuf sb = STRBUF_INIT;\n \n \tstrbuf_addf(&sb, \"%s/reftable\", refs->base.gitdir);\n-\tsafe_create_dir(the_repository, sb.buf, 1);\n+\tsafe_create_dir(ref_store->repo, sb.buf, 1);\n \tstrbuf_reset(&sb);\n \n \tstrbuf_release(&sb);\n-- \n2.53.0\n\n"},{"id":"540859","messageId":"5017740b-4437-4e55-b019-244b33eed05a@gmail.com","threadId":"65352","inReplyTo":"20260403120938.1142533-2-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH v4 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms()","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-04-03T17:40:55Z","receivedAt":"2026-04-03T17:41:00Z","isPatch":true,"body":"On 4/3/26 20:08, Shreyansh Paliwal wrote:\n> -long get_files_ref_lock_timeout_ms(void)\n> +long get_files_ref_lock_timeout_ms(struct repository *repo)\n>   {\n>   \tstatic int configured = 0;\n>   \n> @@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)\n>   \tstatic int timeout_ms = 100;\n> \n\nA very minor and trivial question: the 'static' keyword is still present \nhere. This is entirely understandable, given that you mentioned earlier \nthat...\n\n> Hi Yuchen,\n> \n> I have acknowledged this in a previous reply to Burak. As stated there,\n> this is a valid issue and would require moving the config into\n> repo-settings struct.\n> In this patch, I focused on removing the dependency on\n> 'the_repository' while preserving existing behavior. Global state\n> removal and multi-repo correctness is an incremental process,\n> so I would prefer to handle this in a follow-up change.\n> I'll also update the patch title in the next version to better reflect\n> the scope of the change.\n\nBut if that is the case, the accuracy of this line in the commit message:\n\n> This reduces reliance on the_repository global.\n\n..is open to question. Or perhaps it would be worth mentioning:\n\n\"Note: This function still uses static variables, which means it does \nnot fully support in-process multi-repo usage yet. This will be \naddressed in a follow-up by moving the configuration to the \n'repo-settings' struct, but changing the signature is a necessary first \nstep...\"\n\nor something (shorter)?\n\nTo reiterate, I think this is a minor issue, so it would be better if \nyou decide for yourself. Other parts look good to me. ;)\n\nRegards, Yuchen\n\n\n"},{"id":"540887","messageId":"20260404135914.61195-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260403120938.1142533-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v5 0/3] refs: reduce reliance on global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-04T13:58:37Z","receivedAt":"2026-04-04T13:59:50Z","isPatch":true,"body":"This series continues the effort to reduce reliance on the_repository\nglobal state by making repository context explicit across the refs\nsubsystem. The patches focus on passing struct repository through various\nref helpers and backends, and replacing uses of global state such as\nthe_repository and the_hash_algo with the appropriate repository instance.\n\nPatch 1/3: Updating get_files_ref_lock_timeout_ms() to take a repository\nand propagating it through files-backend, including callback paths.\n\nPatch 2/3:Replacing uses of the_hash_algo in refs.c with the hash\nalgorithm from the appropriate repository.\n\nPatch 3/3:Removing remaining uses of the_repository in reftable-backend.c\nwhere a repository instance is already available.\n\nShreyansh Paliwal (3):\n  refs: add struct repository parameter in\n    get_files_ref_lock_timeout_ms()\n  refs: remove the_hash_algo global state\n  refs/reftable-backend: drop uses of the_repository\n\n refs.c                  | 17 +++++++++--------\n refs/files-backend.c    | 19 +++++++++++++------\n refs/refs-internal.h    |  2 +-\n refs/reftable-backend.c |  6 +++---\n 4 files changed, 26 insertions(+), 18 deletions(-)\n\n---\nChanges in v5:\n - made the commit message of patch 1/3 more explicit.\n\nChanges in v4:\n - Dropped patches 1/5 and 5/5, as they require further refactoring and\n   discussion. I will send them separately as a follow-up.\n\nChanges in v3:\n - Fixed an import\n - better readability in patch 3/5\n\nChanges in v2:\n - Made struct repository the first argument in function parameters.\n\nRange-diff against v4:\n1:  11c134b3f5 ! 1:  59c4662031 refs: add struct repository parameter in get_files_ref_lock_timeout_ms()\n    @@ Commit message\n         is used as a callback, introduce a small wrapper struct to pass both struct\n         lock_file and struct repository through the callback data.\n\n    -    This reduces reliance on the_repository global.\n    +    This reduces reliance on the_repository global, though the function\n    +    still uses static variables and is not yet fully repository-scoped.\n    +    This can be addressed in a follow-up change.\n\n         Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n\n2:  d144e879ad = 2:  9dd20df759 refs: remove the_hash_algo global state\n3:  76c14eb320 = 3:  04c88f7ed4 refs/reftable-backend: drop uses of the_repository\n--\n2.53.0\n\n"},{"id":"540888","messageId":"20260404135914.61195-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260404135914.61195-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v5 1/3] refs: add struct repository parameter in get_files_ref_lock_timeout_ms()","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-04T13:58:38Z","receivedAt":"2026-04-04T13:59:55Z","isPatch":true,"body":"get_files_ref_lock_timeout_ms() calls repo_config_get_int() using\nthe_repository, as no repository instance is available in its scope. Add a\nstruct repository parameter and use it instead of the_repository.\n\nUpdate all callers accordingly. In files-backend.c, lock_raw_ref() can\nobtain repository instance from the struct ref_transaction via\ntransaction->ref_store->repo and pass it down. For create_reflock(), which\nis used as a callback, introduce a small wrapper struct to pass both struct\nlock_file and struct repository through the callback data.\n\nThis reduces reliance on the_repository global, though the function\nstill uses static variables and is not yet fully repository-scoped.\nThis can be addressed in a follow-up change.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c               |  4 ++--\n refs/files-backend.c | 19 +++++++++++++------\n refs/refs-internal.h |  2 +-\n 3 files changed, 16 insertions(+), 9 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 685a0c247b..214ebfd5ce 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -989,7 +989,7 @@ enum ref_worktree_type parse_worktree_ref(const char *maybe_worktree_ref,\n \treturn REF_WORKTREE_SHARED;\n }\n \n-long get_files_ref_lock_timeout_ms(void)\n+long get_files_ref_lock_timeout_ms(struct repository *repo)\n {\n \tstatic int configured = 0;\n \n@@ -997,7 +997,7 @@ long get_files_ref_lock_timeout_ms(void)\n \tstatic int timeout_ms = 100;\n \n \tif (!configured) {\n-\t\trepo_config_get_int(the_repository, \"core.filesreflocktimeout\", &timeout_ms);\n+\t\trepo_config_get_int(repo, \"core.filesreflocktimeout\", &timeout_ms);\n \t\tconfigured = 1;\n \t}\n \ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 7ce0d57478..ee8dd771a4 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -792,7 +792,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs,\n \n \tif (hold_lock_file_for_update_timeout(\n \t\t\t    &lock->lk, ref_file.buf, LOCK_NO_DEREF,\n-\t\t\t    get_files_ref_lock_timeout_ms()) < 0) {\n+\t\t\t    get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {\n \t\tint myerr = errno;\n \t\terrno = 0;\n \t\tif (myerr == ENOENT && --attempts_remaining > 0) {\n@@ -1190,13 +1190,17 @@ static int remove_empty_directories(struct strbuf *path)\n \treturn remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);\n }\n \n+struct create_reflock_cb {\n+    struct lock_file *lk;\n+    struct repository *repo;\n+};\n+\n static int create_reflock(const char *path, void *cb)\n {\n-\tstruct lock_file *lk = cb;\n-\n+\tstruct create_reflock_cb *data = cb;\n \treturn hold_lock_file_for_update_timeout(\n-\t\t\tlk, path, LOCK_NO_DEREF,\n-\t\t\tget_files_ref_lock_timeout_ms()) < 0 ? -1 : 0;\n+\t\t\tdata->lk, path, LOCK_NO_DEREF,\n+\t\t\tget_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;\n }\n \n /*\n@@ -1208,6 +1212,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n {\n \tstruct strbuf ref_file = STRBUF_INIT;\n \tstruct ref_lock *lock;\n+\tstruct create_reflock_cb cb_data;\n \n \tfiles_assert_main_repository(refs, \"lock_ref_oid_basic\");\n \tassert(err);\n@@ -1229,8 +1234,10 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n \n \tlock->ref_name = xstrdup(refname);\n \tlock->count = 1;\n+\tcb_data.lk   = &lock->lk;\n+\tcb_data.repo = refs->base.repo;\n \n-\tif (raceproof_create_file(ref_file.buf, create_reflock, &lock->lk)) {\n+\tif (raceproof_create_file(ref_file.buf, create_reflock, &cb_data)) {\n \t\tunable_to_lock_message(ref_file.buf, errno, err);\n \t\tgoto error_return;\n \t}\ndiff --git a/refs/refs-internal.h b/refs/refs-internal.h\nindex d79e35fd26..e4cfd9e19e 100644\n--- a/refs/refs-internal.h\n+++ b/refs/refs-internal.h\n@@ -43,7 +43,7 @@ struct ref_transaction;\n  * Return the length of time to retry acquiring a loose reference lock\n  * before giving up, in milliseconds:\n  */\n-long get_files_ref_lock_timeout_ms(void);\n+long get_files_ref_lock_timeout_ms(struct repository *repo);\n \n /*\n  * Return true iff refname is minimally safe. \"Safe\" here means that\n-- \n2.53.0\n\n"},{"id":"540889","messageId":"20260404135914.61195-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260404135914.61195-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v5 2/3] refs: remove the_hash_algo global state","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-04T13:58:39Z","receivedAt":"2026-04-04T13:59:59Z","isPatch":true,"body":"refs.c uses the_hash_algo in multiple places, relying on global state for\nthe object hash algorithm. Replace these uses with the appropriate\nrepository-specific hash_algo. In transaction-related functions\n(ref_transaction_create, ref_transaction_delete, migrate_one_ref, and\ntransaction_hook_feed_stdin), use transaction->ref_store->repo->hash_algo.\nIn other cases, such as repo_get_submodule_ref_store(), use\nrepo->hash_algo.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs.c | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 214ebfd5ce..cb58e10dc6 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1472,7 +1472,7 @@ int ref_transaction_create(struct ref_transaction *transaction,\n \t\treturn 1;\n \t}\n \treturn ref_transaction_update(transaction, refname, new_oid,\n-\t\t\t\t      null_oid(the_hash_algo), new_target, NULL, flags,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), new_target, NULL, flags,\n \t\t\t\t      msg, err);\n }\n \n@@ -1491,7 +1491,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,\n \tif (old_target && !(flags & REF_NO_DEREF))\n \t\tBUG(\"delete cannot operate on symrefs with deref mode\");\n \treturn ref_transaction_update(transaction, refname,\n-\t\t\t\t      null_oid(the_hash_algo), old_oid,\n+\t\t\t\t      null_oid(transaction->ref_store->repo->hash_algo), old_oid,\n \t\t\t\t      NULL, old_target, flags,\n \t\t\t\t      msg, err);\n }\n@@ -2379,7 +2379,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,\n \tsubrepo = xmalloc(sizeof(*subrepo));\n \n \tif (repo_submodule_init(subrepo, repo, submodule,\n-\t\t\t\tnull_oid(the_hash_algo))) {\n+\t\t\t\tnull_oid(repo->hash_algo))) {\n \t\tfree(subrepo);\n \t\tgoto done;\n \t}\n@@ -2571,14 +2571,14 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_\n \tstrbuf_reset(buf);\n \n \tif (!(update->flags & REF_HAVE_OLD))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->old_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->old_target);\n \telse\n \t\tstrbuf_addf(buf, \"%s \", oid_to_hex(&update->old_oid));\n \n \tif (!(update->flags & REF_HAVE_NEW))\n-\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(the_hash_algo)));\n+\t\tstrbuf_addf(buf, \"%s \", oid_to_hex(null_oid(transaction->ref_store->repo->hash_algo)));\n \telse if (update->new_target)\n \t\tstrbuf_addf(buf, \"ref:%s \", update->new_target);\n \telse\n@@ -3145,6 +3145,7 @@ struct migration_data {\n static int migrate_one_ref(const struct reference *ref, void *cb_data)\n {\n \tstruct migration_data *data = cb_data;\n+\tconst struct git_hash_algo *hash_algo = data->transaction->ref_store->repo->hash_algo;\n \tstruct strbuf symref_target = STRBUF_INIT;\n \tint ret;\n \n@@ -3153,7 +3154,7 @@ static int migrate_one_ref(const struct reference *ref, void *cb_data)\n \t\tif (ret < 0)\n \t\t\tgoto done;\n \n-\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(the_hash_algo),\n+\t\tret = ref_transaction_update(data->transaction, ref->name, NULL, null_oid(hash_algo),\n \t\t\t\t\t     symref_target.buf, NULL,\n \t\t\t\t\t     REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);\n \t\tif (ret < 0)\n-- \n2.53.0\n\n"},{"id":"540890","messageId":"20260404135914.61195-4-shreyanshpaliwalcmsmn@gmail.com","threadId":"65352","inReplyTo":"20260404135914.61195-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[PATCH v5 3/3] refs/reftable-backend: drop uses of the_repository","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-04-04T13:58:40Z","receivedAt":"2026-04-04T14:00:03Z","isPatch":true,"body":"reftable_be_init() and reftable_be_create_on_disk() use the_repository even\nthough a repository instance is already available, either directly or via\nstruct ref_store.\n\nReplace these uses with the appropriate local repository instance (repo or\nref_store->repo) to avoid relying on global state.\n\nNote that USE_THE_REPOSITORY_VARIABLE cannot be removed yet, as\nis_bare_repository() is still there in the file.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n refs/reftable-backend.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/refs/reftable-backend.c b/refs/reftable-backend.c\nindex b124404663..7c8a992fcb 100644\n--- a/refs/reftable-backend.c\n+++ b/refs/reftable-backend.c\n@@ -404,13 +404,13 @@ static struct ref_store *reftable_be_init(struct repository *repo,\n \tdefault:\n \t\tBUG(\"unknown hash algorithm %d\", repo->hash_algo->format_id);\n \t}\n-\trefs->write_options.default_permissions = calc_shared_perm(the_repository, 0666 & ~mask);\n+\trefs->write_options.default_permissions = calc_shared_perm(repo, 0666 & ~mask);\n \trefs->write_options.disable_auto_compact =\n \t\t!git_env_bool(\"GIT_TEST_REFTABLE_AUTOCOMPACTION\", 1);\n \trefs->write_options.lock_timeout_ms = 100;\n \trefs->write_options.fsync = reftable_be_fsync;\n \n-\trepo_config(the_repository, reftable_be_config, &refs->write_options);\n+\trepo_config(repo, reftable_be_config, &refs->write_options);\n \n \t/*\n \t * It is somewhat unfortunate that we have to mirror the default block\n@@ -492,7 +492,7 @@ static int reftable_be_create_on_disk(struct ref_store *ref_store,\n \tstruct strbuf sb = STRBUF_INIT;\n \n \tstrbuf_addf(&sb, \"%s/reftable\", refs->base.gitdir);\n-\tsafe_create_dir(the_repository, sb.buf, 1);\n+\tsafe_create_dir(ref_store->repo, sb.buf, 1);\n \tstrbuf_reset(&sb);\n \n \tstrbuf_release(&sb);\n-- \n2.53.0\n\n"},{"id":"541122","messageId":"adYV6NK93Kzg1EYG@pks.im","threadId":"65352","inReplyTo":"20260404135914.61195-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [PATCH v5 0/3] refs: reduce reliance on global state","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-04-08T08:46:32Z","receivedAt":"2026-04-08T08:46:40Z","isPatch":true,"body":"On Sat, Apr 04, 2026 at 07:28:37PM +0530, Shreyansh Paliwal wrote:\n> Changes in v5:\n>  - made the commit message of patch 1/3 more explicit.\n> \n> Changes in v4:\n>  - Dropped patches 1/5 and 5/5, as they require further refactoring and\n>    discussion. I will send them separately as a follow-up.\n> \n> Changes in v3:\n>  - Fixed an import\n>  - better readability in patch 3/5\n> \n> Changes in v2:\n>  - Made struct repository the first argument in function parameters.\n\nThis version looks good to me. We bail on some of the more intricate\npieces, but that's totally fine as we can still fix these in a\nsubsequent patch series.\n\nThanks!\n\nPatrick\n"},{"id":"541152","messageId":"xmqqtstlz8d6.fsf@gitster.g","threadId":"65352","inReplyTo":"adYV6NK93Kzg1EYG@pks.im","subject":"Re: [PATCH v5 0/3] refs: reduce reliance on global state","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-04-08T17:09:57Z","receivedAt":"2026-04-08T17:10:00Z","isPatch":true,"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> On Sat, Apr 04, 2026 at 07:28:37PM +0530, Shreyansh Paliwal wrote:\n>> Changes in v5:\n>>  - made the commit message of patch 1/3 more explicit.\n>> \n>> Changes in v4:\n>>  - Dropped patches 1/5 and 5/5, as they require further refactoring and\n>>    discussion. I will send them separately as a follow-up.\n>> \n>> Changes in v3:\n>>  - Fixed an import\n>>  - better readability in patch 3/5\n>> \n>> Changes in v2:\n>>  - Made struct repository the first argument in function parameters.\n>\n> This version looks good to me. We bail on some of the more intricate\n> pieces, but that's totally fine as we can still fix these in a\n> subsequent patch series.\n>\n> Thanks!\n>\n> Patrick\n\nThanks for this ack---all of these iterations somehow escaped from\nmy radar.  Will apply.\n\n\n"}]}