diff options
author | Joey Hess <joey@kitenet.net> | 2013-07-03 15:26:59 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-07-03 15:26:59 -0400 |
commit | 289a3f7749a5086a19a22b277a022e3b006da94f (patch) | |
tree | 10c4a4fe5ab4391c82cf91f4069bf0d7f4c7490b /Logs | |
parent | 0e4ed4dd9bf9b78c1723400e9c787a18430c5f57 (diff) |
--unused: New switch that makes git-annex operate on all data found by the last run of git annex unused. Supported by fsck, get, move, copy.
Diffstat (limited to 'Logs')
-rw-r--r-- | Logs/Unused.hs | 58 |
1 files changed, 6 insertions, 52 deletions
diff --git a/Logs/Unused.hs b/Logs/Unused.hs index 342d88aa6..271211ed2 100644 --- a/Logs/Unused.hs +++ b/Logs/Unused.hs @@ -6,21 +6,20 @@ -} module Logs.Unused ( - UnusedMap, - UnusedMaps(..), + UnusedMap(..), writeUnusedLog, readUnusedLog, - withUnusedMaps, - startUnused, + unusedKeys, ) where import qualified Data.Map as M import Common.Annex -import Command import Types.Key import Utility.Tmp +type UnusedMap = M.Map Int Key + writeUnusedLog :: FilePath -> [(Int, Key)] -> Annex () writeUnusedLog prefix l = do logfile <- fromRepo $ gitAnnexUnusedLog prefix @@ -42,50 +41,5 @@ readUnusedLog prefix = do where (tag, rest) = separate (== ' ') line -type UnusedMap = M.Map Int Key - -data UnusedMaps = UnusedMaps - { unusedMap :: UnusedMap - , unusedBadMap :: UnusedMap - , unusedTmpMap :: UnusedMap - } - -{- Read unused logs once, and pass the maps to each start action. -} -withUnusedMaps :: (UnusedMaps -> Int -> CommandStart) -> CommandSeek -withUnusedMaps a params = do - unused <- readUnusedLog "" - unusedbad <- readUnusedLog "bad" - unusedtmp <- readUnusedLog "tmp" - return $ map (a $ UnusedMaps unused unusedbad unusedtmp) $ - concatMap unusedSpec params - -unusedSpec :: String -> [Int] -unusedSpec spec - | "-" `isInfixOf` spec = range $ separate (== '-') spec - | otherwise = maybe badspec (: []) (readish spec) - where - range (a, b) = case (readish a, readish b) of - (Just x, Just y) -> [x..y] - _ -> badspec - badspec = error $ "Expected number or range, not \"" ++ spec ++ "\"" - -{- Start action for unused content. Finds the number in the maps, and - - calls either of 3 actions, depending on the type of unused file. -} -startUnused :: String - -> (Key -> CommandPerform) - -> (Key -> CommandPerform) - -> (Key -> CommandPerform) - -> UnusedMaps -> Int -> CommandStart -startUnused message unused badunused tmpunused maps n = search - [ (unusedMap maps, unused) - , (unusedBadMap maps, badunused) - , (unusedTmpMap maps, tmpunused) - ] - where - search [] = stop - search ((m, a):rest) = - case M.lookup n m of - Nothing -> search rest - Just key -> do - showStart message (show n) - next $ a key +unusedKeys :: Annex [Key] +unusedKeys = M.elems <$> readUnusedLog "" |