findkeys: New command, very similar to git-annex find but operating on keys

I've long been asked for `git-annex find --all` or something like that,
but pushed back on it because I feel that the command is analagous to
find(1) and so it would be surprising for it to list keys rather than
files. So instead, add a new findkeys subcommand.

Note that the use of withKeyOptions is rather strange because usually
that is used to fall back to --all rather than listing files, but here
it's made to default to --all like behavior and never list files.

A performance thing that could be improved is that withKeyOptions
always reads and caches location logs. But findkeys with no options does
not need them, so it could be made faster. That caching does speed up
options like --in though. This is really just a subset of a more general
performance thing that --all reads location logs sometimes unncessarily.
Anyway, it needs to read the location log in order to checkDead,
and it seems good that findkeys does skip dead keys.

Also, cleaned up comments on git-annex-find man page asking for --all
option.

Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
Joey Hess 2023-01-17 14:42:29 -04:00
parent a522a41a42
commit f8bc208e89
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
24 changed files with 172 additions and 205 deletions

View file

@ -239,15 +239,23 @@ annexedMatchingOptions :: [AnnexOption]
annexedMatchingOptions = concat
[ keyMatchingOptions'
, fileMatchingOptions' Limit.LimitAnnexFiles
, anythingNothingOptions
, combiningOptions
, timeLimitOption
, sizeLimitOption
]
-- Matching options that can operate on keys as well as files.
-- Options to match properties of keys.
keyMatchingOptions :: [AnnexOption]
keyMatchingOptions = keyMatchingOptions' ++ combiningOptions ++ timeLimitOption ++ sizeLimitOption
keyMatchingOptions = concat
[ keyMatchingOptions'
, anythingNothingOptions
, combiningOptions
, timeLimitOption
, sizeLimitOption
]
-- Matching options that can operate on keys as well as files.
keyMatchingOptions' :: [AnnexOption]
keyMatchingOptions' =
[ annexOption (setAnnexState . Limit.addIn) $ strOption
@ -378,7 +386,11 @@ fileMatchingOptions' lb =
<> help "match files smaller than a size"
<> hidden
)
, annexFlag (setAnnexState Limit.addAnything)
]
anythingNothingOptions :: [AnnexOption]
anythingNothingOptions =
[ annexFlag (setAnnexState Limit.addAnything)
( long "anything"
<> help "match all files"
<> hidden