aboutsummaryrefslogtreecommitdiff
path: root/Git/HashObject.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-12 21:41:37 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-12 21:41:37 -0400
commit46588674b081cd4ea5820680d8fc15c81ed175ad (patch)
tree29055caae381eb6a2bb857a258ec43caecb4df11 /Git/HashObject.hs
parent0e45b762a07d12dbc099936a8481bda9c02d0318 (diff)
avoid closing pipe before all the shas are read from it
Could have just used hGetContentsStrict here, but that would require storing all the shas in memory. Since this is called at the end of a git-annex run, it may have created a *lot* of shas, so I avoid that memory use and stream them out like before.
Diffstat (limited to 'Git/HashObject.hs')
-rw-r--r--Git/HashObject.hs14
1 files changed, 8 insertions, 6 deletions
diff --git a/Git/HashObject.hs b/Git/HashObject.hs
index f28d865b1..99b96afcb 100644
--- a/Git/HashObject.hs
+++ b/Git/HashObject.hs
@@ -10,16 +10,15 @@ module Git.HashObject where
import Common
import Git
-{- Injects a set of files into git, returning the shas of the objects. -}
-hashFiles :: [FilePath] -> Repo -> IO [Sha]
+{- Injects a set of files into git, returning the shas of the objects
+ - and an IO action to call ones 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
_ <- forkProcess (feeder toh)
hClose toh
- shas <- map Git.Ref . lines <$> hGetContents fromh
- hClose fromh
- forceSuccess pid
- return shas
+ shas <- map Git.Ref . lines <$> hGetContentsStrict fromh
+ return (shas, ender fromh pid)
where
git_hash_object = Git.gitCommandLine
[Param "hash-object", Param "-w", Param "--stdin-paths"]
@@ -27,3 +26,6 @@ hashFiles paths repo = do
hPutStr toh $ unlines paths
hClose toh
exitSuccess
+ ender fromh pid = do
+ hClose fromh
+ forceSuccess pid