diff options
author | Joey Hess <joey@kitenet.net> | 2014-01-22 16:35:32 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-01-22 16:35:32 -0400 |
commit | 180fbceee03badc450c84c28ef8219fa68d80bd6 (patch) | |
tree | 1739e92f46067ae0be84af6789b3d3b9adb09ee1 /Logs/Unused.hs | |
parent | 9a5de318d15f0234080a6f0bd802fe073cf57334 (diff) |
add "unused" preferred content expression
With a really nice optimisation that keeps it from having any overhead
in normal operation!
This commit was sponsored by Ulises Vitulli.
Diffstat (limited to 'Logs/Unused.hs')
-rw-r--r-- | Logs/Unused.hs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Logs/Unused.hs b/Logs/Unused.hs index daeeb93ab..74f46b85e 100644 --- a/Logs/Unused.hs +++ b/Logs/Unused.hs @@ -21,14 +21,17 @@ module Logs.Unused ( readUnusedLog, readUnusedMap, unusedKeys, + unusedKeys' ) where import qualified Data.Map as M +import qualified Data.Set as S import Data.Time.Clock.POSIX import Data.Time import System.Locale import Common.Annex +import qualified Annex import Types.Key import Utility.Tmp @@ -84,5 +87,16 @@ readUnusedLog prefix = do readUnusedMap :: FilePath -> Annex UnusedMap readUnusedMap = log2map <$$> readUnusedLog -unusedKeys :: Annex [Key] -unusedKeys = M.keys <$> readUnusedLog "" +{- Set of unused keys. This is cached for speed. -} +unusedKeys :: Annex (S.Set Key) +unusedKeys = maybe (setUnusedKeys =<< unusedKeys') return + =<< Annex.getState Annex.unusedkeys + +unusedKeys' :: Annex [Key] +unusedKeys' = M.keys <$> readUnusedLog "" + +setUnusedKeys :: [Key] -> Annex (S.Set Key) +setUnusedKeys ks = do + let v = S.fromList ks + Annex.changeState $ \s -> s { Annex.unusedkeys = Just v } + return v |