summaryrefslogtreecommitdiff
path: root/Git/HashObject.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-02-14 14:35:52 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-02-14 14:37:59 -0400
commit7ebd98d8d829005c7dae38b789146d98e6800e5b (patch)
treee20bfa80563081153d712633eb25b8c6a0f5fc78 /Git/HashObject.hs
parentcdd6cdbb67ea87a4a03357fb75c22d432fa2e15d (diff)
fix memory leak when staging the journal
The list of files had to be retained until the end so it could be deleted. Also, a list of update-index lines was generated and only then fed into it. Now everything streams in constant space.
Diffstat (limited to 'Git/HashObject.hs')
-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