diff options
author | Joey Hess <joey@kitenet.net> | 2012-01-14 14:31:16 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-01-14 14:31:16 -0400 |
commit | a3d97e0c85cf6c1b6668939c02d07522d06f2d18 (patch) | |
tree | 8d37e1c61b12f376cdc60a91ca1eb2d723f448ab /Annex | |
parent | 5e2b4e16ba8f6cb32461b5c09e3872ce50aa13e7 (diff) |
tweak
Diffstat (limited to 'Annex')
-rw-r--r-- | Annex/BranchState.hs | 30 |
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 } |