summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-01-14 12:07:36 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-01-14 12:07:36 -0400
commit5e2b4e16ba8f6cb32461b5c09e3872ce50aa13e7 (patch)
tree2420780869a072c9c3a76d12aea887bd64c5cf04
parent8c87293b4886bd7b3389c3a3066e2c6cfa9f1a56 (diff)
avoid multiple unnecessary stats of the index file
Up to one per file processed.
-rw-r--r--Annex/Branch.hs2
-rw-r--r--Annex/BranchState.hs17
-rw-r--r--Types/BranchState.hs3
3 files changed, 14 insertions, 8 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs
index a653a4995..b2b1ed3e4 100644
--- a/Annex/Branch.hs
+++ b/Annex/Branch.hs
@@ -268,7 +268,7 @@ withIndex' :: Bool -> Annex a -> Annex a
withIndex' bootstrapping a = do
f <- fromRepo gitAnnexIndex
bracketIO (Git.Index.override f) id $ do
- unlessM (liftIO $ doesFileExist f) $ do
+ checkIndexOnce $ unlessM (liftIO $ doesFileExist f) $ do
unless bootstrapping create
liftIO $ createDirectoryIfMissing True $ takeDirectory f
unless bootstrapping $ inRepo genIndex
diff --git a/Annex/BranchState.hs b/Annex/BranchState.hs
index 0950e9a96..977c4aa10 100644
--- a/Annex/BranchState.hs
+++ b/Annex/BranchState.hs
@@ -37,6 +37,14 @@ invalidateCache = do
state <- getState
setState state { cachedFile = Nothing, cachedContent = "" }
+{- Runs an action to check that the index file exists, if it's not been
+ - checked before in this run of git-annex. -}
+checkIndexOnce :: Annex () -> Annex ()
+checkIndexOnce a = unlessM (indexChecked <$> getState) $ do
+ a
+ state <- getState
+ setState state { indexChecked = True }
+
{- Runs an action to update the branch, if it's not been updated before
- in this run of git-annex. -}
runUpdateOnce :: Annex () -> Annex ()
@@ -48,9 +56,6 @@ runUpdateOnce a = unlessM (branchUpdated <$> getState) $ do
- is known to have not changed, or git-annex won't be relying on info
- from it. -}
disableUpdate :: Annex ()
-disableUpdate = Annex.changeState setupdated
- where
- setupdated s = s { Annex.branchstate = new }
- where
- new = old { branchUpdated = True }
- old = Annex.branchstate s
+disableUpdate = do
+ state <- getState
+ setState state { branchUpdated = True }
diff --git a/Types/BranchState.hs b/Types/BranchState.hs
index 777edb32c..e5b2291f3 100644
--- a/Types/BranchState.hs
+++ b/Types/BranchState.hs
@@ -9,6 +9,7 @@ module Types.BranchState where
data BranchState = BranchState {
branchUpdated :: Bool, -- has the branch been updated this run?
+ indexChecked :: Bool, -- has the index file been checked to exist?
-- the content of one file is cached
cachedFile :: Maybe FilePath,
@@ -16,4 +17,4 @@ data BranchState = BranchState {
}
startBranchState :: BranchState
-startBranchState = BranchState False Nothing ""
+startBranchState = BranchState False False Nothing ""