diff options
author | Joey Hess <joey@kitenet.net> | 2012-03-11 17:15:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-03-11 17:15:58 -0400 |
commit | ff3644ad38d210c5ce0ebfb5a2cf5e84bb3b47da (patch) | |
tree | 8c9638d417204ad7dc2a0b3c0406dd631a0e51a1 /Command/Unused.hs | |
parent | b086e32c63a4932fc5916bedae7abe0690da4eb0 (diff) |
status: Fixed to run in nearly constant space.
Before, it leaked space due to caching lists of keys. Now all necessary
data about keys is calculated as they stream in.
The "nearly constant" is due to getKeysPresent, which builds up a lot
of [] thunks as it traverses .git/annex/objects/. Will deal with it later.
Diffstat (limited to 'Command/Unused.hs')
-rw-r--r-- | Command/Unused.hs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/Command/Unused.hs b/Command/Unused.hs index ba14bfc4a..69b58c5e7 100644 --- a/Command/Unused.hs +++ b/Command/Unused.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2010-2011 Joey Hess <joey@kitenet.net> + - Copyright 2010-2012 Joey Hess <joey@kitenet.net> - - Licensed under the GNU GPL version 3 or higher. -} @@ -171,7 +171,7 @@ excludeReferenced l = do go s (r:rs) | s == S.empty = return [] -- optimisation | otherwise = do - !s' <- withKeysReferencedInGit r s S.delete + s' <- withKeysReferencedInGit r s S.delete go s' rs {- Finds items in the first, smaller list, that are not @@ -186,21 +186,14 @@ exclude smaller larger = S.toList $ remove larger $ S.fromList smaller where remove a b = foldl (flip S.delete) b a -{- List of keys referenced by symlinks in the git repo. -} -getKeysReferenced :: Annex [Key] -getKeysReferenced = do - top <- fromRepo Git.workTree - files <- inRepo $ LsFiles.inRepo [top] - keypairs <- mapM Backend.lookupFile files - return $ map fst $ catMaybes keypairs - {- Given an initial value, mutates it using an action for each - key referenced by symlinks in the git repo. -} withKeysReferenced :: v -> (Key -> v -> v) -> Annex v -withKeysReferenced initial a = do - top <- fromRepo Git.workTree - go initial =<< inRepo (LsFiles.inRepo [top]) +withKeysReferenced initial a = go initial =<< files where + files = do + top <- fromRepo Git.workTree + inRepo $ LsFiles.inRepo [top] go v [] = return v go v (f:fs) = do x <- Backend.lookupFile f |