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.
|
- 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.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -19,31 +19,31 @@ getState = Annex.getState Annex.branchstate
|
||||||
setState :: BranchState -> Annex ()
|
setState :: BranchState -> Annex ()
|
||||||
setState state = Annex.changeState $ \s -> s { Annex.branchstate = state }
|
setState state = Annex.changeState $ \s -> s { Annex.branchstate = state }
|
||||||
|
|
||||||
|
changeState :: (BranchState -> BranchState) -> Annex ()
|
||||||
|
changeState changer = setState =<< changer <$> getState
|
||||||
|
|
||||||
setCache :: FilePath -> String -> Annex ()
|
setCache :: FilePath -> String -> Annex ()
|
||||||
setCache file content = do
|
setCache file content = changeState $ \s -> s
|
||||||
state <- getState
|
{ cachedFile = Just file, cachedContent = content}
|
||||||
setState state { cachedFile = Just file, cachedContent = content }
|
|
||||||
|
|
||||||
getCache :: FilePath -> Annex (Maybe String)
|
getCache :: FilePath -> Annex (Maybe String)
|
||||||
getCache file = getState >>= go
|
getCache file = from <$> getState
|
||||||
where
|
where
|
||||||
go state
|
from state
|
||||||
| cachedFile state == Just file =
|
| cachedFile state == Just file =
|
||||||
return $ Just $ cachedContent state
|
Just $ cachedContent state
|
||||||
| otherwise = return Nothing
|
| otherwise = Nothing
|
||||||
|
|
||||||
invalidateCache :: Annex ()
|
invalidateCache :: Annex ()
|
||||||
invalidateCache = do
|
invalidateCache = changeState $ \s -> s
|
||||||
state <- getState
|
{ cachedFile = Nothing, cachedContent = "" }
|
||||||
setState state { cachedFile = Nothing, cachedContent = "" }
|
|
||||||
|
|
||||||
{- Runs an action to check that the index file exists, if it's not been
|
{- Runs an action to check that the index file exists, if it's not been
|
||||||
- checked before in this run of git-annex. -}
|
- checked before in this run of git-annex. -}
|
||||||
checkIndexOnce :: Annex () -> Annex ()
|
checkIndexOnce :: Annex () -> Annex ()
|
||||||
checkIndexOnce a = unlessM (indexChecked <$> getState) $ do
|
checkIndexOnce a = unlessM (indexChecked <$> getState) $ do
|
||||||
a
|
a
|
||||||
state <- getState
|
changeState $ \s -> s { indexChecked = True }
|
||||||
setState state { indexChecked = True }
|
|
||||||
|
|
||||||
{- Runs an action to update the branch, if it's not been updated before
|
{- Runs an action to update the branch, if it's not been updated before
|
||||||
- in this run of git-annex. -}
|
- 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
|
- is known to have not changed, or git-annex won't be relying on info
|
||||||
- from it. -}
|
- from it. -}
|
||||||
disableUpdate :: Annex ()
|
disableUpdate :: Annex ()
|
||||||
disableUpdate = do
|
disableUpdate = changeState $ \s -> s { branchUpdated = True }
|
||||||
state <- getState
|
|
||||||
setState state { branchUpdated = True }
|
|
||||||
|
|
Loading…
Reference in a new issue