find --batch

This commit is contained in:
Joey Hess 2016-01-20 13:04:07 -04:00
parent 1bd4809bd2
commit 6d79f9e755
Failed to extract signature
4 changed files with 37 additions and 17 deletions

View file

@ -17,6 +17,7 @@ import Limit
import qualified Utility.Format
import Utility.DataUnits
import Types.Key
import CmdLine.Batch
cmd :: Command
cmd = withGlobalOptions annexedMatchingOptions $ mkCommand $
@ -29,12 +30,14 @@ mkCommand = noCommit . noMessages . withGlobalOptions [jsonOption]
data FindOptions = FindOptions
{ findThese :: CmdParams
, formatOption :: Maybe Utility.Format.Format
, batchOption :: BatchMode
}
optParser :: CmdParamsDesc -> Parser FindOptions
optParser desc = FindOptions
<$> cmdParams desc
<*> optional parseFormatOption
<*> parseBatchOption
parseFormatOption :: Parser Utility.Format.Format
parseFormatOption =
@ -48,15 +51,21 @@ parseFormatOption =
)
seek :: FindOptions -> CommandSeek
seek o = withFilesInGit (whenAnnexed $ start o) (findThese o)
seek o = case batchOption o of
NoBatch -> withFilesInGit go (findThese o)
Batch -> batchFiles go
where
go = whenAnnexed $ start o
-- only files inAnnex are shown, unless the user has requested
-- others via a limit
start :: FindOptions -> FilePath -> Key -> CommandStart
start o file key = do
-- only files inAnnex are shown, unless the user has requested
-- others via a limit
whenM (limited <||> inAnnex key) $
start o file key = ifM (limited <||> inAnnex key)
( do
showFormatted (formatOption o) file $ ("file", file) : keyVars key
stop
next $ next $ return True
, stop
)
showFormatted :: Maybe Utility.Format.Format -> String -> [(String, String)] -> Annex ()
showFormatted format unformatted vars =

2
debian/changelog vendored
View file

@ -2,7 +2,7 @@ git-annex (6.20160115) UNRELEASED; urgency=medium
* whereis --json: Urls are now listed inside the remote that claims them,
rather than all together at the end.
* info, add, whereis: Support --batch mode.
* info, add, whereis, find: Support --batch mode.
* Force output to be line-buffered, even when it's not connected to the
terminal. This is particuarly important for commands with --batch
output, which was not always being flushed at an appropriate time.

View file

@ -13,6 +13,19 @@ finds files in the current directory and its subdirectories.
# OPTIONS
* matching options
The [[git-annex-matching-options]](1)
can be used to specify files to list.
By default, the find command only lists annexed files whose content is
currently present. Specifying any of the matching options will override
this default behavior.
To list all annexed files, present or not, specify `--include "*"`.
To list annexed files whose content is not present, specify `--not --in=here`
* `--print0`
Output filenames terminated with nulls, for use with `xargs -0`
@ -41,18 +54,14 @@ finds files in the current directory and its subdirectories.
This is intended to be parsed by programs that use
git-annex. Each line of output is a JSON object.
* matching options
The [[git-annex-matching-options]](1)
can be used to specify files to list.
* `--batch`
By default, the find command only lists annexed files whose content is
currently present. Specifying any of the matching options will override
this default behavior.
Enables batch mode, in which a file is read in a line from stdin,
its information displayed, and repeat.
To list all annexed files, present or not, specify `--include "*"`.
To list annexed files whose content is not present, specify `--not --in=here`
Note that if the file is not an annexed file, or is not present,
or otherwise doesn't meet the matching options, an empty line
will be output instead.
# SEE ALSO

View file

@ -1,3 +1,5 @@
I am using `annex find filename` after running 'annex add` to figure out if file was added to annex or to git.
[[!meta author=yoh]]
> [[done]] --[[Joey]]