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>main
parent
e2533e0915
commit
b1296cb1aa
2
branch.c
2
branch.c
|
|
@ -372,7 +372,7 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
|
||||||
*/
|
*/
|
||||||
int validate_branchname(const char *name, struct strbuf *ref)
|
int validate_branchname(const char *name, struct strbuf *ref)
|
||||||
{
|
{
|
||||||
if (check_branch_ref(ref, name)) {
|
if (check_branch_ref(the_repository, ref, name)) {
|
||||||
int code = die_message(_("'%s' is not a valid branch name"), name);
|
int code = die_message(_("'%s' is not a valid branch name"), name);
|
||||||
advise_if_enabled(ADVICE_REF_SYNTAX,
|
advise_if_enabled(ADVICE_REF_SYNTAX,
|
||||||
_("See 'git help check-ref-format'"));
|
_("See 'git help check-ref-format'"));
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
|
||||||
char *target = NULL;
|
char *target = NULL;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
copy_branchname(&bname, argv[i], allowed_interpret);
|
copy_branchname(the_repository, &bname,
|
||||||
|
argv[i], allowed_interpret);
|
||||||
free(name);
|
free(name);
|
||||||
name = mkpathdup(fmt, bname.buf);
|
name = mkpathdup(fmt, bname.buf);
|
||||||
|
|
||||||
|
|
@ -581,7 +582,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
|
||||||
int recovery = 0, oldref_usage = 0;
|
int recovery = 0, oldref_usage = 0;
|
||||||
struct worktree **worktrees = get_worktrees(the_repository);
|
struct worktree **worktrees = get_worktrees(the_repository);
|
||||||
|
|
||||||
if (check_branch_ref(&oldref, oldname)) {
|
if (check_branch_ref(the_repository, &oldref, oldname)) {
|
||||||
/*
|
/*
|
||||||
* Bad name --- this could be an attempt to rename a
|
* Bad name --- this could be an attempt to rename a
|
||||||
* ref that we used to allow to be created by accident.
|
* ref that we used to allow to be created by accident.
|
||||||
|
|
@ -898,7 +899,8 @@ int cmd_branch(int argc,
|
||||||
die(_("cannot give description to detached HEAD"));
|
die(_("cannot give description to detached HEAD"));
|
||||||
branch_name = head;
|
branch_name = head;
|
||||||
} else if (argc == 1) {
|
} else if (argc == 1) {
|
||||||
copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
|
copy_branchname(the_repository, &buf, argv[0],
|
||||||
|
INTERPRET_BRANCH_LOCAL);
|
||||||
branch_name = buf.buf;
|
branch_name = buf.buf;
|
||||||
} else {
|
} else {
|
||||||
die(_("cannot edit description of more than one branch"));
|
die(_("cannot edit description of more than one branch"));
|
||||||
|
|
@ -941,7 +943,8 @@ int cmd_branch(int argc,
|
||||||
if (!argc)
|
if (!argc)
|
||||||
branch = branch_get(NULL);
|
branch = branch_get(NULL);
|
||||||
else if (argc == 1) {
|
else if (argc == 1) {
|
||||||
copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
|
copy_branchname(the_repository, &buf, argv[0],
|
||||||
|
INTERPRET_BRANCH_LOCAL);
|
||||||
branch = branch_get(buf.buf);
|
branch = branch_get(buf.buf);
|
||||||
} else
|
} else
|
||||||
die(_("too many arguments to set new upstream"));
|
die(_("too many arguments to set new upstream"));
|
||||||
|
|
@ -971,7 +974,8 @@ int cmd_branch(int argc,
|
||||||
if (!argc)
|
if (!argc)
|
||||||
branch = branch_get(NULL);
|
branch = branch_get(NULL);
|
||||||
else if (argc == 1) {
|
else if (argc == 1) {
|
||||||
copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
|
copy_branchname(the_repository, &buf, argv[0],
|
||||||
|
INTERPRET_BRANCH_LOCAL);
|
||||||
branch = branch_get(buf.buf);
|
branch = branch_get(buf.buf);
|
||||||
} else
|
} else
|
||||||
die(_("too many arguments to unset upstream"));
|
die(_("too many arguments to unset upstream"));
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ static int check_ref_format_branch(const char *arg)
|
||||||
int nongit;
|
int nongit;
|
||||||
|
|
||||||
setup_git_directory_gently(the_repository, &nongit);
|
setup_git_directory_gently(the_repository, &nongit);
|
||||||
if (check_branch_ref(&sb, arg) ||
|
if (check_branch_ref(the_repository, &sb, arg) ||
|
||||||
!skip_prefix(sb.buf, "refs/heads/", &name))
|
!skip_prefix(sb.buf, "refs/heads/", &name))
|
||||||
die("'%s' is not a valid branch name", arg);
|
die("'%s' is not a valid branch name", arg);
|
||||||
printf("%s\n", name);
|
printf("%s\n", name);
|
||||||
|
|
|
||||||
|
|
@ -805,7 +805,7 @@ static void setup_branch_path(struct branch_info *branch)
|
||||||
&branch->oid, &branch->refname, 0))
|
&branch->oid, &branch->refname, 0))
|
||||||
repo_get_oid_committish(the_repository, branch->name, &branch->oid);
|
repo_get_oid_committish(the_repository, branch->name, &branch->oid);
|
||||||
|
|
||||||
copy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
|
copy_branchname(the_repository, &buf, branch->name, INTERPRET_BRANCH_LOCAL);
|
||||||
if (strcmp(buf.buf, branch->name)) {
|
if (strcmp(buf.buf, branch->name)) {
|
||||||
free(branch->name);
|
free(branch->name);
|
||||||
branch->name = xstrdup(buf.buf);
|
branch->name = xstrdup(buf.buf);
|
||||||
|
|
|
||||||
|
|
@ -553,7 +553,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
|
||||||
char *found_ref = NULL;
|
char *found_ref = NULL;
|
||||||
int len, early;
|
int len, early;
|
||||||
|
|
||||||
copy_branchname(&bname, remote, 0);
|
copy_branchname(the_repository, &bname, remote, 0);
|
||||||
remote = bname.buf;
|
remote = bname.buf;
|
||||||
|
|
||||||
oidclr(&branch_head, the_repository->hash_algo);
|
oidclr(&branch_head, the_repository->hash_algo);
|
||||||
|
|
|
||||||
|
|
@ -481,7 +481,7 @@ static int add_worktree(const char *path, const char *refname,
|
||||||
worktrees = NULL;
|
worktrees = NULL;
|
||||||
|
|
||||||
/* is 'refname' a branch or commit? */
|
/* is 'refname' a branch or commit? */
|
||||||
if (!opts->detach && !check_branch_ref(&symref, refname) &&
|
if (!opts->detach && !check_branch_ref(the_repository, &symref, refname) &&
|
||||||
refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {
|
refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {
|
||||||
is_branch = 1;
|
is_branch = 1;
|
||||||
if (!opts->force)
|
if (!opts->force)
|
||||||
|
|
@ -650,7 +650,7 @@ static void print_preparing_worktree_line(int detach,
|
||||||
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
|
fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
|
||||||
} else {
|
} else {
|
||||||
struct strbuf s = STRBUF_INIT;
|
struct strbuf s = STRBUF_INIT;
|
||||||
if (!detach && !check_branch_ref(&s, branch) &&
|
if (!detach && !check_branch_ref(the_repository, &s, branch) &&
|
||||||
refs_ref_exists(get_main_ref_store(the_repository), s.buf))
|
refs_ref_exists(get_main_ref_store(the_repository), s.buf))
|
||||||
fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
|
fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
|
||||||
branch);
|
branch);
|
||||||
|
|
@ -772,7 +772,7 @@ static char *dwim_branch(const char *path, char **new_branch)
|
||||||
char *branchname = xstrndup(s, n);
|
char *branchname = xstrndup(s, n);
|
||||||
struct strbuf ref = STRBUF_INIT;
|
struct strbuf ref = STRBUF_INIT;
|
||||||
|
|
||||||
branch_exists = !check_branch_ref(&ref, branchname) &&
|
branch_exists = !check_branch_ref(the_repository, &ref, branchname) &&
|
||||||
refs_ref_exists(get_main_ref_store(the_repository),
|
refs_ref_exists(get_main_ref_store(the_repository),
|
||||||
ref.buf);
|
ref.buf);
|
||||||
strbuf_release(&ref);
|
strbuf_release(&ref);
|
||||||
|
|
@ -869,7 +869,7 @@ static int add(int ac, const char **av, const char *prefix,
|
||||||
new_branch = new_branch_force;
|
new_branch = new_branch_force;
|
||||||
|
|
||||||
if (!opts.force &&
|
if (!opts.force &&
|
||||||
!check_branch_ref(&symref, new_branch) &&
|
!check_branch_ref(the_repository, &symref, new_branch) &&
|
||||||
refs_ref_exists(get_main_ref_store(the_repository), symref.buf))
|
refs_ref_exists(get_main_ref_store(the_repository), symref.buf))
|
||||||
die_if_checked_out(symref.buf, 0);
|
die_if_checked_out(symref.buf, 0);
|
||||||
strbuf_release(&symref);
|
strbuf_release(&symref);
|
||||||
|
|
|
||||||
23
refs.c
23
refs.c
|
|
@ -2,8 +2,6 @@
|
||||||
* The backend-independent part of the reference module.
|
* The backend-independent part of the reference module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define USE_THE_REPOSITORY_VARIABLE
|
|
||||||
|
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include "abspath.h"
|
#include "abspath.h"
|
||||||
#include "advice.h"
|
#include "advice.h"
|
||||||
|
|
@ -744,14 +742,15 @@ static char *substitute_branch_name(struct repository *r,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void copy_branchname(struct strbuf *sb, const char *name,
|
void copy_branchname(struct repository *repo,
|
||||||
|
struct strbuf *sb, const char *name,
|
||||||
enum interpret_branch_kind allowed)
|
enum interpret_branch_kind allowed)
|
||||||
{
|
{
|
||||||
int len = strlen(name);
|
int len = strlen(name);
|
||||||
struct interpret_branch_name_options options = {
|
struct interpret_branch_name_options options = {
|
||||||
.allowed = allowed
|
.allowed = allowed
|
||||||
};
|
};
|
||||||
int used = repo_interpret_branch_name(the_repository, name, len, sb,
|
int used = repo_interpret_branch_name(repo, name, len, sb,
|
||||||
&options);
|
&options);
|
||||||
|
|
||||||
if (used < 0)
|
if (used < 0)
|
||||||
|
|
@ -759,10 +758,10 @@ void copy_branchname(struct strbuf *sb, const char *name,
|
||||||
strbuf_add(sb, name + used, len - used);
|
strbuf_add(sb, name + used, len - used);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_branch_ref(struct strbuf *sb, const char *name)
|
int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name)
|
||||||
{
|
{
|
||||||
if (startup_info->have_repository)
|
if (startup_info->have_repository)
|
||||||
copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
|
copy_branchname(repo, sb, name, INTERPRET_BRANCH_LOCAL);
|
||||||
else
|
else
|
||||||
strbuf_addstr(sb, name);
|
strbuf_addstr(sb, name);
|
||||||
|
|
||||||
|
|
@ -3326,9 +3325,9 @@ done:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int has_worktrees(void)
|
static int has_worktrees(struct repository *repo)
|
||||||
{
|
{
|
||||||
struct worktree **worktrees = get_worktrees(the_repository);
|
struct worktree **worktrees = get_worktrees(repo);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
|
@ -3373,12 +3372,8 @@ int repo_migrate_ref_storage_format(struct repository *repo,
|
||||||
* Worktrees complicate the migration because every worktree has a
|
* Worktrees complicate the migration because every worktree has a
|
||||||
* separate ref storage. While it should be feasible to implement, this
|
* separate ref storage. While it should be feasible to implement, this
|
||||||
* is pushed out to a future iteration.
|
* is pushed out to a future iteration.
|
||||||
*
|
|
||||||
* TODO: we should really be passing the caller-provided repository to
|
|
||||||
* `has_worktrees()`, but our worktree subsystem doesn't yet support
|
|
||||||
* that.
|
|
||||||
*/
|
*/
|
||||||
if (has_worktrees()) {
|
if (has_worktrees(repo)) {
|
||||||
strbuf_addstr(errbuf, "migrating repositories with worktrees is not supported yet");
|
strbuf_addstr(errbuf, "migrating repositories with worktrees is not supported yet");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -3503,7 +3498,7 @@ int repo_migrate_ref_storage_format(struct repository *repo,
|
||||||
* repository format so that clients will use the new ref store.
|
* repository format so that clients will use the new ref store.
|
||||||
* We also need to swap out the repository's main ref store.
|
* We also need to swap out the repository's main ref store.
|
||||||
*/
|
*/
|
||||||
initialize_repository_version(the_repository, hash_algo_by_ptr(repo->hash_algo), format, 1);
|
initialize_repository_version(repo, hash_algo_by_ptr(repo->hash_algo), format, 1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unset the old ref store and release it. `get_main_ref_store()` will
|
* Unset the old ref store and release it. `get_main_ref_store()` will
|
||||||
|
|
|
||||||
5
refs.h
5
refs.h
|
|
@ -234,7 +234,8 @@ char *repo_default_branch_name(struct repository *r, int quiet);
|
||||||
* If "allowed" is non-zero, restrict the set of allowed expansions. See
|
* If "allowed" is non-zero, restrict the set of allowed expansions. See
|
||||||
* repo_interpret_branch_name() for details.
|
* repo_interpret_branch_name() for details.
|
||||||
*/
|
*/
|
||||||
void copy_branchname(struct strbuf *sb, const char *name,
|
void copy_branchname(struct repository *repo,
|
||||||
|
struct strbuf *sb, const char *name,
|
||||||
enum interpret_branch_kind allowed);
|
enum interpret_branch_kind allowed);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -243,7 +244,7 @@ void copy_branchname(struct strbuf *sb, const char *name,
|
||||||
*
|
*
|
||||||
* The return value is "0" if the result is valid, and "-1" otherwise.
|
* The return value is "0" if the result is valid, and "-1" otherwise.
|
||||||
*/
|
*/
|
||||||
int check_branch_ref(struct strbuf *sb, const char *name);
|
int check_branch_ref(struct repository *repo, struct strbuf *sb, const char *name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Similar for a tag name in refs/tags/.
|
* Similar for a tag name in refs/tags/.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue