Optimised union merging; now only runs git cat-file once.

This commit is contained in:
Joey Hess 2011-11-12 17:45:12 -04:00
parent cea65b9e5b
commit 04edae6791
7 changed files with 62 additions and 36 deletions

View file

@ -6,18 +6,25 @@
-}
module Annex.CatFile (
catFile
catFile,
catFileHandle
) where
import qualified Data.ByteString.Lazy.Char8 as L
import Common.Annex
import qualified Git.CatFile
import qualified Annex
catFile :: String -> FilePath -> Annex String
catFile branch file = maybe startup go =<< Annex.getState Annex.catfilehandle
catFile :: String -> FilePath -> Annex L.ByteString
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
where
startup = do
h <- inRepo Git.CatFile.catFileStart
Annex.changeState $ \s -> s { Annex.catfilehandle = Just h }
go h
go h = liftIO $ Git.CatFile.catFile h branch file
return h