check_refname_component(): return 0 for zero-length components

Return 0 (instead of -1) for zero-length components. Move the interpretation of zero-length components as illegal to check_refname_format(). This will make it easier to extend check_refname_format() to also check whether directory names are valid. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Apr 10, 2012 at 07:30 UTC dac529e44fb9e8c0ee4628c0f947db8890950317
1 file changed +2 -2
refs.c
+2 -2
@@ -51,7 +51,7 @@ static int check_refname_component(const char *refname, int flags)
51 last = ch;
52 }
53 if (cp == refname)
54 - return -1; /* Component has zero length. */
54 + return 0; /* Component has zero length. */
55 if (refname[0] == '.') {
56 if (!(flags & REFNAME_DOT_COMPONENT))
57 return -1; /* Component starts with '.'. */
@@ -74,7 +74,7 @@ int check_refname_format(const char *refname, int flags)
74 while (1) {
75 /* We are at the start of a path component. */
76 component_len = check_refname_component(refname, flags);
77 - if (component_len < 0) {
77 + if (component_len <= 0) {
78 if ((flags & REFNAME_REFSPEC_PATTERN) &&
79 refname[0] == '*' &&
80 (refname[1] == '\0' || refname[1] == '/')) {