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:
parent
a522a41a42
commit
f8bc208e89
24 changed files with 172 additions and 205 deletions
|
@ -43,28 +43,26 @@ optParser desc = FindOptions
|
|||
<*> parseBatchOption False
|
||||
|
||||
parseFormatOption :: Parser Utility.Format.Format
|
||||
parseFormatOption =
|
||||
parseFormatOption = parseFormatOption' "${file}\0"
|
||||
|
||||
parseFormatOption' :: String -> Parser Utility.Format.Format
|
||||
parseFormatOption' print0format =
|
||||
option (Utility.Format.gen <$> str)
|
||||
( long "format" <> metavar paramFormat
|
||||
<> help "control format of output"
|
||||
)
|
||||
<|> flag' (Utility.Format.gen "${file}\0")
|
||||
<|> flag' (Utility.Format.gen print0format)
|
||||
( long "print0"
|
||||
<> help "output filenames terminated with nulls"
|
||||
<> help "use nulls to separate output rather than lines"
|
||||
)
|
||||
|
||||
seek :: FindOptions -> CommandSeek
|
||||
seek o = do
|
||||
unless (isJust (keyOptions o)) $
|
||||
checkNotBareRepo
|
||||
islimited <- limited
|
||||
let seeker = AnnexedFileSeeker
|
||||
seeker <- contentPresentUnlessLimited $ AnnexedFileSeeker
|
||||
{ startAction = start o
|
||||
-- only files with content present are shown, unless
|
||||
-- the user has requested others via a limit
|
||||
, checkContentPresent = if islimited
|
||||
then Nothing
|
||||
else Just True
|
||||
, checkContentPresent = Nothing
|
||||
, usesLocationLog = False
|
||||
}
|
||||
case batchOption o of
|
||||
|
@ -77,6 +75,17 @@ seek o = do
|
|||
where
|
||||
ww = WarnUnmatchLsFiles
|
||||
|
||||
-- Default to needing content to be present, but if the user specified a
|
||||
-- limit, content does not need to be present.
|
||||
contentPresentUnlessLimited :: AnnexedFileSeeker -> Annex AnnexedFileSeeker
|
||||
contentPresentUnlessLimited s = do
|
||||
islimited <- limited
|
||||
return $ s
|
||||
{ checkContentPresent = if islimited
|
||||
then Nothing
|
||||
else Just True
|
||||
}
|
||||
|
||||
start :: FindOptions -> SeekInput -> RawFilePath -> Key -> CommandStart
|
||||
start o _ file key = startingCustomOutput key $ do
|
||||
showFormatted (formatOption o) file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue