tweak
This commit is contained in:
parent
5e2b4e16ba
commit
a3d97e0c85
1 changed files with 14 additions and 16 deletions
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue