summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-04-11 12:29:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-04-11 12:29:31 -0400
commit378f61d0ef5564aab28442f09b2462ce7013ce1b (patch)
treef250247bb665f896c1a6a43e37f1e3126c4a2a4d /Git
parent0be6ebb0aad2cc9135479f3a3725e7c21add4989 (diff)
nicer style; also empty refs are implicitly not allowed
Diffstat (limited to 'Git')
-rw-r--r--Git/Ref.hs30
1 files changed, 18 insertions, 12 deletions
diff --git a/Git/Ref.hs b/Git/Ref.hs
index c7abdb00a..29b69de9b 100644
--- a/Git/Ref.hs
+++ b/Git/Ref.hs
@@ -68,19 +68,25 @@ matchingUniq ref repo = nubBy uniqref <$> matching ref repo
-
- The rules for this are complex; see git-check-ref-format(1) -}
legalRef :: Bool -> String -> Bool
-legalRef allowonelevel s
- | any ("." `isPrefixOf`) pathbits = False
- | any (".lock" `isSuffixOf`) pathbits = False
- | not allowonelevel && length pathbits < 2 = False
- | ".." `isInfixOf` s = False
- | any (\c -> [c] `isInfixOf` s) illegalchars = False
- | "/" `isPrefixOf` s = False
- | "/" `isSuffixOf` s = False
- | "//" `isInfixOf` s = False
- | "." `isSuffixOf` s = False
- | "@{" `isInfixOf` s = False
- | otherwise = True
+legalRef allowonelevel s = all (== False) illegal
where
+ illegal =
+ [ any ("." `isPrefixOf`) pathbits
+ , any (".lock" `isSuffixOf`) pathbits
+ , not allowonelevel && length pathbits < 2
+ , contains ".."
+ , any (\c -> contains [c]) illegalchars
+ , begins "/"
+ , ends "/"
+ , contains "//"
+ , ends "."
+ , contains "@{"
+ , null s
+ ]
+ contains v = v `isInfixOf` s
+ ends v = v `isSuffixOf` s
+ begins v = v `isPrefixOf` s
+
pathbits = split "/" s
illegalchars = " ~^:?*[\\" ++ controlchars
controlchars = chr 0o177 : [chr 0 .. chr (0o40-1)]