summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-12 21:24:55 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-12 21:24:55 -0400
commit0e45b762a07d12dbc099936a8481bda9c02d0318 (patch)
tree8c192751dccbe346390d91d130566d0c3dff345b /Git
parent31a0c07ee91af9e3bf434f416a4d711d841aa223 (diff)
broke out Git/HashObject.hs
Diffstat (limited to 'Git')
-rw-r--r--Git/HashObject.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/Git/HashObject.hs b/Git/HashObject.hs
new file mode 100644
index 000000000..f28d865b1
--- /dev/null
+++ b/Git/HashObject.hs
@@ -0,0 +1,29 @@
+{- 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
+
+{- Injects a set of files into git, returning the shas of the objects. -}
+hashFiles :: [FilePath] -> Repo -> IO [Sha]
+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
+ where
+ git_hash_object = Git.gitCommandLine
+ [Param "hash-object", Param "-w", Param "--stdin-paths"]
+ feeder toh = do
+ hPutStr toh $ unlines paths
+ hClose toh
+ exitSuccess