Code

git-send-email.txt: clarify which options take an argument.
[git.git] / refs.c
diff --git a/refs.c b/refs.c
index aeef257ee3cadfe751628f4157a4d63d77237090..59c373fc6d315aacfc3b1a0cecce0ceb4b65d72f 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -676,6 +676,7 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
  * - it has double dots "..", or
  * - it has ASCII control character, "~", "^", ":" or SP, anywhere, or
  * - it ends with a "/".
+ * - it ends with ".lock"
  */
 
 static inline int bad_ref_char(int ch)
@@ -693,7 +694,7 @@ static inline int bad_ref_char(int ch)
 
 int check_ref_format(const char *ref)
 {
-       int ch, level, bad_type;
+       int ch, level, bad_type, last;
        int ret = CHECK_REF_FORMAT_OK;
        const char *cp = ref;
 
@@ -717,26 +718,43 @@ int check_ref_format(const char *ref)
                                return CHECK_REF_FORMAT_ERROR;
                }
 
+               last = ch;
                /* scan the rest of the path component */
                while ((ch = *cp++) != 0) {
                        bad_type = bad_ref_char(ch);
-                       if (bad_type) {
+                       if (bad_type)
                                return CHECK_REF_FORMAT_ERROR;
-                       }
                        if (ch == '/')
                                break;
-                       if (ch == '.' && *cp == '.')
+                       if (last == '.' && ch == '.')
+                               return CHECK_REF_FORMAT_ERROR;
+                       if (last == '@' && ch == '{')
                                return CHECK_REF_FORMAT_ERROR;
+                       last = ch;
                }
                level++;
                if (!ch) {
+                       if (ref <= cp - 2 && cp[-2] == '.')
+                               return CHECK_REF_FORMAT_ERROR;
                        if (level < 2)
                                return CHECK_REF_FORMAT_ONELEVEL;
+                       if (has_extension(ref, ".lock"))
+                               return CHECK_REF_FORMAT_ERROR;
                        return ret;
                }
        }
 }
 
+const char *prettify_ref(const struct ref *ref)
+{
+       const char *name = ref->name;
+       return name + (
+               !prefixcmp(name, "refs/heads/") ? 11 :
+               !prefixcmp(name, "refs/tags/") ? 10 :
+               !prefixcmp(name, "refs/remotes/") ? 13 :
+               0);
+}
+
 const char *ref_rev_parse_rules[] = {
        "%.*s",
        "refs/%.*s",