summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
Diffstat (limited to 'Git')
-rw-r--r--Git/HashObject.hs47
1 files changed, 28 insertions, 19 deletions
diff --git a/Git/HashObject.hs b/Git/HashObject.hs
index ac74f0257..200fedbd2 100644
--- a/Git/HashObject.hs
+++ b/Git/HashObject.hs
@@ -1,6 +1,6 @@
{- git hash-object interface
-
- - Copyright 2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2011-2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -11,23 +11,32 @@ import Common
import Git
import Git.Command
-{- Injects a set of files into git, returning the shas of the objects
- - and an IO action to call once the the shas have been used. -}
-hashFiles :: [FilePath] -> Repo -> IO ([Sha], IO ())
-hashFiles paths repo = do
- (pid, fromh, toh) <- hPipeBoth "git" $ toCommand $ git_hash_object repo
+type HashObjectHandle = (PipeHandle, Handle, Handle)
+
+{- Starts git hash-object and returns a handle. -}
+hashObjectStart :: Repo -> IO HashObjectHandle
+hashObjectStart repo = do
+ r@(_, _, toh) <- hPipeBoth "git" $
+ toCommand $ gitCommandLine params repo
fileEncoding toh
- _ <- forkProcess (feeder toh)
- hClose toh
- shas <- map Ref . lines <$> hGetContents fromh
- return (shas, ender fromh pid)
+ return r
where
- git_hash_object = gitCommandLine
- [Param "hash-object", Param "-w", Param "--stdin-paths"]
- feeder toh = do
- hPutStr toh $ unlines paths
- hClose toh
- exitSuccess
- ender fromh pid = do
- hClose fromh
- forceSuccess pid
+ params =
+ [ Param "hash-object"
+ , Param "-w"
+ , Param "--stdin-paths"
+ ]
+
+{- Stops git hash-object. -}
+hashObjectStop :: HashObjectHandle -> IO ()
+hashObjectStop (pid, from, to) = do
+ hClose to
+ hClose from
+ forceSuccess pid
+
+{- Injects a file into git, returning the shas of the objects. -}
+hashFile :: HashObjectHandle -> FilePath -> IO Sha
+hashFile (_, from, to) file = do
+ hPutStrLn to file
+ hFlush to
+ Ref <$> hGetLine from