Code

gitweb: Fix test of highlighting support in t9500
[git.git] / strbuf.c
index 67448b7b07aa9d07b0c8cc250e3e0fad64c8fb5e..65b4cf43434a8b7327565d0e0f87d5378d098f99 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -10,6 +10,15 @@ int prefixcmp(const char *str, const char *prefix)
                        return (unsigned char)*prefix - (unsigned char)*str;
 }
 
+int suffixcmp(const char *str, const char *suffix)
+{
+       int len = strlen(str), suflen = strlen(suffix);
+       if (len < suflen)
+               return -1;
+       else
+               return strcmp(str + len - suflen, suffix);
+}
+
 /*
  * Used as the default ->buf value, so that people can always assume
  * buf is non NULL and ->buf is NUL terminated even for a freshly
@@ -390,6 +399,8 @@ int strbuf_branchname(struct strbuf *sb, const char *name)
 int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
 {
        strbuf_branchname(sb, name);
+       if (name[0] == '-')
+               return CHECK_REF_FORMAT_ERROR;
        strbuf_splice(sb, 0, 0, "refs/heads/", 11);
        return check_ref_format(sb->buf);
 }