diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-06 02:31:31 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-06 02:31:31 -0400 |
commit | f596084a599fb363dcbb425dce7c4ca46bb56ca0 (patch) | |
tree | 934e14858c9f56cf9f69cb7eadfadee4a8b4c1eb /Git/HashObject.hs | |
parent | f1bd72ea546be705334ba8f6d01d9dcfb0c33cf9 (diff) |
move hashObject to HashObject library and generalize it to support all git object types
Diffstat (limited to 'Git/HashObject.hs')
-rw-r--r-- | Git/HashObject.hs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Git/HashObject.hs b/Git/HashObject.hs index 617e5ac28..b052413fd 100644 --- a/Git/HashObject.hs +++ b/Git/HashObject.hs @@ -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"] |