summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-04-06 00:43:44 -0700
committerJunio C Hamano <gitster@pobox.com>2009-04-06 00:43:44 -0700
commitfbdc05661d9b732d06c47ccb3d5836d0d1b563e5 (patch)
treeb5e7e00ca449758d6244a382a27e9b967286787a /refs.c
parent03a39a91842cf745e5fc27dbd6485aad44d839a4 (diff)
parent3e262b95c50991de12cc5e180b72256561606a19 (diff)
downloadgit-fbdc05661d9b732d06c47ccb3d5836d0d1b563e5.tar.gz
Merge branch 'jc/name-branch'
* jc/name-branch: Don't permit ref/branch names to end with ".lock" check_ref_format(): tighten refname rules strbuf_check_branch_ref(): a helper to check a refname for a branch Fix branch -m @{-1} newname check-ref-format --branch: give Porcelain a way to grok branch shorthand strbuf_branchname(): a wrapper for branch name shorthands Rename interpret/substitute nth_last_branch functions Conflicts: Documentation/git-check-ref-format.txt
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/refs.c b/refs.c
index 26b001453b..59c373fc6d 100644
--- 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,21 +718,28 @@ 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;
}
}