aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-01-20 13:04:07 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-01-20 13:04:07 -0400
commit91c9f6f086cf6d503c3ecb10a211c0c946e554eb (patch)
treea4e5409d432176937b326f6bf9056c440c40dee1
parentc48b1434d1443ea1421fa474a6a5aecbf60ac83a (diff)
find --batch
-rw-r--r--Command/Find.hs21
-rw-r--r--debian/changelog2
-rw-r--r--doc/git-annex-find.mdwn29
-rw-r--r--doc/todo/--batch_for_find.mdwn2
4 files changed, 37 insertions, 17 deletions
diff --git a/Command/Find.hs b/Command/Find.hs
index ae5595c1d..c720ce76c 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 53b4d14e7..8c23e7edb 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 4c1501e96..9c578c245 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 89f6e3de5..825ca560f 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]]