diff options
author | Joey Hess <joey@kitenet.net> | 2011-01-29 23:30:08 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-01-29 23:30:08 -0400 |
commit | 5584ccc8adbbcd629b3809fd39b5c00479fd0a25 (patch) | |
tree | 69cb13e43a2d5b97118dd3b0d52d3599069bf9ed /Command | |
parent | b8318384858c59d73f231d225323a8a0a4a42868 (diff) |
factor out pure code
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Unused.hs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Command/Unused.hs b/Command/Unused.hs index 4ffa6a17f..32d70aa19 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -51,12 +51,9 @@ checkUnused = do g <- Annex.gitRepo liftIO $ safeWriteFile (gitAnnexUnusedLog g) $ unlines $ map (\(n, k) -> show n ++ " " ++ show k) list - unless (null unused) $ - showLongNote $ unusedmsg unusedlist - unless (null staletmp) $ - showLongNote $ staletmpmsg staletmplist - unless (null list) $ - showLongNote $ "\n" + unless (null unused) $ showLongNote $ unusedmsg unusedlist + unless (null staletmp) $ showLongNote $ staletmpmsg staletmplist + unless (null list) $ showLongNote $ "\n" return $ null list where @@ -85,20 +82,23 @@ unusedKeys = do g <- Annex.gitRepo present <- getKeysPresent referenced <- getKeysReferenced + tmps <- tmpKeys - let unused = present `exclude` referenced + let (unused, staletmp, duptmp) = calcUnusedKeys present referenced tmps - -- Some tmp files may be dups copies of content that is fully present. - -- Simply delete those, while including the keys for the rest of - -- the temp files in the returned list for the user to deal with. - tmps <- tmpKeys - let staletmp = tmps `exclude` present - let duptmp = tmps `exclude` staletmp + -- Tmp files that are dups of content already present can simply + -- be removed. _ <- liftIO $ mapM (\t -> removeFile $ gitAnnexTmpLocation g t) duptmp return (unused, staletmp) +calcUnusedKeys :: [Key] -> [Key] -> [Key] -> ([Key], [Key], [Key]) +calcUnusedKeys present referenced tmps = (unused, staletmp, duptmp) where + unused = present `exclude` referenced + staletmp = tmps `exclude` present + duptmp = tmps `exclude` staletmp + -- Constructing a single map, of the set that tends to be -- smaller, appears more efficient in both memory and CPU -- than constructing and taking the M.difference of two maps. |