summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-13 15:35:04 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-13 15:35:04 -0400
commit91546b8c484bf5b40bc9cafcba72679378b2d60a (patch)
tree86ba4a5d3a977ea579cd3c9c0b97212af81fef79
parent189e261a42020f6980854cfd4e0bcd32941455b5 (diff)
Make all --batch input, as well as fromkey and registerurl stdin be processed without requiring it to be in the current encoding.
-rw-r--r--CHANGELOG2
-rw-r--r--CmdLine/Batch.hs17
-rw-r--r--Command/FromKey.hs2
-rw-r--r--Command/RegisterUrl.hs2
-rw-r--r--doc/bugs/git-annex_fromkey_barfs_on_utf-8_input.mdwn4
5 files changed, 18 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 4bd69705b..044ab199b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,8 @@ git-annex (6.20161211) UNRELEASED; urgency=medium
with too many old versions of ssh and unusual ssh configurations.
It should have not been needed anyway since ssh is supposted to
have TCPKeepAlive enabled by default.
+ * Make all --batch input, as well as fromkey and registerurl stdin
+ be processed without requiring it to be in the current encoding.
-- Joey Hess <id@joeyh.name> Sun, 11 Dec 2016 21:29:51 -0400
diff --git a/CmdLine/Batch.hs b/CmdLine/Batch.hs
index 627c1df10..6ef21372f 100644
--- a/CmdLine/Batch.hs
+++ b/CmdLine/Batch.hs
@@ -48,16 +48,19 @@ batchBadInput Batch = liftIO $ putStrLn ""
-- Reads lines of batch mode input and passes to the action to handle.
batchInput :: (String -> Either String a) -> (a -> Annex ()) -> Annex ()
-batchInput parser a = do
- mp <- liftIO $ catchMaybeIO getLine
- case mp of
- Nothing -> return ()
- Just v -> do
- either parseerr a (parser v)
- batchInput parser a
+batchInput parser a = go =<< batchLines
where
+ go [] = return ()
+ go (l:rest) = do
+ either parseerr a (parser l)
+ go rest
parseerr s = giveup $ "Batch input parse failure: " ++ s
+batchLines :: Annex [String]
+batchLines = liftIO $ do
+ fileEncoding stdin
+ lines <$> getContents
+
-- Runs a CommandStart in batch mode.
--
-- The batch mode user expects to read a line of output, and it's up to the
diff --git a/Command/FromKey.hs b/Command/FromKey.hs
index dca63aabe..c1e3a7965 100644
--- a/Command/FromKey.hs
+++ b/Command/FromKey.hs
@@ -45,7 +45,7 @@ startMass = do
next massAdd
massAdd :: CommandPerform
-massAdd = go True =<< map (separate (== ' ')) . lines <$> liftIO getContents
+massAdd = go True =<< map (separate (== ' ')) <$> batchLines
where
go status [] = next $ return status
go status ((keyname,f):rest) | not (null keyname) && not (null f) = do
diff --git a/Command/RegisterUrl.hs b/Command/RegisterUrl.hs
index 28dd2d8c5..008e6436c 100644
--- a/Command/RegisterUrl.hs
+++ b/Command/RegisterUrl.hs
@@ -35,7 +35,7 @@ start [] = do
start _ = giveup "specify a key and an url"
massAdd :: CommandPerform
-massAdd = go True =<< map (separate (== ' ')) . lines <$> liftIO getContents
+massAdd = go True =<< map (separate (== ' ')) <$> batchLines
where
go status [] = next $ return status
go status ((keyname,u):rest) | not (null keyname) && not (null u) = do
diff --git a/doc/bugs/git-annex_fromkey_barfs_on_utf-8_input.mdwn b/doc/bugs/git-annex_fromkey_barfs_on_utf-8_input.mdwn
index c1f71789b..e544015a6 100644
--- a/doc/bugs/git-annex_fromkey_barfs_on_utf-8_input.mdwn
+++ b/doc/bugs/git-annex_fromkey_barfs_on_utf-8_input.mdwn
@@ -32,3 +32,7 @@ Note that this is indeed valid utf-8:
00000000 c3 a9 0a |...|
00000003
"""]]
+
+> Despite my strange inability to reproduce these, there's really only one
+> thing that can fix it, namely using fileEncoding. Now done for all batch
+> and stdin reading stuff. [[fixed|done]] I suppose. --[[Joey]]