Always use filesystem encoding for all file and handle reads and writes.
This is a big scary change. I have convinced myself it should be safe. I hope!
This commit is contained in:
parent
c89a9e6ca5
commit
8484c0c197
48 changed files with 75 additions and 109 deletions
|
@ -37,6 +37,7 @@ import Git.Command
|
|||
import Git.Types
|
||||
import Git.FilePath
|
||||
import qualified Utility.CoProcess as CoProcess
|
||||
import Utility.FileSystemEncoding
|
||||
|
||||
data CatFileHandle = CatFileHandle
|
||||
{ catFileProcess :: CoProcess.CoProcessHandle
|
||||
|
|
|
@ -53,7 +53,6 @@ runQuiet params repo = withQuietOutput createProcessSuccess $
|
|||
pipeReadLazy :: [CommandParam] -> Repo -> IO (String, IO Bool)
|
||||
pipeReadLazy params repo = assertLocal repo $ do
|
||||
(_, Just h, _, pid) <- createProcess p { std_out = CreatePipe }
|
||||
fileEncoding h
|
||||
c <- hGetContents h
|
||||
return (c, checkSuccessProcess pid)
|
||||
where
|
||||
|
@ -66,7 +65,6 @@ pipeReadLazy params repo = assertLocal repo $ do
|
|||
pipeReadStrict :: [CommandParam] -> Repo -> IO String
|
||||
pipeReadStrict params repo = assertLocal repo $
|
||||
withHandle StdoutHandle (createProcessChecked ignoreFailureProcess) p $ \h -> do
|
||||
fileEncoding h
|
||||
output <- hGetContentsStrict h
|
||||
hClose h
|
||||
return output
|
||||
|
@ -81,9 +79,7 @@ pipeWriteRead params writer repo = assertLocal repo $
|
|||
writeReadProcessEnv "git" (toCommand $ gitCommandLine params repo)
|
||||
(gitEnv repo) writer (Just adjusthandle)
|
||||
where
|
||||
adjusthandle h = do
|
||||
fileEncoding h
|
||||
hSetNewlineMode h noNewlineTranslation
|
||||
adjusthandle h = hSetNewlineMode h noNewlineTranslation
|
||||
|
||||
{- Runs a git command, feeding it input on a handle with an action. -}
|
||||
pipeWrite :: [CommandParam] -> Repo -> (Handle -> IO ()) -> IO ()
|
||||
|
|
|
@ -79,10 +79,6 @@ global = do
|
|||
{- Reads git config from a handle and populates a repo with it. -}
|
||||
hRead :: Repo -> Handle -> IO Repo
|
||||
hRead repo h = do
|
||||
-- We use the FileSystemEncoding when reading from git-config,
|
||||
-- because it can contain arbitrary filepaths (and other strings)
|
||||
-- in any encoding.
|
||||
fileEncoding h
|
||||
val <- hGetContentsStrict h
|
||||
store val repo
|
||||
|
||||
|
@ -167,7 +163,6 @@ coreBare = "core.bare"
|
|||
fromPipe :: Repo -> String -> [CommandParam] -> IO (Either SomeException (Repo, String))
|
||||
fromPipe r cmd params = try $
|
||||
withHandle StdoutHandle createProcessSuccess p $ \h -> do
|
||||
fileEncoding h
|
||||
val <- hGetContentsStrict h
|
||||
r' <- store val r
|
||||
return (r', val)
|
||||
|
|
|
@ -41,7 +41,6 @@ hashFile h file = CoProcess.query h send receive
|
|||
- interface does not allow batch hashing without using temp files. -}
|
||||
hashBlob :: HashObjectHandle -> String -> IO Sha
|
||||
hashBlob h s = withTmpFile "hash" $ \tmp tmph -> do
|
||||
fileEncoding tmph
|
||||
#ifdef mingw32_HOST_OS
|
||||
hSetNewlineMode tmph noNewlineTranslation
|
||||
#endif
|
||||
|
|
|
@ -159,7 +159,6 @@ runAction repo action@(CommandAction {}) = do
|
|||
#ifndef mingw32_HOST_OS
|
||||
let p = (proc "xargs" $ "-0":"git":toCommand gitparams) { env = gitEnv repo }
|
||||
withHandle StdinHandle createProcessSuccess p $ \h -> do
|
||||
fileEncoding h
|
||||
hPutStr h $ intercalate "\0" $ toCommand $ getFiles action
|
||||
hClose h
|
||||
#else
|
||||
|
|
|
@ -614,4 +614,4 @@ successfulRepair = fst
|
|||
safeReadFile :: FilePath -> IO String
|
||||
safeReadFile f = do
|
||||
allowRead f
|
||||
readFileStrictAnyEncoding f
|
||||
readFileStrict f
|
||||
|
|
|
@ -22,6 +22,7 @@ import Git.UpdateIndex
|
|||
import Git.HashObject
|
||||
import Git.Types
|
||||
import Git.FilePath
|
||||
import Utility.FileSystemEncoding
|
||||
|
||||
{- Performs a union merge between two branches, staging it in the index.
|
||||
- Any previously staged changes in the index will be lost.
|
||||
|
@ -94,8 +95,7 @@ mergeFile info file hashhandle h = case filter (/= nullSha) [Ref asha, Ref bsha]
|
|||
-- We don't know how the file is encoded, but need to
|
||||
-- split it into lines to union merge. Using the
|
||||
-- FileSystemEncoding for this is a hack, but ensures there
|
||||
-- are no decoding errors. Note that this works because
|
||||
-- hashObject sets fileEncoding on its write handle.
|
||||
-- are no decoding errors.
|
||||
getcontents s = lines . encodeW8NUL . L.unpack <$> catObject h s
|
||||
|
||||
{- Calculates a union merge between a list of refs, with contents.
|
||||
|
|
|
@ -55,7 +55,6 @@ startUpdateIndex :: Repo -> IO UpdateIndexHandle
|
|||
startUpdateIndex repo = do
|
||||
(Just h, _, _, p) <- createProcess (gitCreateProcess params repo)
|
||||
{ std_in = CreatePipe }
|
||||
fileEncoding h
|
||||
return $ UpdateIndexHandle p h
|
||||
where
|
||||
params = map Param ["update-index", "-z", "--index-info"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue