git-annex/Git/HashObject.hs

33 lines
867 B
Haskell
Raw Normal View History

2011-12-13 01:24:55 +00:00
{- git hash-object interface
-
- Copyright 2011 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Git.HashObject where
import Common
import Git
2011-12-14 19:56:11 +00:00
import Git.Command
2011-12-13 01:24:55 +00:00
{- 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 ())
2011-12-13 01:24:55 +00:00
hashFiles paths repo = do
(pid, fromh, toh) <- hPipeBoth "git" $ toCommand $ git_hash_object repo
_ <- forkProcess (feeder toh)
hClose toh
2011-12-14 19:30:14 +00:00
shas <- map Ref . lines <$> hGetContentsStrict fromh
return (shas, ender fromh pid)
2011-12-13 01:24:55 +00:00
where
2011-12-14 19:30:14 +00:00
git_hash_object = gitCommandLine
2011-12-13 01:24:55 +00:00
[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