refs: remove remaining uses of `the_repository`
There are still a couple of callsites that use `the_repository`. Convert these to instead use a repository injected by the caller. This allows us to remove `USE_THE_REPOSITORY_VARIABLE`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jul 16, 2026 at 07:33 UTC
b1296cb1aafd29c69e3b2a526b19c091f7fe5cf9
8 files changed
+29
-29
branch.c
+1
-1
@@ -372,7 +372,7 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
372
*/
373
int validate_branchname(const char *name, struct strbuf *ref)
374
{
375
- if (check_branch_ref(ref, name)) {
375
+ if (check_branch_ref(the_repository, ref, name)) {
376
int code = die_message(_("'%s' is not a valid branch name"), name);
377
advise_if_enabled(ADVICE_REF_SYNTAX,
378
_("See 'git help check-ref-format'"));
builtin/branch.c
+9
-5
@@ -259,7 +259,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
259
char *target = NULL;
260
int flags = 0;
261
262
- copy_branchname(&bname, argv[i], allowed_interpret);
262
+ copy_branchname(the_repository, &bname,
263
+ argv[i], allowed_interpret);
264
free(name);
265
name = mkpathdup(fmt, bname.buf);
266
@@ -581,7 +582,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
582
int recovery = 0, oldref_usage = 0;
583
struct worktree **worktrees = get_worktrees(the_repository);
584
584
- if (check_branch_ref(&oldref, oldname)) {
585
+ if (check_branch_ref(the_repository, &oldref, oldname)) {
586
/*
587
* Bad name --- this could be an attempt to rename a
588
* ref that we used to allow to be created by accident.
@@ -898,7 +899,8 @@ int cmd_branch(int argc,
899
die(_("cannot give description to detached HEAD"));
900
branch_name = head;
901
} else if (argc == 1) {
901
- copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
902
+ copy_branchname(the_repository, &buf, argv[0],
903
+ INTERPRET_BRANCH_LOCAL);
904
branch_name = buf.buf;
905
} else {
906
die(_("cannot edit description of more than one branch"));
@@ -941,7 +943,8 @@ int cmd_branch(int argc,
943
if (!argc)
944
branch = branch_get(NULL);
945
else if (argc == 1) {
944
- copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
946
+ copy_branchname(the_repository, &buf, argv[0],
947
+ INTERPRET_BRANCH_LOCAL);
948
branch = branch_get(buf.buf);
949
} else
950
die(_("too many arguments to set new upstream"));
@@ -971,7 +974,8 @@ int cmd_branch(int argc,
974
if (!argc)
975
branch = branch_get(NULL);
976
else if (argc == 1) {
974
- copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
977
+ copy_branchname(the_repository, &buf, argv[0],
978
+ INTERPRET_BRANCH_LOCAL);
979
branch = branch_get(buf.buf);
980
} else
981
die(_("too many arguments to unset upstream"));
builtin/check-ref-format.c
+1
-1
@@ -45,7 +45,7 @@ static int check_ref_format_branch(const char *arg)
45
int nongit;
46
47
setup_git_directory_gently(the_repository, &nongit);
48
- if (check_branch_ref(&sb, arg) ||
48
+ if (check_branch_ref(the_repository, &sb, arg) ||
49
!skip_prefix(sb.buf, "refs/heads/", &name))
50
die("'%s' is not a valid branch name", arg);
51
printf("%s\n", name);
builtin/checkout.c
+1
-1
@@ -805,7 +805,7 @@ static void setup_branch_path(struct branch_info *branch)
805
&branch->oid, &branch->refname, 0))
806
repo_get_oid_committish(the_repository, branch->name, &branch->oid);
807
808
- copy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
808
+ copy_branchname(the_repository, &buf, branch->name, INTERPRET_BRANCH_LOCAL);
809
if (strcmp(buf.buf, branch->name)) {
810
free(branch->name);
811
branch->name = xstrdup(buf.buf);
builtin/merge.c
+1
-1
@@ -553,7 +553,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
553
char *found_ref = NULL;
554
int len, early;
555
556
- copy_branchname(&bname, remote, 0);
556
+ copy_branchname(the_repository, &bname, remote, 0);
557
remote = bname.buf;
558
559
oidclr(&branch_head, the_repository->hash_algo);
builtin/worktree.c
+4
-4
@@ -481,7 +481,7 @@ static int add_worktree(const char *path, const char *refname,
481
worktrees = NULL;
482
483
/* is 'refname' a branch or commit? */
484
- if (!opts->detach && !check_branch_ref(&symref, refname) &&
484
+ if (!opts->detach && !check_branch_ref(the_repository, &symref, refname) &&
485
refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {
486
is_branch = 1;
487
if (!opts->force)
@@ -650,7 +650,7 @@ static void print_preparing_worktree_line(int detach,
650
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
651
} else {
652
struct strbuf s = STRBUF_INIT;
653
- if (!detach && !check_branch_ref(&s, branch) &&
653
+ if (!detach && !check_branch_ref(the_repository, &s, branch) &&
654
refs_ref_exists(get_main_ref_store(the_repository), s.buf))
655
fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
656
branch);
@@ -772,7 +772,7 @@ static char *dwim_branch(const char *path, char **new_branch)
772
char *branchname = xstrndup(s, n);
773
struct strbuf ref = STRBUF_INIT;
774
775
- branch_exists = !check_branch_ref(&ref, branchname) &&
775
+ branch_exists = !check_branch_ref(the_repository, &ref, branchname) &&
776
refs_ref_exists(get_main_ref_store(the_repository),
777
ref.buf);
778
strbuf_release(&ref);
@@ -869,7 +869,7 @@ static int add(int ac, const char **av, const char *prefix,
869
new_branch = new_branch_force;
870
871
if (!opts.force &&
872
- !check_branch_ref(&symref, new_branch) &&
872
+ !check_branch_ref(the_repository, &symref, new_branch) &&
873
refs_ref_exists(get_main_ref_store(the_repository), symref.buf))
874
die_if_checked_out(symref.buf, 0);
875
strbuf_release(&symref);
refs.c
+9
-14
@@ -2,8 +2,6 @@
2
* The backend-independent part of the reference module.
3
*/
4
5
-#define USE_THE_REPOSITORY_VARIABLE
6
-
5
#include "git-compat-util.h"
6
#include "abspath.h"
7
#include "advice.h"
@@ -744,14 +742,15 @@ static char *substitute_branch_name(struct repository *r,
742
return NULL;
743
}
744
747
-void copy_branchname(struct strbuf *sb, const char *name,
745
+void copy_branchname(struct repository *repo,
746
+ struct strbuf *sb, const char *name,
747
enum interpret_branch_kind allowed)
748
{
749
int len = strlen(name);
750
struct interpret_branch_name_options options = {
751
.allowed = allowed
752
};
754
- int used = repo_interpret_branch_name(the_repository, name, len, sb,
753
+ int used = repo_interpret_branch_name(repo, name, len, sb,
754
&options);
755
756
if (used < 0)
@@ -759,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,
758
strbuf_add(sb, name + used, len - used);
759
}
760
762
-int check_branch_ref(struct strbuf *sb, const char *name)
761
+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)
762
{
763
if (startup_info->have_repository)
765
- copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
764
+ copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);
765
else
766
strbuf_addstr(sb, name);
767
@@ -3326,9 +3325,9 @@ done:
3325
return ret;
3326
}
3327
3329
-static int has_worktrees(void)
3328
+static int has_worktrees(struct repository *repo)
3329
{
3331
- struct worktree **worktrees = get_worktrees(the_repository);
3330
+ struct worktree **worktrees = get_worktrees(repo);
3331
int ret = 0;
3332
size_t i;
3333
@@ -3373,12 +3372,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
3372
* Worktrees complicate the migration because every worktree has a
3373
* separate ref storage. While it should be feasible to implement, this
3374
* is pushed out to a future iteration.
3376
- *
3377
- * TODO: we should really be passing the caller-provided repository to
3378
- * `has_worktrees()`, but our worktree subsystem doesn't yet support
3379
- * that.
3375
*/
3381
- if (has_worktrees()) {
3376
+ if (has_worktrees(repo)) {
3377
strbuf_addstr(errbuf, "migrating repositories with worktrees is not supported yet");
3378
ret = -1;
3379
goto done;
@@ -3503,7 +3498,7 @@ int repo_migrate_ref_storage_format(struct repository *repo,
3498
* repository format so that clients will use the new ref store.
3499
* We also need to swap out the repository's main ref store.
3500
*/
3506
- initialize_repository_version(the_repository, hash_algo_by_ptr(repo->hash_algo), format, 1);
3501
+ initialize_repository_version(repo, hash_algo_by_ptr(repo->hash_algo), format, 1);
3502
3503
/*
3504
* Unset the old ref store and release it. `get_main_ref_store()` will
refs.h
+3
-2
@@ -234,7 +234,8 @@ char *repo_default_branch_name(struct repository *r, int quiet);
234
* If "allowed" is non-zero, restrict the set of allowed expansions. See
235
* repo_interpret_branch_name() for details.
236
*/
237
-void copy_branchname(struct strbuf *sb, const char *name,
237
+void copy_branchname(struct repository *repo,
238
+ struct strbuf *sb, const char *name,
239
enum interpret_branch_kind allowed);
240
241
/*
@@ -243,7 +244,7 @@ void copy_branchname(struct strbuf *sb, const char *name,
244
*
245
* The return value is "0" if the result is valid, and "-1" otherwise.
246
*/
246
-int check_branch_ref(struct strbuf *sb, const char *name);
247
+int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name);
248
249
/*
250
* Similar for a tag name in refs/tags/.