--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.

This commit is contained in:
Joey Hess 2013-07-03 15:26:59 -04:00
parent ef4239dda0
commit 04d07f2c1f
13 changed files with 120 additions and 87 deletions

37
Seek.hs
View file

@ -25,6 +25,7 @@ import qualified Limit
import qualified Option
import Config
import Logs.Location
import Logs.Unused
seekHelper :: ([FilePath] -> Git.Repo -> IO ([FilePath], IO Bool)) -> [FilePath] -> Annex [FilePath]
seekHelper a params = do
@ -123,22 +124,32 @@ withNothing a [] = return [a]
withNothing _ _ = error "This command takes no parameters."
{- If --all is specified, or in a bare repo, runs an action on all
- known keys. Otherwise, fall back to a regular CommandSeek action on
- known keys.
-
- If --unused is specified, runs an action on all keys found by
- the last git annex unused scan.
-
- Otherwise, fall back to a regular CommandSeek action on
- whatever params were passed. -}
withAll :: (Key -> CommandStart) -> CommandSeek -> CommandSeek
withAll allop fallbackop params = go =<< (Annex.getFlag "all" <||> isbare)
withKeyOptions :: (Key -> CommandStart) -> CommandSeek -> CommandSeek
withKeyOptions keyop fallbackop params = do
bare <- fromRepo Git.repoIsLocalBare
all <- Annex.getFlag "all" <||> pure bare
unused <- Annex.getFlag "unused"
auto <- Annex.getState Annex.auto
case (all , unused, auto ) of
(True , False , False) -> go loggedKeys
(False, True , False) -> go unusedKeys
(True , True , _ ) -> error "Cannot use --all with --unused."
(False, False , _ ) -> fallbackop params
(_ , _ , True )
| bare -> error "Cannot use --auto in a bare repository."
| otherwise -> error "Cannot use --auto with --all or --unused."
where
go False = fallbackop params
go True = do
whenM (Annex.getState Annex.auto) $
ifM isbare
( error "Cannot use --auto in a bare repository."
, error "Cannot use --auto with --all."
)
go a = do
unless (null params) $
error "Cannot mix --all with file names."
map allop <$> loggedKeys
isbare = fromRepo Git.repoIsLocalBare
error "Cannot mix --all or --unused with file names."
map keyop <$> a
prepFiltered :: (FilePath -> CommandStart) -> Annex [FilePath] -> Annex [CommandStart]
prepFiltered a fs = do