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>

Junio C Hamano committed Dec 3, 2024 at 11:32 UTC 93e5e048f84138a632b239632c9b45ae238cdf1c
10 files changed +23 -23
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 (strbuf_check_branch_ref(ref, name)) {
375 + if (check_branch_ref(ref, name)) {
376 int code = die_message(_("'%s' is not a valid branch name"), name);
377 advise_if_enabled(ADVICE_REF_SYNTAX,
378 _("See `man git check-ref-format`"));
builtin/branch.c
+5 -5
@@ -257,7 +257,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
257 char *target = NULL;
258 int flags = 0;
259
260 - strbuf_branchname(&bname, argv[i], allowed_interpret);
260 + copy_branchname(&bname, argv[i], allowed_interpret);
261 free(name);
262 name = mkpathdup(fmt, bname.buf);
263
@@ -579,7 +579,7 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
579 int recovery = 0, oldref_usage = 0;
580 struct worktree **worktrees = get_worktrees();
581
582 - if (strbuf_check_branch_ref(&oldref, oldname)) {
582 + if (check_branch_ref(&oldref, oldname)) {
583 /*
584 * Bad name --- this could be an attempt to rename a
585 * ref that we used to allow to be created by accident.
@@ -894,7 +894,7 @@ int cmd_branch(int argc,
894 die(_("cannot give description to detached HEAD"));
895 branch_name = head;
896 } else if (argc == 1) {
897 - strbuf_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
897 + copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
898 branch_name = buf.buf;
899 } else {
900 die(_("cannot edit description of more than one branch"));
@@ -933,7 +933,7 @@ int cmd_branch(int argc,
933 if (!argc)
934 branch = branch_get(NULL);
935 else if (argc == 1) {
936 - strbuf_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
936 + copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
937 branch = branch_get(buf.buf);
938 } else
939 die(_("too many arguments to set new upstream"));
@@ -963,7 +963,7 @@ int cmd_branch(int argc,
963 if (!argc)
964 branch = branch_get(NULL);
965 else if (argc == 1) {
966 - strbuf_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
966 + copy_branchname(&buf, argv[0], INTERPRET_BRANCH_LOCAL);
967 branch = branch_get(buf.buf);
968 } else
969 die(_("too many arguments to unset upstream"));
builtin/check-ref-format.c
+1 -1
@@ -42,7 +42,7 @@ static int check_ref_format_branch(const char *arg)
42 int nongit;
43
44 setup_git_directory_gently(&nongit);
45 - if (strbuf_check_branch_ref(&sb, arg) ||
45 + if (check_branch_ref(&sb, arg) ||
46 !skip_prefix(sb.buf, "refs/heads/", &name))
47 die("'%s' is not a valid branch name", arg);
48 printf("%s\n", name);
builtin/checkout.c
+1 -1
@@ -742,7 +742,7 @@ static void setup_branch_path(struct branch_info *branch)
742 &branch->oid, &branch->refname, 0))
743 repo_get_oid_committish(the_repository, branch->name, &branch->oid);
744
745 - strbuf_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
745 + copy_branchname(&buf, branch->name, INTERPRET_BRANCH_LOCAL);
746 if (strcmp(buf.buf, branch->name)) {
747 free(branch->name);
748 branch->name = xstrdup(buf.buf);
builtin/merge.c
+1 -1
@@ -498,7 +498,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
498 char *found_ref = NULL;
499 int len, early;
500
501 - strbuf_branchname(&bname, remote, 0);
501 + copy_branchname(&bname, remote, 0);
502 remote = bname.buf;
503
504 oidclr(&branch_head, the_repository->hash_algo);
builtin/tag.c
+1 -1
@@ -639,7 +639,7 @@ int cmd_tag(int argc,
639 if (repo_get_oid(the_repository, object_ref, &object))
640 die(_("Failed to resolve '%s' as a valid ref."), object_ref);
641
642 - if (strbuf_check_tag_ref(&ref, tag))
642 + if (check_tag_ref(&ref, tag))
643 die(_("'%s' is not a valid tag name."), tag);
644
645 if (refs_read_ref(get_main_ref_store(the_repository), ref.buf, &prev))
builtin/worktree.c
+4 -4
@@ -432,7 +432,7 @@ static int add_worktree(const char *path, const char *refname,
432 worktrees = NULL;
433
434 /* is 'refname' a branch or commit? */
435 - if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&
435 + if (!opts->detach && !check_branch_ref(&symref, refname) &&
436 refs_ref_exists(get_main_ref_store(the_repository), symref.buf)) {
437 is_branch = 1;
438 if (!opts->force)
@@ -604,7 +604,7 @@ static void print_preparing_worktree_line(int detach,
604 fprintf_ln(stderr, _("Preparing worktree (new branch '%s')"), new_branch);
605 } else {
606 struct strbuf s = STRBUF_INIT;
607 - if (!detach && !strbuf_check_branch_ref(&s, branch) &&
607 + if (!detach && !check_branch_ref(&s, branch) &&
608 refs_ref_exists(get_main_ref_store(the_repository), s.buf))
609 fprintf_ln(stderr, _("Preparing worktree (checking out '%s')"),
610 branch);
@@ -745,7 +745,7 @@ static char *dwim_branch(const char *path, char **new_branch)
745 char *branchname = xstrndup(s, n);
746 struct strbuf ref = STRBUF_INIT;
747
748 - branch_exists = !strbuf_check_branch_ref(&ref, branchname) &&
748 + branch_exists = !check_branch_ref(&ref, branchname) &&
749 refs_ref_exists(get_main_ref_store(the_repository),
750 ref.buf);
751 strbuf_release(&ref);
@@ -838,7 +838,7 @@ static int add(int ac, const char **av, const char *prefix)
838 new_branch = new_branch_force;
839
840 if (!opts.force &&
841 - !strbuf_check_branch_ref(&symref, new_branch) &&
841 + !check_branch_ref(&symref, new_branch) &&
842 refs_ref_exists(get_main_ref_store(the_repository), symref.buf))
843 die_if_checked_out(symref.buf, 0);
844 strbuf_release(&symref);
gitweb/gitweb.perl
+1 -1
@@ -2094,7 +2094,7 @@ sub format_log_line_html {
2094 (
2095 # The output of "git describe", e.g. v2.10.0-297-gf6727b0
2096 # or hadoop-20160921-113441-20-g094fb7d
2097 - (?<!-) # see strbuf_check_tag_ref(). Tags can't start with -
2097 + (?<!-) # see check_tag_ref(). Tags can't start with -
2098 [A-Za-z0-9.-]+
2099 (?!\.) # refs can't end with ".", see check_refname_format()
2100 -g$regex
refs.c
+4 -4
@@ -697,7 +697,7 @@ static char *substitute_branch_name(struct repository *r,
697 return NULL;
698 }
699
700 -void strbuf_branchname(struct strbuf *sb, const char *name, unsigned allowed)
700 +void copy_branchname(struct strbuf *sb, const char *name, unsigned allowed)
701 {
702 int len = strlen(name);
703 struct interpret_branch_name_options options = {
@@ -711,10 +711,10 @@ void strbuf_branchname(struct strbuf *sb, const char *name, unsigned allowed)
711 strbuf_add(sb, name + used, len - used);
712 }
713
714 -int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
714 +int check_branch_ref(struct strbuf *sb, const char *name)
715 {
716 if (startup_info->have_repository)
717 - strbuf_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
717 + copy_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
718 else
719 strbuf_addstr(sb, name);
720
@@ -733,7 +733,7 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
733 return check_refname_format(sb->buf, 0);
734 }
735
736 -int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
736 +int check_tag_ref(struct strbuf *sb, const char *name)
737 {
738 if (name[0] == '-')
739 return -1;
refs.h
+4 -4
@@ -191,23 +191,23 @@ char *repo_default_branch_name(struct repository *r, int quiet);
191 * If "allowed" is non-zero, restrict the set of allowed expansions. See
192 * repo_interpret_branch_name() for details.
193 */
194 -void strbuf_branchname(struct strbuf *sb, const char *name,
194 +void copy_branchname(struct strbuf *sb, const char *name,
195 unsigned allowed);
196
197 /*
198 - * Like strbuf_branchname() above, but confirm that the result is
198 + * Like copy_branchname() above, but confirm that the result is
199 * syntactically valid to be used as a local branch name in refs/heads/.
200 *
201 * The return value is "0" if the result is valid, and "-1" otherwise.
202 */
203 -int strbuf_check_branch_ref(struct strbuf *sb, const char *name);
203 +int check_branch_ref(struct strbuf *sb, const char *name);
204
205 /*
206 * Similar for a tag name in refs/tags/.
207 *
208 * The return value is "0" if the result is valid, and "-1" otherwise.
209 */
210 -int strbuf_check_tag_ref(struct strbuf *sb, const char *name);
210 +int check_tag_ref(struct strbuf *sb, const char *name);
211
212 /*
213 * A ref_transaction represents a collection of reference updates that