aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-01-01 22:33:20 -0800
committerJunio C Hamano <gitster@pobox.com>2008-01-02 02:28:54 -0800
commit5f7b202a7fa8ffbf076c456106750b2bb7732ba4 (patch)
tree0acba82e3731e1fa1a28dda325d6b48a7da78dbb /refs.c
parent49b9362fd35d45dc94ea15006c4bb88671b8da7d (diff)
downloadgit-5f7b202a7fa8ffbf076c456106750b2bb7732ba4.tar.gz
git-5f7b202a7fa8ffbf076c456106750b2bb7732ba4.tar.xz
lock_any_ref_for_update(): reject wildcard return from check_ref_format
Recent check_ref_format() returns -3 as well as -1 (general error) and -2 (less than two levels). The caller was explicitly checking for -1, to allow "HEAD" but still needed to disallow bogus refs. This introduces symbolic constants for the return values from check_ref_format() to make them read better and more meaningful. Normal ref creation codepath can still treat non-zero return values as errors. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/refs.c b/refs.c
index 759924d0c..7484a46d6 100644
--- a/refs.c
+++ b/refs.c
@@ -613,32 +613,37 @@ int check_ref_format(const char *ref)
while ((ch = *cp++) == '/')
; /* tolerate duplicated slashes */
if (!ch)
- return -1; /* should not end with slashes */
+ /* should not end with slashes */
+ return CHECK_REF_FORMAT_ERROR;
/* we are at the beginning of the path component */
if (ch == '.')
- return -1;
+ return CHECK_REF_FORMAT_ERROR;
bad_type = bad_ref_char(ch);
if (bad_type) {
- return (bad_type == 2 && !*cp) ? -3 : -1;
+ return (bad_type == 2 && !*cp)
+ ? CHECK_REF_FORMAT_WILDCARD
+ : CHECK_REF_FORMAT_ERROR;
}
/* scan the rest of the path component */
while ((ch = *cp++) != 0) {
bad_type = bad_ref_char(ch);
if (bad_type) {
- return (bad_type == 2 && !*cp) ? -3 : -1;
+ return (bad_type == 2 && !*cp)
+ ? CHECK_REF_FORMAT_WILDCARD
+ : CHECK_REF_FORMAT_ERROR;
}
if (ch == '/')
break;
if (ch == '.' && *cp == '.')
- return -1;
+ return CHECK_REF_FORMAT_ERROR;
}
level++;
if (!ch) {
if (level < 2)
- return -2; /* at least of form "heads/blah" */
- return 0;
+ return CHECK_REF_FORMAT_ONELEVEL;
+ return CHECK_REF_FORMAT_OK;
}
}
}
@@ -816,9 +821,13 @@ struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1, int flags)
{
- if (check_ref_format(ref) == -1)
+ switch (check_ref_format(ref)) {
+ case CHECK_REF_FORMAT_ERROR:
+ case CHECK_REF_FORMAT_WILDCARD:
return NULL;
- return lock_ref_sha1_basic(ref, old_sha1, flags, NULL);
+ default:
+ return lock_ref_sha1_basic(ref, old_sha1, flags, NULL);
+ }
}
static struct lock_file packlock;