summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CmdLine/Action.hs13
-rw-r--r--CmdLine/Batch.hs11
-rw-r--r--Command/Add.hs20
-rw-r--r--debian/changelog2
-rw-r--r--doc/git-annex-add.mdwn14
-rw-r--r--doc/todo/--batch_for_add.mdwn4
6 files changed, 51 insertions, 13 deletions
diff --git a/CmdLine/Action.hs b/CmdLine/Action.hs
index 60e108bee..693a6814f 100644
--- a/CmdLine/Action.hs
+++ b/CmdLine/Action.hs
@@ -134,15 +134,20 @@ includeCommandAction a = account =<< tryIO (callCommandAction a)
- stages, without catching errors. Useful if one command wants to run
- part of another command. -}
callCommandAction :: CommandStart -> CommandCleanup
-callCommandAction = start
+callCommandAction = fromMaybe True <$$> callCommandAction'
+
+{- Like callCommandAction, but returns Nothing when the command did not
+ - perform any action. -}
+callCommandAction' :: CommandStart -> Annex (Maybe Bool)
+callCommandAction' = start
where
start = stage $ maybe skip perform
perform = stage $ maybe failure cleanup
cleanup = stage $ status
stage = (=<<)
- skip = return True
- failure = showEndFail >> return False
- status r = showEndResult r >> return r
+ skip = return Nothing
+ failure = showEndFail >> return (Just False)
+ status r = showEndResult r >> return (Just r)
{- Do concurrent output when that has been requested. -}
allowConcurrentOutput :: Annex a -> Annex a
diff --git a/CmdLine/Batch.hs b/CmdLine/Batch.hs
index d8d210de4..e7706881a 100644
--- a/CmdLine/Batch.hs
+++ b/CmdLine/Batch.hs
@@ -54,3 +54,14 @@ batchInput parser a = do
batchInput parser a
where
parseerr s = error $ "Batch input parse failure: " ++ s
+
+-- Runs a CommandStart in batch mode.
+--
+-- The batch mode user expects to read a line of output, and it's up to the
+-- CommandStart to generate that output as it succeeds or fails to do its
+-- job. However, if it stops without doing anything, it won't generate
+-- any output, so in that case, batchBadInput is used to provide the caller
+-- with an empty line.
+batchCommandAction :: CommandStart -> Annex ()
+batchCommandAction a = maybe (batchBadInput Batch) (const noop)
+ =<< callCommandAction' a
diff --git a/Command/Add.hs b/Command/Add.hs
index 0dea0a7b7..f2fcd2fb1 100644
--- a/Command/Add.hs
+++ b/Command/Add.hs
@@ -22,6 +22,7 @@ import Annex.FileMatcher
import Annex.Version
import qualified Database.Keys
import Types.Key
+import CmdLine.Batch
cmd :: Command
cmd = notBareRepo $ withGlobalOptions (jobsOption : jsonOption : fileMatchingOptions) $
@@ -31,6 +32,7 @@ cmd = notBareRepo $ withGlobalOptions (jobsOption : jsonOption : fileMatchingOpt
data AddOptions = AddOptions
{ addThese :: CmdParams
, includeDotFiles :: Bool
+ , batchOption :: BatchMode
}
optParser :: CmdParamsDesc -> Parser AddOptions
@@ -40,6 +42,7 @@ optParser desc = AddOptions
( long "include-dotfiles"
<> help "don't skip dotfiles"
)
+ <*> parseBatchOption
{- Add acts on both files not checked into git yet, and unlocked files.
-
@@ -47,15 +50,20 @@ optParser desc = AddOptions
seek :: AddOptions -> CommandSeek
seek o = allowConcurrentOutput $ do
matcher <- largeFilesMatcher
- let go a = flip a (addThese o) $ \file -> ifM (checkFileMatcher matcher file <||> Annex.getState Annex.force)
+ let gofile file = ifM (checkFileMatcher matcher file <||> Annex.getState Annex.force)
( start file
, startSmall file
)
- go $ withFilesNotInGit (not $ includeDotFiles o)
- ifM (versionSupportsUnlockedPointers <||> isDirect)
- ( go withFilesMaybeModified
- , go withFilesOldUnlocked
- )
+ case batchOption o of
+ Batch -> batchInput Right $
+ batchCommandAction . gofile
+ NoBatch -> do
+ let go a = a gofile (addThese o)
+ go (withFilesNotInGit (not $ includeDotFiles o))
+ ifM (versionSupportsUnlockedPointers <||> isDirect)
+ ( go withFilesMaybeModified
+ , go withFilesOldUnlocked
+ )
{- Pass file off to git-add. -}
startSmall :: FilePath -> CommandStart
diff --git a/debian/changelog b/debian/changelog
index 657c3c7cf..81c1f3e6f 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: Support --batch mode.
+ * info, add: 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-add.mdwn b/doc/git-annex-add.mdwn
index 382ea1e6f..5f1ab33b0 100644
--- a/doc/git-annex-add.mdwn
+++ b/doc/git-annex-add.mdwn
@@ -8,8 +8,9 @@ git annex add `[path ...]`
# DESCRIPTION
-Adds files in the path to the annex. If no path is specified, adds
-files from the current directory and below.
+Adds the specified files to the annex. If a directory is specified,
+acts on all files inside the directory and its subdirectories.
+If no path is specified, adds files from the current directory and below.
Files that are already checked into git and are unmodified, or that
git has been configured to ignore will be silently skipped.
@@ -59,6 +60,15 @@ annexed content, and other symlinks.
Enable JSON output. This is intended to be parsed by programs that use
git-annex. Each line of output is a JSON object.
+* `--batch`
+
+ Enables batch mode, in which a file to add is read in a line from stdin,
+ the file is added, and repeat.
+
+ Note that if a file is skipped (due to not existing, being gitignored,
+ already being in git etc), an empty line will be output instead of the
+ normal output produced when adding a file.
+
# SEE ALSO
[[git-annex]](1)
diff --git a/doc/todo/--batch_for_add.mdwn b/doc/todo/--batch_for_add.mdwn
index 1f009074b..c0450c11f 100644
--- a/doc/todo/--batch_for_add.mdwn
+++ b/doc/todo/--batch_for_add.mdwn
@@ -1,3 +1,7 @@
should be extremely helpful when adding many files one at a time ;)
[[!meta author=yoh]]
+
+> Implemented; made it not recurse into directories and output a blank line
+> if it doesn't add the file, so there's aways 1 line of output for each
+> input. [[done]] --[[Joey]]