All commands that support --all also support a --key option, which limits them to acting on a single key.

This commit is contained in:
Joey Hess 2014-01-26 14:59:47 -04:00
parent 85398d068e
commit ec7443eb06
4 changed files with 26 additions and 13 deletions

View file

@ -81,6 +81,8 @@ keyOptions =
"operate on all versions of all files" "operate on all versions of all files"
, Option ['U'] ["unused"] (NoArg (Annex.setFlag "unused")) , Option ['U'] ["unused"] (NoArg (Annex.setFlag "unused"))
"operate on files found by last run of git-annex unused" "operate on files found by last run of git-annex unused"
, Option [] ["key"] (ReqArg (Annex.setField "key") paramKey)
"operate on specified key"
] ]
fromOption :: Option fromOption :: Option

31
Seek.hs
View file

@ -123,6 +123,8 @@ withNothing _ _ = error "This command takes no parameters."
- If --unused is specified, runs an action on all keys found by - If --unused is specified, runs an action on all keys found by
- the last git annex unused scan. - the last git annex unused scan.
- -
- If --key is specified, operates only on that key.
-
- Otherwise, fall back to a regular CommandSeek action on - Otherwise, fall back to a regular CommandSeek action on
- whatever params were passed. -} - whatever params were passed. -}
withKeyOptions :: (Key -> CommandStart) -> CommandSeek -> CommandSeek withKeyOptions :: (Key -> CommandStart) -> CommandSeek -> CommandSeek
@ -130,21 +132,24 @@ withKeyOptions keyop fallbackop params = do
bare <- fromRepo Git.repoIsLocalBare bare <- fromRepo Git.repoIsLocalBare
allkeys <- Annex.getFlag "all" allkeys <- Annex.getFlag "all"
unused <- Annex.getFlag "unused" unused <- Annex.getFlag "unused"
specifickey <- Annex.getField "key"
auto <- Annex.getState Annex.auto auto <- Annex.getState Annex.auto
case (allkeys || bare , unused, auto ) of when (auto && bare) $
(True , False , False) -> go loggedKeys error "Cannot use --auto in a bare repository"
(False , True , False) -> go unusedKeys' case (allkeys, unused, null params, specifickey) of
(True , True , _ ) (False , False , True , Nothing)
| bare && not allkeys -> go unusedKeys' | bare -> go auto loggedKeys
| otherwise -> error "Cannot use --all with --unused." | otherwise -> fallbackop params
(False , False , _ ) -> fallbackop params (False , False , _ , Nothing) -> fallbackop params
(_ , _ , True ) (True , False , True , Nothing) -> go auto loggedKeys
| bare -> error "Cannot use --auto in a bare repository." (False , True , True , Nothing) -> go auto unusedKeys'
| otherwise -> error "Cannot use --auto with --all or --unused." (False , False , True , Just ks) -> case file2key ks of
Nothing -> error "Invalid key"
Just k -> go auto $ return [k]
_ -> error "Can only specify one of file names, --all, --unused, or --key"
where where
go a = do go True _ = error "Cannot use --auto with --all or --unused or --key"
unless (null params) $ go False a = do
error "Cannot mix --all or --unused with file names."
matcher <- Limit.getMatcher matcher <- Limit.getMatcher
seekActions $ map (process matcher) <$> a seekActions $ map (process matcher) <$> a
process matcher k = ifM (matcher $ MatchingKey k) process matcher k = ifM (matcher $ MatchingKey k)

2
debian/changelog vendored
View file

@ -38,6 +38,8 @@ git-annex (5.20140118) UNRELEASED; urgency=medium
* webapp: After upgrading a git repository to git-annex, fix * webapp: After upgrading a git repository to git-annex, fix
bug that made it temporarily not be synced with. bug that made it temporarily not be synced with.
* whereis: Support --all. * whereis: Support --all.
* All commands that support --all also support a --key option,
which limits them to acting on a single key.
-- Joey Hess <joeyh@debian.org> Sat, 18 Jan 2014 11:54:17 -0400 -- Joey Hess <joeyh@debian.org> Sat, 18 Jan 2014 11:54:17 -0400

View file

@ -860,6 +860,10 @@ subdirectories).
Operate on all data that has been determined to be unused by Operate on all data that has been determined to be unused by
a previous run of `git-annex unused`. a previous run of `git-annex unused`.
* `--key=key`
Operate on only the specified key.
* `--quiet` * `--quiet`
Avoid the default verbose display of what is done; only show errors Avoid the default verbose display of what is done; only show errors