This commit is contained in:
Joey Hess 2012-01-14 14:31:16 -04:00
parent 5e2b4e16ba
commit a3d97e0c85

View file

@ -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 }