From 6d79f9e755b3d6548d5e251dca4ec2f623809777 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 20 Jan 2016 13:04:07 -0400 Subject: [PATCH] find --batch --- Command/Find.hs | 21 +++++++++++++++------ debian/changelog | 2 +- doc/git-annex-find.mdwn | 29 +++++++++++++++++++---------- doc/todo/--batch_for_find.mdwn | 2 ++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Command/Find.hs b/Command/Find.hs index ae5595c1d6..c720ce76cf 100644 --- a/Command/Find.hs +++ b/Command/Find.hs @@ -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 = diff --git a/debian/changelog b/debian/changelog index 53b4d14e7e..8c23e7edb0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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. diff --git a/doc/git-annex-find.mdwn b/doc/git-annex-find.mdwn index 4c1501e962..9c578c2451 100644 --- a/doc/git-annex-find.mdwn +++ b/doc/git-annex-find.mdwn @@ -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 diff --git a/doc/todo/--batch_for_find.mdwn b/doc/todo/--batch_for_find.mdwn index 89f6e3de5e..825ca560fa 100644 --- a/doc/todo/--batch_for_find.mdwn +++ b/doc/todo/--batch_for_find.mdwn @@ -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]]