summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-05-11 23:11:56 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-05-11 23:11:56 -0400
commitc46bbe9b5095dc58ab11c106e07179db85a0f1df (patch)
treec5c49c51841509f0da98715297252dfba11ec8af
parentcbc98eee9d583f56d52a70fbff7abe171a1ecebe (diff)
refactoring
-rwxr-xr-xGit/CatFile.hs15
-rwxr-xr-xGit/HashObject.hs22
-rw-r--r--Utility/CoProcess.hs17
3 files changed, 23 insertions, 31 deletions
diff --git a/Git/CatFile.hs b/Git/CatFile.hs
index c1ba11bd9..b83241445 100755
--- a/Git/CatFile.hs
+++ b/Git/CatFile.hs
@@ -5,8 +5,6 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-{-# LANGUAGE CPP #-}
-
module Git.CatFile (
CatFileHandle,
catFileStart,
@@ -30,7 +28,7 @@ import qualified Utility.CoProcess as CoProcess
type CatFileHandle = CoProcess.CoProcessHandle
catFileStart :: Repo -> IO CatFileHandle
-catFileStart = gitCoProcessStart
+catFileStart = CoProcess.rawMode <=< gitCoProcessStart
[ Param "cat-file"
, Param "--batch"
]
@@ -51,17 +49,8 @@ catObject h object = maybe L.empty fst <$> catObjectDetails h object
catObjectDetails :: CatFileHandle -> Ref -> IO (Maybe (L.ByteString, Sha))
catObjectDetails h object = CoProcess.query h send receive
where
- send to = do
- fileEncoding to
-#ifdef __WINDOWS__
- hSetNewlineMode to noNewlineTranslation
-#endif
- hPutStrLn to $ show object
+ send to = hPutStrLn to $ show object
receive from = do
- fileEncoding from
-#ifdef __WINDOWS__
- hSetNewlineMode from noNewlineTranslation
-#endif
header <- hGetLine from
case words header of
[sha, objtype, size]
diff --git a/Git/HashObject.hs b/Git/HashObject.hs
index 5e153687d..bf3ca7f8b 100755
--- a/Git/HashObject.hs
+++ b/Git/HashObject.hs
@@ -5,8 +5,6 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-{-# LANGUAGE CPP #-}
-
module Git.HashObject where
import Common
@@ -19,7 +17,7 @@ import qualified Utility.CoProcess as CoProcess
type HashObjectHandle = CoProcess.CoProcessHandle
hashObjectStart :: Repo -> IO HashObjectHandle
-hashObjectStart = gitCoProcessStart
+hashObjectStart = CoProcess.rawMode <=< gitCoProcessStart
[ Param "hash-object"
, Param "-w"
, Param "--stdin-paths"
@@ -32,23 +30,13 @@ hashObjectStop = CoProcess.stop
hashFile :: HashObjectHandle -> FilePath -> IO Sha
hashFile h file = CoProcess.query h send receive
where
- send to = do
- fileEncoding to
-#ifdef __WINDOWS__
- hSetNewlineMode to noNewlineTranslation
-#endif
- hPutStrLn to file
- receive from = getSha "hash-object" $ do
-#ifdef __WINDOWS__
- hSetNewlineMode from noNewlineTranslation
-#endif
- hGetLine from
+ send to = hPutStrLn to file
+ receive from = getSha "hash-object" $ hGetLine from
{- Injects some content into git, returning its Sha. -}
hashObject :: ObjectType -> String -> Repo -> IO Sha
-hashObject objtype content repo = getSha subcmd $ do
- s <- pipeWriteRead (map Param params) content repo
- return s
+hashObject objtype content repo = getSha subcmd $
+ pipeWriteRead (map Param params) content repo
where
subcmd = "hash-object"
params = [subcmd, "-t", show objtype, "-w", "--stdin"]
diff --git a/Utility/CoProcess.hs b/Utility/CoProcess.hs
index 7a2a5fe8e..f72850fc5 100644
--- a/Utility/CoProcess.hs
+++ b/Utility/CoProcess.hs
@@ -6,11 +6,14 @@
- Licensed under the GNU GPL version 3 or higher.
-}
+{-# LANGUAGE CPP #-}
+
module Utility.CoProcess (
CoProcessHandle,
start,
stop,
- query
+ query,
+ rawMode
) where
import Common
@@ -33,3 +36,15 @@ query (_, from, to, _) send receive = do
_ <- send to
hFlush to
receive from
+
+rawMode :: CoProcessHandle -> IO CoProcessHandle
+rawMode ch@(_, from, to, _) = do
+ raw from
+ raw to
+ return ch
+ where
+ raw h = do
+ fileEncoding h
+#ifdef __WINDOWS__
+ hSetNewlineMode h noNewlineTranslation
+#endif