refs: drop strbuf_ prefix from helpers
The helper functions (strbuf_branchname, strbuf_check_branch_ref, and strbuf_check_tag_ref) are about handling branch and tag names, and it is a non-essential fact that these functions use strbuf to hold these names. Rename them to make it clarify that these are more about "ref". Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5bcbde9e49
commit
93e5e048f8
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 (strbuf_check_branch_ref(ref, name)) {
|
if (check_branch_ref(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 `man git check-ref-format`"));
|
_("See `man git check-ref-format`"));
|
||||||
|
@ -257,7 +257,7 @@ 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;
|
||||||
|
|
||||||
strbuf_branchname(&bname, argv[i], allowed_interpret);
|
copy_branchname(&bname, argv[i], allowed_interpret);
|
||||||
free(name);
|
free(name);
|
||||||
name = mkpathdup(fmt, bname.buf);
|
name = mkpathdup(fmt, bname.buf);
|
||||||
|
|
||||||
@ -579,7 +579,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();
|
struct worktree **worktrees = get_worktrees();
|
||||||
|
|
||||||
if (strbuf_check_branch_ref(&oldref, oldname)) {
|
if (check_branch_ref(&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.
|
||||||
@ -894,7 +894,7 @@ 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) {
|
||||||
strbuf_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
|
copy_branchname(&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"));
|
||||||
@ -933,7 +933,7 @@ 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) {
|
||||||
strbuf_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
|
copy_branchname(&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"));
|
||||||
@ -963,7 +963,7 @@ 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) {
|
||||||
strbuf_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
|
copy_branchname(&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"));
|
||||||
|
@ -42,7 +42,7 @@ static int check_ref_format_branch(const char *arg)
|
|||||||
int nongit;
|
int nongit;
|
||||||
|
|
||||||
setup_git_directory_gently(&nongit);
|
setup_git_directory_gently(&nongit);
|
||||||
if (strbuf_check_branch_ref(&sb, arg) ||
|
if (check_branch_ref(&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);
|
||||||
|
@ -742,7 +742,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);
|
||||||
|
|
||||||
strbuf_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
|
copy_branchname(&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);
|
||||||
|
@ -498,7 +498,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;
|
||||||
|
|
||||||
strbuf_branchname(&bname, remote, 0);
|
copy_branchname(&bname, remote, 0);
|
||||||
remote = bname.buf;
|
remote = bname.buf;
|
||||||
|
|
||||||
oidclr(&branch_head, the_repository->hash_algo);
|
oidclr(&branch_head, the_repository->hash_algo);
|
||||||
|
@ -639,7 +639,7 @@ int cmd_tag(int argc,
|
|||||||
if (repo_get_oid(the_repository, object_ref, &object))
|
if (repo_get_oid(the_repository, object_ref, &object))
|
||||||
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
|
die(_("Failed to resolve '%s' as a valid ref."), object_ref);
|
||||||
|
|
||||||
if (strbuf_check_tag_ref(&ref, tag))
|
if (check_tag_ref(&ref, tag))
|
||||||
die(_("'%s' is not a valid tag name."), tag);
|
die(_("'%s' is not a valid tag name."), tag);
|
||||||
|
|
||||||
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
|
if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
|
||||||
|
@ -432,7 +432,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 && !strbuf_check_branch_ref(&symref, refname) &&
|
if (!opts->detach && !check_branch_ref(&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)
|
||||||
@ -604,7 +604,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 && !strbuf_check_branch_ref(&s, branch) &&
|
if (!detach && !check_branch_ref(&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);
|
||||||
@ -745,7 +745,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 = !strbuf_check_branch_ref(&ref, branchname) &&
|
branch_exists = !check_branch_ref(&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);
|
||||||
@ -838,7 +838,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 &&
|
||||||
!strbuf_check_branch_ref(&symref, new_branch) &&
|
!check_branch_ref(&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);
|
||||||
|
@ -2094,7 +2094,7 @@ sub format_log_line_html {
|
|||||||
(
|
(
|
||||||
# The output of "git describe", e.g. v2.10.0-297-gf6727b0
|
# The output of "git describe", e.g. v2.10.0-297-gf6727b0
|
||||||
# or hadoop-20160921-113441-20-g094fb7d
|
# or hadoop-20160921-113441-20-g094fb7d
|
||||||
(?<!-) # see strbuf_check_tag_ref(). Tags can't start with -
|
(?<!-) # see check_tag_ref(). Tags can't start with -
|
||||||
[A-Za-z0-9.-]+
|
[A-Za-z0-9.-]+
|
||||||
(?!\.) # refs can't end with ".", see check_refname_format()
|
(?!\.) # refs can't end with ".", see check_refname_format()
|
||||||
-g$regex
|
-g$regex
|
||||||
|
8
refs.c
8
refs.c
@ -697,7 +697,7 @@ static char *substitute_branch_name(struct repository *r,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void strbuf_branchname(struct strbuf *sb, const char *name, unsigned allowed)
|
void copy_branchname(struct strbuf *sb, const char *name, unsigned allowed)
|
||||||
{
|
{
|
||||||
int len = strlen(name);
|
int len = strlen(name);
|
||||||
struct interpret_branch_name_options options = {
|
struct interpret_branch_name_options options = {
|
||||||
@ -711,10 +711,10 @@ void strbuf_branchname(struct strbuf *sb, const char *name, unsigned allowed)
|
|||||||
strbuf_add(sb, name + used, len - used);
|
strbuf_add(sb, name + used, len - used);
|
||||||
}
|
}
|
||||||
|
|
||||||
int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
|
int check_branch_ref(struct strbuf *sb, const char *name)
|
||||||
{
|
{
|
||||||
if (startup_info->have_repository)
|
if (startup_info->have_repository)
|
||||||
strbuf_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
|
copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
|
||||||
else
|
else
|
||||||
strbuf_addstr(sb, name);
|
strbuf_addstr(sb, name);
|
||||||
|
|
||||||
@ -733,7 +733,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
|
|||||||
return check_refname_format(sb->buf, 0);
|
return check_refname_format(sb->buf, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
|
int check_tag_ref(struct strbuf *sb, const char *name)
|
||||||
{
|
{
|
||||||
if (name[0] == '-')
|
if (name[0] == '-')
|
||||||
return -1;
|
return -1;
|
||||||
|
8
refs.h
8
refs.h
@ -191,23 +191,23 @@ 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 strbuf_branchname(struct strbuf *sb, const char *name,
|
void copy_branchname(struct strbuf *sb, const char *name,
|
||||||
unsigned allowed);
|
unsigned allowed);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Like strbuf_branchname() above, but confirm that the result is
|
* Like copy_branchname() above, but confirm that the result is
|
||||||
* syntactically valid to be used as a local branch name in refs/heads/.
|
* syntactically valid to be used as a local branch name in refs/heads/.
|
||||||
*
|
*
|
||||||
* 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 strbuf_check_branch_ref(struct strbuf *sb, const char *name);
|
int check_branch_ref(struct strbuf *sb, const char *name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Similar for a tag name in refs/tags/.
|
* Similar for a tag name in refs/tags/.
|
||||||
*
|
*
|
||||||
* 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 strbuf_check_tag_ref(struct strbuf *sb, const char *name);
|
int check_tag_ref(struct strbuf *sb, const char *name);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A ref_transaction represents a collection of reference updates that
|
* A ref_transaction represents a collection of reference updates that
|
||||||
|
Loading…
Reference in New Issue
Block a user