move hashObject to HashObject library and generalize it to support all git object types
This commit is contained in:
parent
f1bd72ea54
commit
f596084a59
4 changed files with 36 additions and 22 deletions
|
@ -9,7 +9,9 @@ module Git.HashObject where
|
|||
|
||||
import Common
|
||||
import Git
|
||||
import Git.Sha
|
||||
import Git.Command
|
||||
import Git.Types
|
||||
import qualified Utility.CoProcess as CoProcess
|
||||
|
||||
type HashObjectHandle = CoProcess.CoProcessHandle
|
||||
|
@ -24,11 +26,23 @@ hashObjectStart = CoProcess.start "git" . toCommand . gitCommandLine
|
|||
hashObjectStop :: HashObjectHandle -> IO ()
|
||||
hashObjectStop = CoProcess.stop
|
||||
|
||||
{- Injects a file into git, returning the shas of the objects. -}
|
||||
{- Injects a file into git, returning the Sha of the object. -}
|
||||
hashFile :: HashObjectHandle -> FilePath -> IO Sha
|
||||
hashFile h file = CoProcess.query h send receive
|
||||
where
|
||||
send to = do
|
||||
fileEncoding to
|
||||
hPutStrLn to file
|
||||
receive from = Ref <$> hGetLine from
|
||||
receive from = getSha "hash-object" $ hGetLine from
|
||||
|
||||
{- Injects some content into git, returning its Sha. -}
|
||||
hashObject :: Repo -> ObjectType -> String -> IO Sha
|
||||
hashObject repo objtype content = getSha subcmd $ do
|
||||
(h, s) <- pipeWriteRead (map Param params) content repo
|
||||
length s `seq` do
|
||||
forceSuccess h
|
||||
reap -- XXX unsure why this is needed
|
||||
return s
|
||||
where
|
||||
subcmd = "hash-object"
|
||||
params = [subcmd, "-t", show objtype, "-w", "--stdin"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue