2011-09-28 19:15:42 +00:00
|
|
|
{- 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.
|
|
|
|
-}
|
|
|
|
|
2011-10-04 04:40:47 +00:00
|
|
|
module Annex.CatFile (
|
2011-11-12 21:45:12 +00:00
|
|
|
catFile,
|
|
|
|
catFileHandle
|
2011-09-28 19:15:42 +00:00
|
|
|
) where
|
|
|
|
|
2011-11-12 21:45:12 +00:00
|
|
|
import qualified Data.ByteString.Lazy.Char8 as L
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
improve type signatures with a Ref newtype
In git, a Ref can be a Sha, or a Branch, or a Tag. I added type aliases for
those. Note that this does not prevent mixing up of eg, refs and branches
at the type level. Since git really doesn't care, except rare cases like
git update-ref, or git tag -d, that seems ok for now.
There's also a tree-ish, but let's just use Ref for it. A given Sha or Ref
may or may not be a tree-ish, depending on the object type, so there seems
no point in trying to represent it at the type level.
2011-11-16 06:23:34 +00:00
|
|
|
import qualified Git
|
2011-09-28 19:15:42 +00:00
|
|
|
import qualified Git.CatFile
|
|
|
|
import qualified Annex
|
|
|
|
|
improve type signatures with a Ref newtype
In git, a Ref can be a Sha, or a Branch, or a Tag. I added type aliases for
those. Note that this does not prevent mixing up of eg, refs and branches
at the type level. Since git really doesn't care, except rare cases like
git update-ref, or git tag -d, that seems ok for now.
There's also a tree-ish, but let's just use Ref for it. A given Sha or Ref
may or may not be a tree-ish, depending on the object type, so there seems
no point in trying to represent it at the type level.
2011-11-16 06:23:34 +00:00
|
|
|
catFile :: Git.Branch -> FilePath -> Annex L.ByteString
|
2011-11-12 21:45:12 +00:00
|
|
|
catFile branch file = do
|
|
|
|
h <- catFileHandle
|
|
|
|
liftIO $ Git.CatFile.catFile h branch file
|
|
|
|
|
|
|
|
catFileHandle :: Annex Git.CatFile.CatFileHandle
|
|
|
|
catFileHandle = maybe startup return =<< Annex.getState Annex.catfilehandle
|
2011-09-28 19:15:42 +00:00
|
|
|
where
|
|
|
|
startup = do
|
2011-11-11 05:52:58 +00:00
|
|
|
h <- inRepo Git.CatFile.catFileStart
|
2011-09-28 19:15:42 +00:00
|
|
|
Annex.changeState $ \s -> s { Annex.catfilehandle = Just h }
|
2011-11-12 21:45:12 +00:00
|
|
|
return h
|