aboutsummaryrefslogtreecommitdiff
path: root/CatFile.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-28 15:15:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-28 15:17:36 -0400
commitad245a6375b32a17a9aa18088ee006cad6b4c1ff (patch)
tree857f50ce714cbf667bcbb77796e806a3c7bd1985 /CatFile.hs
parent4f4eaf387ab801157cb8986a9ca3542a977e9e03 (diff)
refactor catfile code
split into generic IO code, and a thin Annex wrapper
Diffstat (limited to 'CatFile.hs')
-rw-r--r--CatFile.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/CatFile.hs b/CatFile.hs
new file mode 100644
index 000000000..0eb1e74f6
--- /dev/null
+++ b/CatFile.hs
@@ -0,0 +1,26 @@
+{- git cat-file interface, with handle automatically stored in the Annex monad
+ -
+ - Copyright 2011 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module CatFile (
+ catFile
+) where
+
+import Control.Monad.State
+
+import qualified Git.CatFile
+import Types
+import qualified Annex
+
+catFile :: String -> FilePath -> Annex String
+catFile branch file = maybe startup go =<< Annex.getState Annex.catfilehandle
+ where
+ startup = do
+ g <- Annex.gitRepo
+ h <- liftIO $ Git.CatFile.catFileStart g
+ Annex.changeState $ \s -> s { Annex.catfilehandle = Just h }
+ go h
+ go h = liftIO $ Git.CatFile.catFile h branch file