2014-01-29 17:44:53 +00:00
|
|
|
{- git-annex command-line actions
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
-
|
2015-04-10 21:08:07 +00:00
|
|
|
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2015-11-05 21:22:45 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2014-01-29 17:44:53 +00:00
|
|
|
module CmdLine.Action where
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
import qualified Annex
|
2015-04-10 21:53:58 +00:00
|
|
|
import Annex.Concurrent
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
import Types.Command
|
2016-09-09 16:57:42 +00:00
|
|
|
import Types.Concurrency
|
2015-11-05 21:22:45 +00:00
|
|
|
import Messages.Concurrent
|
2015-04-10 21:08:07 +00:00
|
|
|
import Types.Messages
|
2017-05-25 22:27:01 +00:00
|
|
|
import Remote.List
|
2015-04-10 21:08:07 +00:00
|
|
|
|
|
|
|
import Control.Concurrent.Async
|
|
|
|
import Control.Exception (throwIO)
|
|
|
|
import Data.Either
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
|
2015-11-05 21:22:45 +00:00
|
|
|
#ifdef WITH_CONCURRENTOUTPUT
|
|
|
|
import qualified System.Console.Regions as Regions
|
|
|
|
#endif
|
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
{- Runs a command, starting with the check stage, and then
|
2014-12-30 16:49:34 +00:00
|
|
|
- the seek stage. Finishes by running the continutation, and
|
|
|
|
- then showing a count of any failures. -}
|
2015-07-08 16:33:27 +00:00
|
|
|
performCommandAction :: Command -> CommandSeek -> Annex () -> Annex ()
|
|
|
|
performCommandAction Command { cmdcheck = c, cmdname = name } seek cont = do
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
mapM_ runCheck c
|
|
|
|
Annex.changeState $ \s -> s { Annex.errcounter = 0 }
|
2015-07-08 16:33:27 +00:00
|
|
|
seek
|
2015-04-10 21:08:07 +00:00
|
|
|
finishCommandActions
|
2014-12-30 16:49:34 +00:00
|
|
|
cont
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
showerrcount =<< Annex.getState Annex.errcounter
|
|
|
|
where
|
|
|
|
showerrcount 0 = noop
|
2016-11-16 01:29:54 +00:00
|
|
|
showerrcount cnt = giveup $ name ++ ": " ++ show cnt ++ " failed"
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
|
|
|
|
{- Runs one of the actions needed to perform a command.
|
|
|
|
- Individual actions can fail without stopping the whole command,
|
|
|
|
- including by throwing IO errors (but other errors terminate the whole
|
|
|
|
- command).
|
|
|
|
-
|
2015-04-10 21:08:07 +00:00
|
|
|
- When concurrency is enabled, a thread is forked off to run the action
|
|
|
|
- in the background, as soon as a free slot is available.
|
|
|
|
|
|
|
|
- This should only be run in the seek stage.
|
|
|
|
-}
|
|
|
|
commandAction :: CommandStart -> Annex ()
|
2016-09-09 16:57:42 +00:00
|
|
|
commandAction a = go =<< Annex.getState Annex.concurrency
|
2015-04-10 21:08:07 +00:00
|
|
|
where
|
2016-09-09 16:57:42 +00:00
|
|
|
go (Concurrent n) = do
|
2015-04-10 21:08:07 +00:00
|
|
|
ws <- Annex.getState Annex.workers
|
|
|
|
(st, ws') <- if null ws
|
|
|
|
then do
|
2017-05-25 22:27:01 +00:00
|
|
|
-- Generate the remote list now, to avoid
|
|
|
|
-- each thread generating it, which would
|
|
|
|
-- be more expensive and could cause
|
|
|
|
-- threads to contend over eg, calls to
|
|
|
|
-- setConfig.
|
|
|
|
_ <- remoteList
|
2015-04-10 21:53:58 +00:00
|
|
|
st <- dupState
|
2015-04-10 21:08:07 +00:00
|
|
|
return (st, replicate (n-1) (Left st))
|
|
|
|
else do
|
|
|
|
l <- liftIO $ drainTo (n-1) ws
|
|
|
|
findFreeSlot l
|
2015-11-04 20:19:00 +00:00
|
|
|
w <- liftIO $ async
|
2016-09-09 16:57:42 +00:00
|
|
|
$ snd <$> Annex.run st (inOwnConsoleRegion (Annex.output st) run)
|
2015-04-10 21:08:07 +00:00
|
|
|
Annex.changeState $ \s -> s { Annex.workers = Right w:ws' }
|
2016-09-09 16:57:42 +00:00
|
|
|
go NonConcurrent = run
|
2015-04-10 21:08:07 +00:00
|
|
|
run = void $ includeCommandAction a
|
|
|
|
|
|
|
|
{- Waits for any forked off command actions to finish.
|
|
|
|
-
|
|
|
|
- Merge together the cleanup actions of all the AnnexStates used by
|
|
|
|
- threads, into the current Annex's state, so they'll run at shutdown.
|
|
|
|
-
|
|
|
|
- Also merge together the errcounters of the AnnexStates.
|
|
|
|
-}
|
|
|
|
finishCommandActions :: Annex ()
|
|
|
|
finishCommandActions = do
|
2015-11-05 21:22:45 +00:00
|
|
|
ws <- Annex.getState Annex.workers
|
|
|
|
Annex.changeState $ \s -> s { Annex.workers = [] }
|
|
|
|
l <- liftIO $ drainTo 0 ws
|
2015-04-10 21:53:58 +00:00
|
|
|
forM_ (lefts l) mergeState
|
2015-04-10 21:08:07 +00:00
|
|
|
|
|
|
|
{- Wait for Asyncs from the list to finish, replacing them with their
|
|
|
|
- final AnnexStates, until the list of remaining Asyncs is not larger
|
|
|
|
- than the specified size, then returns the new list.
|
|
|
|
-
|
|
|
|
- If the action throws an exception, it is propigated, but first
|
|
|
|
- all other actions are waited for, to allow for a clean shutdown.
|
|
|
|
-}
|
|
|
|
drainTo
|
|
|
|
:: Int
|
|
|
|
-> [Either Annex.AnnexState (Async Annex.AnnexState)]
|
|
|
|
-> IO [Either Annex.AnnexState (Async Annex.AnnexState)]
|
|
|
|
drainTo sz l
|
|
|
|
| null as || sz >= length as = return l
|
|
|
|
| otherwise = do
|
|
|
|
(done, ret) <- waitAnyCatch as
|
|
|
|
let as' = filter (/= done) as
|
|
|
|
case ret of
|
|
|
|
Left e -> do
|
|
|
|
void $ drainTo 0 (map Left sts ++ map Right as')
|
|
|
|
throwIO e
|
|
|
|
Right st -> do
|
|
|
|
drainTo sz $ map Left (st:sts) ++ map Right as'
|
|
|
|
where
|
|
|
|
(sts, as) = partitionEithers l
|
|
|
|
|
|
|
|
findFreeSlot :: [Either Annex.AnnexState (Async Annex.AnnexState)] -> Annex (Annex.AnnexState, [Either Annex.AnnexState (Async Annex.AnnexState)])
|
|
|
|
findFreeSlot = go []
|
|
|
|
where
|
|
|
|
go c [] = do
|
2015-04-10 21:53:58 +00:00
|
|
|
st <- dupState
|
2015-04-10 21:08:07 +00:00
|
|
|
return (st, c)
|
|
|
|
go c (Left st:rest) = return (st, c ++ rest)
|
|
|
|
go c (v:rest) = go (v:c) rest
|
|
|
|
|
|
|
|
{- Like commandAction, but without the concurrency. -}
|
|
|
|
includeCommandAction :: CommandStart -> CommandCleanup
|
2016-01-13 18:55:01 +00:00
|
|
|
includeCommandAction a = account =<< tryIO (callCommandAction a)
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
where
|
unify exception handling into Utility.Exception
Removed old extensible-exceptions, only needed for very old ghc.
Made webdav use Utility.Exception, to work after some changes in DAV's
exception handling.
Removed Annex.Exception. Mostly this was trivial, but note that
tryAnnex is replaced with tryNonAsync and catchAnnex replaced with
catchNonAsync. In theory that could be a behavior change, since the former
caught all exceptions, and the latter don't catch async exceptions.
However, in practice, nothing in the Annex monad uses async exceptions.
Grepping for throwTo and killThread only find stuff in the assistant,
which does not seem related.
Command.Add.undo is changed to accept a SomeException, and things
that use it for rollback now catch non-async exceptions, rather than
only IOExceptions.
2014-08-08 01:55:44 +00:00
|
|
|
account (Right True) = return True
|
|
|
|
account (Right False) = incerr
|
|
|
|
account (Left err) = do
|
2015-04-30 19:28:17 +00:00
|
|
|
toplevelWarning True (show err)
|
2016-01-20 18:07:13 +00:00
|
|
|
implicitMessage showEndFail
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
incerr
|
2014-01-20 17:31:03 +00:00
|
|
|
incerr = do
|
2015-04-30 19:04:01 +00:00
|
|
|
Annex.incError
|
2014-01-20 17:31:03 +00:00
|
|
|
return False
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
|
2014-01-20 17:31:03 +00:00
|
|
|
{- Runs a single command action through the start, perform and cleanup
|
|
|
|
- stages, without catching errors. Useful if one command wants to run
|
|
|
|
- part of another command. -}
|
2015-04-10 21:08:07 +00:00
|
|
|
callCommandAction :: CommandStart -> CommandCleanup
|
2016-01-19 21:46:46 +00:00
|
|
|
callCommandAction = fromMaybe True <$$> callCommandAction'
|
|
|
|
|
|
|
|
{- Like callCommandAction, but returns Nothing when the command did not
|
|
|
|
- perform any action. -}
|
|
|
|
callCommandAction' :: CommandStart -> Annex (Maybe Bool)
|
|
|
|
callCommandAction' = start
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
where
|
|
|
|
start = stage $ maybe skip perform
|
|
|
|
perform = stage $ maybe failure cleanup
|
|
|
|
cleanup = stage $ status
|
|
|
|
stage = (=<<)
|
2016-01-19 21:46:46 +00:00
|
|
|
skip = return Nothing
|
2016-01-20 18:07:13 +00:00
|
|
|
failure = implicitMessage showEndFail >> return (Just False)
|
|
|
|
status r = implicitMessage (showEndResult r) >> return (Just r)
|
2015-11-05 21:22:45 +00:00
|
|
|
|
|
|
|
{- Do concurrent output when that has been requested. -}
|
|
|
|
allowConcurrentOutput :: Annex a -> Annex a
|
|
|
|
#ifdef WITH_CONCURRENTOUTPUT
|
2016-09-09 16:57:42 +00:00
|
|
|
allowConcurrentOutput a = go =<< Annex.getState Annex.concurrency
|
2015-11-05 21:22:45 +00:00
|
|
|
where
|
2016-09-09 16:57:42 +00:00
|
|
|
go NonConcurrent = a
|
|
|
|
go (Concurrent _) = ifM (liftIO concurrentOutputSupported)
|
2016-02-14 19:02:42 +00:00
|
|
|
( Regions.displayConsoleRegions $
|
2016-09-09 16:57:42 +00:00
|
|
|
goconcurrent True
|
|
|
|
, goconcurrent False
|
2016-02-14 19:02:42 +00:00
|
|
|
)
|
2016-09-09 16:57:42 +00:00
|
|
|
goconcurrent b = bracket_ (setup b) cleanup a
|
|
|
|
setup = setconcurrentenabled
|
2015-11-05 21:22:45 +00:00
|
|
|
cleanup = do
|
|
|
|
finishCommandActions
|
2016-09-09 16:57:42 +00:00
|
|
|
setconcurrentenabled False
|
|
|
|
setconcurrentenabled b = Annex.changeState $ \s ->
|
|
|
|
s { Annex.output = (Annex.output s) { concurrentOutputEnabled = b } }
|
2015-11-05 21:22:45 +00:00
|
|
|
#else
|
|
|
|
allowConcurrentOutput = id
|
|
|
|
#endif
|