Skip to content

Commit d5853a4

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 79574fc commit d5853a4

8 files changed

Lines changed: 29 additions & 29 deletions

File tree

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
372372
*/
373373
int validate_branchname(const char *name, struct strbuf *ref)
374374
{
375-
if (check_branch_ref(ref, name)) {
375+
if (check_branch_ref(the_repository, ref, name)) {
376376
int code = die_message(_("'%s' is not a valid branch name"), name);
377377
advise_if_enabled(ADVICE_REF_SYNTAX,
378378
_("See 'git help check-ref-format'"));

builtin/branch.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
259259
char *target = NULL;
260260
int flags = 0;
261261

262-
copy_branchname(&bname, argv[i], allowed_interpret);
262+
copy_branchname(the_repository, &bname,
263+
argv[i], allowed_interpret);
263264
free(name);
264265
name = mkpathdup(fmt, bname.buf);
265266

@@ -581,7 +582,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
581582
int recovery = 0, oldref_usage = 0;
582583
struct worktree **worktrees = get_worktrees(the_repository);
583584

584-
if (check_branch_ref(&oldref, oldname)) {
585+
if (check_branch_ref(the_repository, &oldref, oldname)) {
585586
/*
586587
* Bad name --- this could be an attempt to rename a
587588
* ref that we used to allow to be created by accident.
@@ -898,7 +899,8 @@ int cmd_branch(int argc,
898899
die(_("cannot give description to detached HEAD"));
899900
branch_name = head;
900901
} 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);
902904
branch_name = buf.buf;
903905
} else {
904906
die(_("cannot edit description of more than one branch"));
@@ -941,7 +943,8 @@ int cmd_branch(int argc,
941943
if (!argc)
942944
branch = branch_get(NULL);
943945
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);
945948
branch = branch_get(buf.buf);
946949
} else
947950
die(_("too many arguments to set new upstream"));
@@ -971,7 +974,8 @@ int cmd_branch(int argc,
971974
if (!argc)
972975
branch = branch_get(NULL);
973976
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);
975979
branch = branch_get(buf.buf);
976980
} else
977981
die(_("too many arguments to unset upstream"));

builtin/check-ref-format.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int check_ref_format_branch(const char *arg)
4545
int nongit;
4646

4747
setup_git_directory_gently(the_repository, &nongit);
48-
if (check_branch_ref(&sb, arg) ||
48+
if (check_branch_ref(the_repository, &sb, arg) ||
4949
!skip_prefix(sb.buf, "refs/heads/", &name))
5050
die("'%s' is not a valid branch name", arg);
5151
printf("%s\n", name);

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ static void setup_branch_path(struct branch_info *branch)
805805
&branch->oid, &branch->refname, 0))
806806
repo_get_oid_committish(the_repository, branch->name, &branch->oid);
807807

808-
copy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
808+
copy_branchname(the_repository, &buf, branch->name, INTERPRET_BRANCH_LOCAL);
809809
if (strcmp(buf.buf, branch->name)) {
810810
free(branch->name);
811811
branch->name = xstrdup(buf.buf);

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
553553
char *found_ref = NULL;
554554
int len, early;
555555

556-
copy_branchname(&bname, remote, 0);
556+
copy_branchname(the_repository, &bname, remote, 0);
557557
remote = bname.buf;
558558

559559
oidclr(&branch_head, the_repository->hash_algo);

builtin/worktree.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static int add_worktree(const char *path, const char *refname,
481481
worktrees = NULL;
482482

483483
/* 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) &&
485485
refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {
486486
is_branch = 1;
487487
if (!opts->force)
@@ -650,7 +650,7 @@ static void print_preparing_worktree_line(int detach,
650650
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
651651
} else {
652652
struct strbuf s = STRBUF_INIT;
653-
if (!detach && !check_branch_ref(&s, branch) &&
653+
if (!detach && !check_branch_ref(the_repository, &s, branch) &&
654654
refs_ref_exists(get_main_ref_store(the_repository), s.buf))
655655
fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
656656
branch);
@@ -772,7 +772,7 @@ static char *dwim_branch(const char *path, char **new_branch)
772772
char *branchname = xstrndup(s, n);
773773
struct strbuf ref = STRBUF_INIT;
774774

775-
branch_exists = !check_branch_ref(&ref, branchname) &&
775+
branch_exists = !check_branch_ref(the_repository, &ref, branchname) &&
776776
refs_ref_exists(get_main_ref_store(the_repository),
777777
ref.buf);
778778
strbuf_release(&ref);
@@ -869,7 +869,7 @@ static int add(int ac, const char **av, const char *prefix,
869869
new_branch = new_branch_force;
870870

871871
if (!opts.force &&
872-
!check_branch_ref(&symref, new_branch) &&
872+
!check_branch_ref(the_repository, &symref, new_branch) &&
873873
refs_ref_exists(get_main_ref_store(the_repository), symref.buf))
874874
die_if_checked_out(symref.buf, 0);
875875
strbuf_release(&symref);

refs.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
* The backend-independent part of the reference module.
33
*/
44

5-
#define USE_THE_REPOSITORY_VARIABLE
6-
75
#include "git-compat-util.h"
86
#include "abspath.h"
97
#include "advice.h"
@@ -744,25 +742,26 @@ static char *substitute_branch_name(struct repository *r,
744742
return NULL;
745743
}
746744

747-
void copy_branchname(struct strbuf *sb, const char *name,
745+
void copy_branchname(struct repository *repo,
746+
struct strbuf *sb, const char *name,
748747
enum interpret_branch_kind allowed)
749748
{
750749
int len = strlen(name);
751750
struct interpret_branch_name_options options = {
752751
.allowed = allowed
753752
};
754-
int used = repo_interpret_branch_name(the_repository, name, len, sb,
753+
int used = repo_interpret_branch_name(repo, name, len, sb,
755754
&options);
756755

757756
if (used < 0)
758757
used = 0;
759758
strbuf_add(sb, name + used, len - used);
760759
}
761760

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)
763762
{
764763
if (startup_info->have_repository)
765-
copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
764+
copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);
766765
else
767766
strbuf_addstr(sb, name);
768767

@@ -3326,9 +3325,9 @@ static int move_files(const char *from_path, const char *to_path, struct strbuf
33263325
return ret;
33273326
}
33283327

3329-
static int has_worktrees(void)
3328+
static int has_worktrees(struct repository *repo)
33303329
{
3331-
struct worktree **worktrees = get_worktrees(the_repository);
3330+
struct worktree **worktrees = get_worktrees(repo);
33323331
int ret = 0;
33333332
size_t i;
33343333

@@ -3373,12 +3372,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
33733372
* Worktrees complicate the migration because every worktree has a
33743373
* separate ref storage. While it should be feasible to implement, this
33753374
* 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.
33803375
*/
3381-
if (has_worktrees()) {
3376+
if (has_worktrees(repo)) {
33823377
strbuf_addstr(errbuf, "migrating repositories with worktrees is not supported yet");
33833378
ret = -1;
33843379
goto done;
@@ -3503,7 +3498,7 @@ int repo_migrate_ref_storage_format(struct repository *repo,
35033498
* repository format so that clients will use the new ref store.
35043499
* We also need to swap out the repository's main ref store.
35053500
*/
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);
35073502

35083503
/*
35093504
* Unset the old ref store and release it. `get_main_ref_store()` will

refs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ char *repo_default_branch_name(struct repository *r, int quiet);
234234
* If "allowed" is non-zero, restrict the set of allowed expansions. See
235235
* repo_interpret_branch_name() for details.
236236
*/
237-
void copy_branchname(struct strbuf *sb, const char *name,
237+
void copy_branchname(struct repository *repo,
238+
struct strbuf *sb, const char *name,
238239
enum interpret_branch_kind allowed);
239240

240241
/*
@@ -243,7 +244,7 @@ void copy_branchname(struct strbuf *sb, const char *name,
243244
*
244245
* The return value is "0" if the result is valid, and "-1" otherwise.
245246
*/
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);
247248

248249
/*
249250
* Similar for a tag name in refs/tags/.

0 commit comments

Comments
 (0)