Change bad_ref_char() to return a boolean value
Previously most bad characters were indicated by returning 1, but "*" was special-cased to return 2 instead of 1. One caller examined the return value to see whether the special case occurred. But it is easier (to document and understand) for bad_ref_char() simply to return a boolean value, treating "*" like any other bad character. Special-case the handling of "*" (which only occurs in very specific circumstances) at the caller. The resulting calling code thereby also becomes more transparent. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 15, 2011 at 23:10 UTC
9224b73be03845a99f8171c57dc282f806b70f4c
1 file changed
+6
-9
refs.c
+6
-9
@@ -860,22 +860,21 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
860
* - it contains a "\" (backslash)
861
*/
862
863
+/* Return true iff ch is not allowed in reference names. */
864
static inline int bad_ref_char(int ch)
865
{
866
if (((unsigned) ch) <= ' ' || ch == 0x7f ||
867
ch == '~' || ch == '^' || ch == ':' || ch == '\\')
868
return 1;
869
/* 2.13 Pattern Matching Notation */
869
- if (ch == '?' || ch == '[') /* Unsupported */
870
+ if (ch == '*' || ch == '?' || ch == '[') /* Unsupported */
871
return 1;
871
- if (ch == '*') /* Supported at the end */
872
- return 2;
872
return 0;
873
}
874
875
int check_ref_format(const char *ref)
876
{
878
- int ch, level, bad_type, last;
877
+ int ch, level, last;
878
int ret = CHECK_REF_FORMAT_OK;
879
const char *cp = ref;
880
@@ -890,9 +889,8 @@ int check_ref_format(const char *ref)
889
/* we are at the beginning of the path component */
890
if (ch == '.')
891
return CHECK_REF_FORMAT_ERROR;
893
- bad_type = bad_ref_char(ch);
894
- if (bad_type) {
895
- if (bad_type == 2 && (!*cp || *cp == '/') &&
892
+ if (bad_ref_char(ch)) {
893
+ if (ch == '*' && (!*cp || *cp == '/') &&
894
ret == CHECK_REF_FORMAT_OK)
895
ret = CHECK_REF_FORMAT_WILDCARD;
896
else
@@ -902,8 +900,7 @@ int check_ref_format(const char *ref)
900
last = ch;
901
/* scan the rest of the path component */
902
while ((ch = *cp++) != 0) {
905
- bad_type = bad_ref_char(ch);
906
- if (bad_type)
903
+ if (bad_ref_char(ch))
904
return CHECK_REF_FORMAT_ERROR;
905
if (ch == '/')
906
break;