added -z
Added -z option to git-annex commands that use --batch, useful for supporting filenames containing newlines. It only controls input to --batch, the output will still be line delimited unless --json or etc is used to get some other output. While git often makes -z affect both input and output, I don't like trying them together, and making it affect output would have been a significant complication, and also git-annex output is generally not intended to be machine parsed, unless using --json or a format option. Commands that take pairs like "file key" still separate them with a space in --batch mode. All such commands take care to support filenames with spaces when parsing that, so there was no need to change it, and it would have needed significant changes to the batch machinery to separate tose with a null. To make fromkey and registerurl support -z, I had to give them a --batch option. The implicit batch mode they enter when not provided with input parameters does not support -z as that would have complicated option parsing. Seemed better to move these toward using the same --batch as everything else, though the implicit batch mode can still be used. This commit was sponsored by Ole-Morten Duesund on Patreon.
This commit is contained in:
parent
2aae6e84af
commit
1d1054faa6
34 changed files with 209 additions and 67 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex command
|
||||
-
|
||||
- Copyright 2010, 2015 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2018 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -21,13 +21,26 @@ cmd :: Command
|
|||
cmd = notDirect $ notBareRepo $
|
||||
command "fromkey" SectionPlumbing "adds a file using a specific key"
|
||||
(paramRepeating (paramPair paramKey paramPath))
|
||||
(withParams seek)
|
||||
(seek <$$> optParser)
|
||||
|
||||
seek :: CmdParams -> CommandSeek
|
||||
seek [] = withNothing startMass []
|
||||
seek ps = do
|
||||
force <- Annex.getState Annex.force
|
||||
withPairs (start force) ps
|
||||
data FromKeyOptions = FromKeyOptions
|
||||
{ keyFilePairs :: CmdParams
|
||||
, batchOption :: BatchMode
|
||||
}
|
||||
|
||||
optParser :: CmdParamsDesc -> Parser FromKeyOptions
|
||||
optParser desc = FromKeyOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
|
||||
seek :: FromKeyOptions -> CommandSeek
|
||||
seek o = case (batchOption o, keyFilePairs o) of
|
||||
(Batch fmt, _) -> withNothing (startMass fmt) []
|
||||
-- older way of enabling batch input, does not support BatchNull
|
||||
(NoBatch, []) -> withNothing (startMass BatchLine) []
|
||||
(NoBatch, ps) -> do
|
||||
force <- Annex.getState Annex.force
|
||||
withPairs (start force) ps
|
||||
|
||||
start :: Bool -> (String, FilePath) -> CommandStart
|
||||
start force (keyname, file) = do
|
||||
|
@ -39,13 +52,13 @@ start force (keyname, file) = do
|
|||
showStart "fromkey" file
|
||||
next $ perform key file
|
||||
|
||||
startMass :: CommandStart
|
||||
startMass = do
|
||||
startMass :: BatchFormat -> CommandStart
|
||||
startMass fmt = do
|
||||
showStart' "fromkey" (Just "stdin")
|
||||
next massAdd
|
||||
next (massAdd fmt)
|
||||
|
||||
massAdd :: CommandPerform
|
||||
massAdd = go True =<< map (separate (== ' ')) <$> batchLines
|
||||
massAdd :: BatchFormat -> CommandPerform
|
||||
massAdd fmt = go True =<< map (separate (== ' ')) <$> batchLines fmt
|
||||
where
|
||||
go status [] = next $ return status
|
||||
go status ((keyname,f):rest) | not (null keyname) && not (null f) = do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue