summaryrefslogtreecommitdiff
path: root/GitRepo.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-02 16:00:55 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-02 16:00:55 -0400
commitcecb1cbeb2017e9e3be252c253ee7f2b49235c63 (patch)
treeda28533de58dbbf7bfbf0cbe49c44ac2e561fa85 /GitRepo.hs
parent9e5985ff983c4b489d545e99946cf62e34fadcd9 (diff)
clean up
Diffstat (limited to 'GitRepo.hs')
-rw-r--r--GitRepo.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/GitRepo.hs b/GitRepo.hs
index c62a820d8..752253b41 100644
--- a/GitRepo.hs
+++ b/GitRepo.hs
@@ -333,23 +333,26 @@ checkAttr repo attr files = do
bits = split sep l
sep = ": " ++ attr ++ ": "
-{- Some git commands output encoded filenames. Such a filename
- - will always be double-quoted, and then \nnn (in octal) is used
- - to escape high characters. -}
+{- Some git commands output encoded filenames. Decode that (annoyingly
+ - complex) encoding. -}
decodeGitFile :: String -> FilePath
decodeGitFile [] = []
decodeGitFile f@(c:s)
+ -- encoded strings will be inside double quotes
| c == '"' = unescape ("", middle)
| otherwise = f
where
+ e = '\\'
middle = take (length s - 1) s
unescape (b, []) = b
+ -- look for escapes starting with '\'
unescape (b, v) = b ++ beginning ++ unescape (decode rest)
where
- pair = span (/= '\\') v
+ pair = span (/= e) v
beginning = fst pair
rest = snd pair
- isescape c = c == '\\'
+ isescape c = c == e
+ -- \NNN is an octal encoded character
decode (e:n1:n2:n3:rest)
| isescape e && alloctal = (fromoctal, rest)
where
@@ -358,10 +361,10 @@ decodeGitFile f@(c:s)
isOctDigit n3
fromoctal = [chr $ readoctal (n1:n2:n3:[])]
readoctal o = read $ "0o" ++ o :: Int
+ -- \C is used for a few special characters
decode (e:nc:rest)
| isescape e = ([echar nc], rest)
where
- -- special character escapes
echar 'a' = '\a'
echar 'b' = '\b'
echar 'f' = '\f'