From d4fbc3b4608914b6de36871419c82fd6462a902b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Sep 2016 16:15:39 -0400 Subject: [PATCH] make --json-progress work for url downloads --- Annex/Content.hs | 2 +- Messages/Progress.hs | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Annex/Content.hs b/Annex/Content.hs index b975c8e909..cb96a0068b 100644 --- a/Annex/Content.hs +++ b/Annex/Content.hs @@ -902,7 +902,7 @@ saveState nocommit = doSideAction $ do {- Downloads content from any of a list of urls. -} downloadUrl :: Key -> MeterUpdate -> [Url.URLString] -> FilePath -> Annex Bool -downloadUrl k p urls file = concurrentMeteredFile file (Just p) k $ +downloadUrl k p urls file = meteredFile file (Just p) k $ go =<< annexWebDownloadCommand <$> Annex.getGitConfig where go Nothing = do diff --git a/Messages/Progress.hs b/Messages/Progress.hs index 14aebe6c9f..f21ccae0b1 100644 --- a/Messages/Progress.hs +++ b/Messages/Progress.hs @@ -75,25 +75,29 @@ metered othermeter key a = case keySize key of Just om -> combineMeterUpdate m om {- Use when the command's own progress output is preferred. - - The command's output will be suppressed and git-annex's progress output + - The command's output will be suppressed and git-annex's progress meter - used for concurrent output, and json progress. -} commandMetered :: Maybe MeterUpdate -> Key -> (MeterUpdate -> Annex a) -> Annex a commandMetered combinemeterupdate key a = - withMessageState $ \s -> case outputType s of - JSONOutput True -> usemeter - NormalOutput | concurrentOutputEnabled s -> usemeter - _ -> a (fromMaybe nullMeterUpdate combinemeterupdate) - where - usemeter = metered combinemeterupdate key a + withMessageState $ \s -> if needOutputMeter s + then metered combinemeterupdate key a + else a (fromMaybe nullMeterUpdate combinemeterupdate) -{- Poll file size to display meter, but only for concurrent output. -} -concurrentMeteredFile :: FilePath -> Maybe MeterUpdate -> Key -> Annex a -> Annex a -concurrentMeteredFile file combinemeterupdate key a = - withMessageState $ \s -> if concurrentOutputEnabled s +{- Poll file size to display meter, but only when concurrent output or + - json progress needs the information. -} +meteredFile :: FilePath -> Maybe MeterUpdate -> Key -> Annex a -> Annex a +meteredFile file combinemeterupdate key a = + withMessageState $ \s -> if needOutputMeter s then metered combinemeterupdate key $ \p -> watchFileSize file p a else a +needOutputMeter :: MessageState -> Bool +needOutputMeter s = case outputType s of + JSONOutput True -> True + NormalOutput | concurrentOutputEnabled s -> True + _ -> False + {- Progress dots. -} showProgressDots :: Annex () showProgressDots = outputMessage JSON.none "."