summaryrefslogtreecommitdiff
path: root/Annex/BranchState.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Annex/BranchState.hs')
-rw-r--r--Annex/BranchState.hs30
1 files changed, 14 insertions, 16 deletions
diff --git a/Annex/BranchState.hs b/Annex/BranchState.hs
index 977c4aa10..2e60d1229 100644
--- a/Annex/BranchState.hs
+++ b/Annex/BranchState.hs
@@ -2,7 +2,7 @@
-
- Runtime state about the git-annex branch, including a small read cache.
-
- - Copyright 2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2011-2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -19,31 +19,31 @@ getState = Annex.getState Annex.branchstate
setState :: BranchState -> Annex ()
setState state = Annex.changeState $ \s -> s { Annex.branchstate = state }
+changeState :: (BranchState -> BranchState) -> Annex ()
+changeState changer = setState =<< changer <$> getState
+
setCache :: FilePath -> String -> Annex ()
-setCache file content = do
- state <- getState
- setState state { cachedFile = Just file, cachedContent = content }
+setCache file content = changeState $ \s -> s
+ { cachedFile = Just file, cachedContent = content}
getCache :: FilePath -> Annex (Maybe String)
-getCache file = getState >>= go
+getCache file = from <$> getState
where
- go state
+ from state
| cachedFile state == Just file =
- return $ Just $ cachedContent state
- | otherwise = return Nothing
+ Just $ cachedContent state
+ | otherwise = Nothing
invalidateCache :: Annex ()
-invalidateCache = do
- state <- getState
- setState state { cachedFile = Nothing, cachedContent = "" }
+invalidateCache = changeState $ \s -> s
+ { 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 }
+ changeState $ \s -> s { indexChecked = True }
{- Runs an action to update the branch, if it's not been updated before
- in this run of git-annex. -}
@@ -56,6 +56,4 @@ 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 = do
- state <- getState
- setState state { branchUpdated = True }
+disableUpdate = changeState $ \s -> s { branchUpdated = True }