diff options
author | Joey Hess <joey@kitenet.net> | 2012-02-03 15:12:41 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-02-03 16:23:20 -0400 |
commit | d8fb97806c430be8358b2b77d67c02e876278d2f (patch) | |
tree | fd7cebea35931445e3e00ea7b2ed160da9b56b3f /Command | |
parent | fb78107f85ffbd83c7c8dad6bfcaa8374387cccc (diff) |
support all filename encodings with ghc 7.4
Under ghc 7.4, this seems to be able to handle all filename encodings
again. Including filename encodings that do not match the LANG setting.
I think this will not work with earlier versions of ghc, it uses some ghc
internals.
Turns out that ghc 7.4 has a special filesystem encoding that it uses when
reading/writing filenames (as FilePaths). This encoding is documented
to allow "arbitrary undecodable bytes to be round-tripped through it".
So, to get FilePaths from eg, git ls-files, set the Handle that is reading
from git to use this encoding. Then things basically just work.
However, I have not found a way to make Text read using this encoding.
Text really does assume unicode. So I had to switch back to using String
when reading/writing data to git. Which is a pity, because it's some
percent slower, but at least it works.
Note that stdout and stderr also have to be set to this encoding, or
printing out filenames that contain undecodable bytes causes a crash.
IMHO this is a misfeature in ghc, that the user can pass you a filename,
which you can readFile, etc, but that default, putStr of filename may
cause a crash!
Git.CheckAttr gave me special trouble, because the filenames I got back
from git, after feeding them in, had further encoding breakage.
Rather than try to deal with that, I just zip up the input filenames
with the attributes. Which must be returned in the same order queried
for this to work.
Also of note is an apparent GHC bug I worked around in Git.CheckAttr. It
used to forkProcess and feed git from the child process. Unfortunatly,
after this forkProcess, accessing the `files` variable from the parent
returns []. Not the value that was passed into the function. This screams
of a bad bug, that's clobbering a variable, but for now I just avoid
forkProcess there to work around it. That forkProcess was itself only added
because of a ghc bug, #624389. I've confirmed that the test case for that
bug doesn't reproduce it with ghc 7.4. So that's ok, except for the new ghc
bug I have not isolated and reported. Why does this simple bit of code
magnet the ghc bugs? :)
Also, the symlink touching code is currently broken, when used on utf-8
filenames in a non-utf-8 locale, or probably on any filename containing
undecodable bytes, and I temporarily commented it out.
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Add.hs | 8 | ||||
-rw-r--r-- | Command/Uninit.hs | 4 | ||||
-rw-r--r-- | Command/Unused.hs | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/Command/Add.hs b/Command/Add.hs index 9410601b8..944525ea5 100644 --- a/Command/Add.hs +++ b/Command/Add.hs @@ -82,9 +82,11 @@ cleanup file key hascontent = do -- touch the symlink to have the same mtime as the -- file it points to - liftIO $ do - mtime <- modificationTime <$> getFileStatus file - touch file (TimeSpec mtime) False + -- XXX Currently broken on non-utf8 locales when + -- dealing with utf-8 filenames. + --liftIO $ do + --mtime <- modificationTime <$> getFileStatus file + --touch file (TimeSpec mtime) False force <- Annex.getState Annex.force if force diff --git a/Command/Uninit.hs b/Command/Uninit.hs index 878547bc3..d6283a77d 100644 --- a/Command/Uninit.hs +++ b/Command/Uninit.hs @@ -7,8 +7,6 @@ module Command.Uninit where -import qualified Data.Text.Lazy as L - import Common.Annex import Command import qualified Git @@ -29,7 +27,7 @@ check = do when (b == Annex.Branch.name) $ error $ "cannot uninit when the " ++ show b ++ " branch is checked out" where - current_branch = Git.Ref . Prelude.head . lines . L.unpack <$> revhead + current_branch = Git.Ref . Prelude.head . lines <$> revhead revhead = inRepo $ Git.Command.pipeRead [Params "rev-parse --abbrev-ref HEAD"] diff --git a/Command/Unused.hs b/Command/Unused.hs index 67f743ab0..1c82b9ae4 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -162,7 +162,7 @@ excludeReferenced l = do refs = map (Git.Ref . snd) . nubBy uniqref . filter ourbranches . - map (separate (== ' ')) . lines . L.unpack + map (separate (== ' ')) . lines uniqref (a, _) (b, _) = a == b ourbranchend = '/' : show Annex.Branch.name ourbranches (_, b) = not $ ourbranchend `isSuffixOf` b |