Make --json-progress output be shown even when the size of a object is not known.
This commit is contained in:
parent
7cd6a6a39c
commit
28c6209f55
4 changed files with 27 additions and 15 deletions
|
@ -7,6 +7,8 @@ git-annex (6.20160924) UNRELEASED; urgency=medium
|
||||||
"git-annex find --in remote" by over 50%.
|
"git-annex find --in remote" by over 50%.
|
||||||
* Optimised git-annex branch log file timestamp parsing.
|
* Optimised git-annex branch log file timestamp parsing.
|
||||||
* Add "total-size" field to --json-progress output.
|
* 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
|
-- Joey Hess <id@joeyh.name> Mon, 26 Sep 2016 16:46:19 -0400
|
||||||
|
|
||||||
|
|
|
@ -95,17 +95,20 @@ complete v _ = add v (Just (HM.empty, True))
|
||||||
|
|
||||||
-- Show JSON formatted progress, including the current state of the JSON
|
-- Show JSON formatted progress, including the current state of the JSON
|
||||||
-- object for the action being performed.
|
-- object for the action being performed.
|
||||||
progress :: Maybe Object -> Integer -> BytesProcessed -> IO ()
|
progress :: Maybe Object -> Maybe Integer -> BytesProcessed -> IO ()
|
||||||
progress maction size bytesprocessed = emit $ case maction of
|
progress maction msize bytesprocessed = emit $ case maction of
|
||||||
Just action -> HM.insert "action" (Object action) o
|
Just action -> HM.insert "action" (Object action) o
|
||||||
Nothing -> o
|
Nothing -> o
|
||||||
where
|
where
|
||||||
n = fromBytesProcessed bytesprocessed :: Integer
|
n = fromBytesProcessed bytesprocessed :: Integer
|
||||||
Object o = object
|
Object o = case msize of
|
||||||
[ "byte-progress" .= n
|
Just size -> object
|
||||||
, "percent-progress" .= showPercentage 2 (percentage size n)
|
[ "byte-progress" .= n
|
||||||
, "total-size" .= size
|
, "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.
|
-- A value that can be displayed either normally, or as JSON.
|
||||||
data DualDisp = DualDisp
|
data DualDisp = DualDisp
|
||||||
|
|
|
@ -30,12 +30,10 @@ import Data.Quantity
|
||||||
{- Shows a progress meter while performing a transfer of a key.
|
{- Shows a progress meter while performing a transfer of a key.
|
||||||
- The action is passed a callback to use to update the meter. -}
|
- The action is passed a callback to use to update the meter. -}
|
||||||
metered :: Maybe MeterUpdate -> Key -> (MeterUpdate -> Annex a) -> Annex a
|
metered :: Maybe MeterUpdate -> Key -> (MeterUpdate -> Annex a) -> Annex a
|
||||||
metered othermeter key a = case keySize key of
|
metered othermeter key a = withMessageState $ go (keySize key)
|
||||||
Nothing -> nometer
|
|
||||||
Just size -> withMessageState (go $ fromInteger size)
|
|
||||||
where
|
where
|
||||||
go _ (MessageState { outputType = QuietOutput }) = nometer
|
go _ (MessageState { outputType = QuietOutput }) = nometer
|
||||||
go size (MessageState { outputType = NormalOutput, concurrentOutputEnabled = False }) = do
|
go (Just size) (MessageState { outputType = NormalOutput, concurrentOutputEnabled = False }) = do
|
||||||
showOutput
|
showOutput
|
||||||
(progress, meter) <- mkmeter size
|
(progress, meter) <- mkmeter size
|
||||||
m <- liftIO $ rateLimitMeterUpdate 0.1 (Just size) $ \n -> do
|
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)
|
r <- a (combinemeter m)
|
||||||
liftIO $ clearMeter stdout meter
|
liftIO $ clearMeter stdout meter
|
||||||
return r
|
return r
|
||||||
go size (MessageState { outputType = NormalOutput, concurrentOutputEnabled = True }) =
|
go (Just size) (MessageState { outputType = NormalOutput, concurrentOutputEnabled = True }) =
|
||||||
#if WITH_CONCURRENTOUTPUT
|
#if WITH_CONCURRENTOUTPUT
|
||||||
withProgressRegion $ \r -> do
|
withProgressRegion $ \r -> do
|
||||||
(progress, meter) <- mkmeter size
|
(progress, meter) <- mkmeter size
|
||||||
|
@ -57,10 +55,10 @@ metered othermeter key a = case keySize key of
|
||||||
nometer
|
nometer
|
||||||
#endif
|
#endif
|
||||||
go _ (MessageState { outputType = JSONOutput False }) = nometer
|
go _ (MessageState { outputType = JSONOutput False }) = nometer
|
||||||
go size (MessageState { outputType = JSONOutput True }) = do
|
go msize (MessageState { outputType = JSONOutput True }) = do
|
||||||
buf <- withMessageState $ return . jsonBuffer
|
buf <- withMessageState $ return . jsonBuffer
|
||||||
m <- liftIO $ rateLimitMeterUpdate 0.1 (Just size) $
|
m <- liftIO $ rateLimitMeterUpdate 0.1 msize $
|
||||||
JSON.progress buf size
|
JSON.progress buf msize
|
||||||
a (combinemeter m)
|
a (combinemeter m)
|
||||||
|
|
||||||
mkmeter size = do
|
mkmeter size = do
|
||||||
|
|
|
@ -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.
|
||||||
|
"""]]
|
Loading…
Add table
Add a link
Reference in a new issue