nicer style; also empty refs are implicitly not allowed
This commit is contained in:
parent
0be6ebb0aa
commit
378f61d0ef
1 changed files with 18 additions and 12 deletions
30
Git/Ref.hs
30
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) -}
|
- The rules for this are complex; see git-check-ref-format(1) -}
|
||||||
legalRef :: Bool -> String -> Bool
|
legalRef :: Bool -> String -> Bool
|
||||||
legalRef allowonelevel s
|
legalRef allowonelevel s = all (== False) illegal
|
||||||
| 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
|
|
||||||
where
|
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
|
pathbits = split "/" s
|
||||||
illegalchars = " ~^:?*[\\" ++ controlchars
|
illegalchars = " ~^:?*[\\" ++ controlchars
|
||||||
controlchars = chr 0o177 : [chr 0 .. chr (0o40-1)]
|
controlchars = chr 0o177 : [chr 0 .. chr (0o40-1)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue