From 04edae6791b4eddaa77dda2407264dc4434d74b7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 12 Nov 2011 17:45:12 -0400 Subject: Optimised union merging; now only runs git cat-file once. --- Annex/Branch.hs | 5 +++-- Annex/CatFile.hs | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'Annex') diff --git a/Annex/Branch.hs b/Annex/Branch.hs index fad818fb0..20134003d 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -149,7 +149,8 @@ update = onceonly $ do - documentation advises users not to directly - modify the branch. -} - inRepo $ \g -> Git.UnionMerge.merge_index g branches + h <- catFileHandle + inRepo $ \g -> Git.UnionMerge.merge_index h g branches ff <- if dirty then return False else tryFastForwardTo refs unless ff $ inRepo $ Git.commit merge_desc fullname (nub $ fullname:refs) @@ -280,7 +281,7 @@ get' staleok file = fromcache =<< getCache file fromjournal Nothing | staleok = withIndex frombranch | otherwise = withIndexUpdate $ frombranch >>= cache - frombranch = catFile fullname file + frombranch = L.unpack <$> catFile fullname file cache content = do setCache file content return content diff --git a/Annex/CatFile.hs b/Annex/CatFile.hs index 99cc519f5..0541f7269 100644 --- a/Annex/CatFile.hs +++ b/Annex/CatFile.hs @@ -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 -- cgit v1.2.3