This commit is contained in:
Joey Hess 2010-11-02 16:00:55 -04:00
parent 9e5985ff98
commit cecb1cbeb2

View file

@ -333,23 +333,26 @@ checkAttr repo attr files = do
bits = split sep l bits = split sep l
sep = ": " ++ attr ++ ": " sep = ": " ++ attr ++ ": "
{- Some git commands output encoded filenames. Such a filename {- Some git commands output encoded filenames. Decode that (annoyingly
- will always be double-quoted, and then \nnn (in octal) is used - complex) encoding. -}
- to escape high characters. -}
decodeGitFile :: String -> FilePath decodeGitFile :: String -> FilePath
decodeGitFile [] = [] decodeGitFile [] = []
decodeGitFile f@(c:s) decodeGitFile f@(c:s)
-- encoded strings will be inside double quotes
| c == '"' = unescape ("", middle) | c == '"' = unescape ("", middle)
| otherwise = f | otherwise = f
where where
e = '\\'
middle = take (length s - 1) s middle = take (length s - 1) s
unescape (b, []) = b unescape (b, []) = b
-- look for escapes starting with '\'
unescape (b, v) = b ++ beginning ++ unescape (decode rest) unescape (b, v) = b ++ beginning ++ unescape (decode rest)
where where
pair = span (/= '\\') v pair = span (/= e) v
beginning = fst pair beginning = fst pair
rest = snd pair rest = snd pair
isescape c = c == '\\' isescape c = c == e
-- \NNN is an octal encoded character
decode (e:n1:n2:n3:rest) decode (e:n1:n2:n3:rest)
| isescape e && alloctal = (fromoctal, rest) | isescape e && alloctal = (fromoctal, rest)
where where
@ -358,10 +361,10 @@ decodeGitFile f@(c:s)
isOctDigit n3 isOctDigit n3
fromoctal = [chr $ readoctal (n1:n2:n3:[])] fromoctal = [chr $ readoctal (n1:n2:n3:[])]
readoctal o = read $ "0o" ++ o :: Int readoctal o = read $ "0o" ++ o :: Int
-- \C is used for a few special characters
decode (e:nc:rest) decode (e:nc:rest)
| isescape e = ([echar nc], rest) | isescape e = ([echar nc], rest)
where where
-- special character escapes
echar 'a' = '\a' echar 'a' = '\a'
echar 'b' = '\b' echar 'b' = '\b'
echar 'f' = '\f' echar 'f' = '\f'