Make --json-progress output be shown even when the size of a object is not known.
authorJoey Hess <joeyh@joeyh.name>
Thu, 29 Sep 2016 20:59:48 +0000 (16:59 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 29 Sep 2016 20:59:48 +0000 (16:59 -0400)
CHANGELOG
Messages/JSON.hs
Messages/Progress.hs
doc/todo/interface_to_the___34__progress__34___of_annex_operations/comment_9_32bfa465567eaad105a8336bc247cc2f._comment [new file with mode: 0644]

index c36fcb74f829950debb4c21b3cce12025a563b69..888e413e94cde1fe627d0526ea1d7e55e104120d 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,8 @@ git-annex (6.20160924) UNRELEASED; urgency=medium
     "git-annex find --in remote" by over 50%.
   * Optimised git-annex branch log file timestamp parsing.
   * Add "total-size" field to --json-progress output.
+  * Make --json-progress output be shown even when the size of a object
+    is not known.
 
  -- Joey Hess <id@joeyh.name>  Mon, 26 Sep 2016 16:46:19 -0400
 
index fb288b7359362b1b1372c56b0cd28d031c3d89f4..06bdd9a4d8a306b42bacfb615110478928586456 100644 (file)
@@ -95,17 +95,20 @@ complete v _ = add v (Just (HM.empty, True))
 
 -- Show JSON formatted progress, including the current state of the JSON 
 -- object for the action being performed.
-progress :: Maybe Object -> Integer -> BytesProcessed -> IO ()
-progress maction size bytesprocessed = emit $ case maction of
+progress :: Maybe Object -> Maybe Integer -> BytesProcessed -> IO ()
+progress maction msize bytesprocessed = emit $ case maction of
        Just action -> HM.insert "action" (Object action) o
        Nothing -> o
   where
        n = fromBytesProcessed bytesprocessed :: Integer
-       Object o = object
-               [ "byte-progress" .= n
-               , "percent-progress" .= showPercentage 2 (percentage size n)
-               , "total-size" .= size
-               ]
+       Object o = case msize of
+               Just size -> object
+                       [ "byte-progress" .= n
+                       , "percent-progress" .= showPercentage 2 (percentage size n)
+                       , "total-size" .= size
+                       ]
+               Nothing -> object
+                       [ "byte-progress" .= n ]
 
 -- A value that can be displayed either normally, or as JSON.
 data DualDisp = DualDisp
index f21ccae0b16a6572e00d43ad381e7f72ae8bda30..06f2531be01f7e95d781694e0ab32e50e060d2e3 100644 (file)
@@ -30,12 +30,10 @@ import Data.Quantity
 {- Shows a progress meter while performing a transfer of a key.
  - The action is passed a callback to use to update the meter. -}
 metered :: Maybe MeterUpdate -> Key -> (MeterUpdate -> Annex a) -> Annex a
-metered othermeter key a = case keySize key of
-       Nothing -> nometer
-       Just size -> withMessageState (go $ fromInteger size)
+metered othermeter key a = withMessageState $ go (keySize key)
   where
        go _ (MessageState { outputType = QuietOutput }) = nometer
-       go size (MessageState { outputType = NormalOutput, concurrentOutputEnabled = False }) = do
+       go (Just size) (MessageState { outputType = NormalOutput, concurrentOutputEnabled = False }) = do
                showOutput
                (progress, meter) <- mkmeter size
                m <- liftIO $ rateLimitMeterUpdate 0.1 (Just size) $ \n -> do
@@ -44,7 +42,7 @@ metered othermeter key a = case keySize key of
                r <- a (combinemeter m)
                liftIO $ clearMeter stdout meter
                return r
-       go size (MessageState { outputType = NormalOutput, concurrentOutputEnabled = True }) =
+       go (Just size) (MessageState { outputType = NormalOutput, concurrentOutputEnabled = True }) =
 #if WITH_CONCURRENTOUTPUT
                withProgressRegion $ \r -> do
                        (progress, meter) <- mkmeter size
@@ -57,10 +55,10 @@ metered othermeter key a = case keySize key of
                nometer
 #endif
        go _ (MessageState { outputType = JSONOutput False }) = nometer
-       go size (MessageState { outputType = JSONOutput True }) = do
+       go msize (MessageState { outputType = JSONOutput True }) = do
                buf <- withMessageState $ return . jsonBuffer
-               m <- liftIO $ rateLimitMeterUpdate 0.1 (Just size) $
-                       JSON.progress buf size
+               m <- liftIO $ rateLimitMeterUpdate 0.1 msize $
+                       JSON.progress buf msize
                a (combinemeter m)
 
        mkmeter size = do
diff --git a/doc/todo/interface_to_the___34__progress__34___of_annex_operations/comment_9_32bfa465567eaad105a8336bc247cc2f._comment b/doc/todo/interface_to_the___34__progress__34___of_annex_operations/comment_9_32bfa465567eaad105a8336bc247cc2f._comment
new file mode 100644 (file)
index 0000000..280cb31
--- /dev/null
@@ -0,0 +1,9 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 9"""
+ date="2016-09-29T20:58:13Z"
+ content="""
+Gone ahead and made --json-progress be displayed when size is not known,
+although of course it then has to omit the total-size and percent-progress
+fields.
+"""]]