Skip to content

Commit 8d9c501

Browse files
mhaggergitster
authored andcommitted
Change check_ref_format() to take a flags argument
Change check_ref_format() to take a flags argument that indicates what is acceptable in the reference name (analogous to "git check-ref-format"'s "--allow-onelevel" and "--refspec-pattern"). This is more convenient for callers and also fixes a failure in the test suite (and likely elsewhere in the code) by enabling "onelevel" and "refspec-pattern" to be allowed independently of each other. Also rename check_ref_format() to check_refname_format() to make it obvious that it deals with refnames rather than references themselves. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9224b73 commit 8d9c501

File tree

20 files changed

+69
-126
lines changed

20 files changed

+69
-126
lines changed

builtin/check-ref-format.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ static void refname_format_print(const char *arg)
5353
printf("%s\n", refname);
5454
}
5555

56-
#define REFNAME_ALLOW_ONELEVEL 1
57-
#define REFNAME_REFSPEC_PATTERN 2
58-
5956
int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
6057
{
6158
int i;
@@ -83,24 +80,8 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
8380
if (! (i == argc - 1))
8481
usage(builtin_check_ref_format_usage);
8582

86-
switch (check_ref_format(argv[i])) {
87-
case CHECK_REF_FORMAT_OK:
88-
break;
89-
case CHECK_REF_FORMAT_ERROR:
83+
if (check_refname_format(argv[i], flags))
9084
return 1;
91-
case CHECK_REF_FORMAT_ONELEVEL:
92-
if (!(flags & REFNAME_ALLOW_ONELEVEL))
93-
return 1;
94-
else
95-
break;
96-
case CHECK_REF_FORMAT_WILDCARD:
97-
if (!(flags & REFNAME_REFSPEC_PATTERN))
98-
return 1;
99-
else
100-
break;
101-
default:
102-
die("internal error: unexpected value from check_ref_format()");
103-
}
10485

10586
if (print)
10687
refname_format_print(argv[i]);

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ static int parse_branchname_arg(int argc, const char **argv,
882882
new->name = arg;
883883
setup_branch_path(new);
884884

885-
if (check_ref_format(new->path) == CHECK_REF_FORMAT_OK &&
885+
if (!check_refname_format(new->path, 0) &&
886886
resolve_ref(new->path, branch_rev, 1, NULL))
887887
hashcpy(rev, branch_rev);
888888
else

builtin/fetch-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static void filter_refs(struct ref **refs, int nr_match, char **match)
544544
for (ref = *refs; ref; ref = next) {
545545
next = ref->next;
546546
if (!memcmp(ref->name, "refs/", 5) &&
547-
check_ref_format(ref->name + 5))
547+
check_refname_format(ref->name + 5, 0))
548548
; /* trash */
549549
else if (args.fetch_all &&
550550
(!args.depth || prefixcmp(ref->name, "refs/tags/") )) {

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static const char *update(struct command *cmd)
356356
struct ref_lock *lock;
357357

358358
/* only refs/... are allowed */
359-
if (prefixcmp(name, "refs/") || check_ref_format(name + 5)) {
359+
if (prefixcmp(name, "refs/") || check_refname_format(name + 5, 0)) {
360360
rp_error("refusing to create funny ref '%s' remotely", name);
361361
return "funny refname";
362362
}

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int replace_object(const char *object_ref, const char *replace_ref,
9494
"refs/replace/%s",
9595
sha1_to_hex(object)) > sizeof(ref) - 1)
9696
die("replace ref name too long: %.*s...", 50, ref);
97-
if (check_ref_format(ref))
97+
if (check_refname_format(ref, 0))
9898
die("'%s' is not a valid ref name.", ref);
9999

100100
if (!resolve_ref(ref, prev, 1, NULL))

builtin/show-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static int exclude_existing(const char *match)
145145
if (strncmp(ref, match, matchlen))
146146
continue;
147147
}
148-
if (check_ref_format(ref)) {
148+
if (check_refname_format(ref, 0)) {
149149
warning("ref '%s' ignored", ref);
150150
continue;
151151
}

builtin/tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
407407
static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
408408
{
409409
if (name[0] == '-')
410-
return CHECK_REF_FORMAT_ERROR;
410+
return -1;
411411

412412
strbuf_reset(sb);
413413
strbuf_addf(sb, "refs/tags/%s", name);
414414

415-
return check_ref_format(sb->buf);
415+
return check_refname_format(sb->buf, 0);
416416
}
417417

418418
int cmd_tag(int argc, const char **argv, const char *prefix)

connect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int check_ref(const char *name, int len, unsigned int flags)
2222
len -= 5;
2323

2424
/* REF_NORMAL means that we don't want the magic fake tag refs */
25-
if ((flags & REF_NORMAL) && check_ref_format(name) < 0)
25+
if ((flags & REF_NORMAL) && check_refname_format(name, 0))
2626
return 0;
2727

2828
/* REF_HEADS means that we want regular branch heads */

environment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static char *expand_namespace(const char *raw_namespace)
106106
if (strcmp((*c)->buf, "/") != 0)
107107
strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf);
108108
strbuf_list_free(components);
109-
if (check_ref_format(buf.buf) != CHECK_REF_FORMAT_OK)
109+
if (check_refname_format(buf.buf, 0))
110110
die("bad git namespace path \"%s\"", raw_namespace);
111111
strbuf_addch(&buf, '/');
112112
return strbuf_detach(&buf, NULL);

fast-import.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,8 @@ static struct branch *new_branch(const char *name)
722722

723723
if (b)
724724
die("Invalid attempt to create duplicate branch: %s", name);
725-
switch (check_ref_format(name)) {
726-
case 0: break; /* its valid */
727-
case CHECK_REF_FORMAT_ONELEVEL:
728-
break; /* valid, but too few '/', allow anyway */
729-
default:
725+
if (check_refname_format(name, REFNAME_ALLOW_ONELEVEL))
730726
die("Branch name doesn't conform to GIT standards: %s", name);
731-
}
732727

733728
b = pool_calloc(1, sizeof(struct branch));
734729
b->name = pool_strdup(name);

0 commit comments

Comments
 (0)