#endif
import Utility.InodeCache
import Utility.Url
-#ifdef WITH_CONCURRENTOUTPUT
-import System.Console.Regions (ConsoleRegion)
-#endif
import "mtl" Control.Monad.Reader
import Control.Concurrent
, existinghooks :: M.Map Git.Hook.Hook Bool
, desktopnotify :: DesktopNotify
, workers :: [Either AnnexState (Async AnnexState)]
-#ifdef WITH_CONCURRENTOUTPUT
- , consoleregion :: Maybe ConsoleRegion
- , consoleregionerrflag :: Bool
-#endif
+ , concurrentjobs :: Maybe Int
}
newState :: GitConfig -> Git.Repo -> AnnexState
, existinghooks = M.empty
, desktopnotify = mempty
, workers = []
-#ifdef WITH_CONCURRENTOUTPUT
- , consoleregion = Nothing
- , consoleregionerrflag = True
-#endif
+ , concurrentjobs = Nothing
}
{- Makes an Annex state object for the specified git repo.
import Annex.Environment
import Command
import Types.Messages
-import Messages.Internal
{- Runs the passed command line. -}
dispatch :: Bool -> CmdParams -> [Command] -> [GlobalOption] -> [(String, String)] -> IO Git.Repo -> String -> String -> IO ()
whenM (annexDebug <$> Annex.getGitConfig) $
liftIO enableDebugOutput
startup
- withConcurrentOutput $
- performCommandAction cmd seek $
- shutdown $ cmdnocommit cmd
+ performCommandAction cmd seek $
+ shutdown $ cmdnocommit cmd
go (Left norepo) = do
let ingitrepo = \a -> a =<< Git.Config.global
-- Parse command line with full cmdparser first,
else do
l <- liftIO $ drainTo (n-1) ws
findFreeSlot l
- w <- liftIO $ async $ snd <$> Annex.run st run
+ w <- liftIO $ async
+ $ snd <$> Annex.run st (inOwnConsoleRegion run)
Annex.changeState $ \s -> s { Annex.workers = Right w:ws' }
go _ = run
run = void $ includeCommandAction a
<> hidden
)
+-- Note that a command that adds this option should wrap its seek
+-- action in `allowConcurrentOutput`.
jobsOption :: GlobalOption
-jobsOption = globalSetter (Annex.setOutput . ConcurrentOutput) $
+jobsOption = globalSetter set $
option auto
( long "jobs" <> short 'J' <> metavar paramNumber
<> help "enable concurrent jobs"
<> hidden
)
+ where
+ set n = Annex.changeState $ \s -> s { Annex.concurrentjobs = Just n }
timeLimitOption :: GlobalOption
timeLimitOption = globalSetter Limit.addTimeLimit $ strOption
whenAnnexed,
ifAnnexed,
isBareRepo,
+ allowConcurrentOutput,
module ReExported
) where
import CmdLine.GlobalSetter as ReExported
import CmdLine.GitAnnex.Options as ReExported
import Options.Applicative as ReExported hiding (command)
+import Messages.Internal (allowConcurrentOutput)
import qualified Options.Applicative as O
<*> optional (parseKeyOptions True)
seek :: GetOptions -> CommandSeek
-seek o = do
+seek o = allowConcurrentOutput $ do
from <- maybe (pure Nothing) (Just <$$> getParsed) (getFrom o)
withKeyOptions (keyOptions o) (autoMode o)
(startKeys from)
<*> pure (keyOptions v)
seek :: MirrorOptions -> CommandSeek
-seek o = withKeyOptions (keyOptions o) False
- (startKey o Nothing)
- (withFilesInGit $ whenAnnexed $ start o)
- (mirrorFiles o)
+seek o = allowConcurrentOutput $
+ withKeyOptions (keyOptions o) False
+ (startKey o Nothing)
+ (withFilesInGit $ whenAnnexed $ start o)
+ (mirrorFiles o)
start :: MirrorOptions -> FilePath -> Key -> CommandStart
start o file = startKey o (Just file)
<*> pure (keyOptions v)
seek :: MoveOptions -> CommandSeek
-seek o = withKeyOptions (keyOptions o) False
- (startKey o True)
- (withFilesInGit $ whenAnnexed $ start o True)
- (moveFiles o)
+seek o = allowConcurrentOutput $
+ withKeyOptions (keyOptions o) False
+ (startKey o True)
+ (withFilesInGit $ whenAnnexed $ start o True)
+ (moveFiles o)
start :: MoveOptions -> Bool -> FilePath -> Key -> CommandStart
start o move = start' o move . Just
<*> optional parseAllOption
seek :: SyncOptions -> CommandSeek
-seek o = do
+seek o = allowConcurrentOutput $ do
prepMerge
-- There may not be a branch checked out until after the commit,
{-# OPTIONS_GHC -fno-warn-orphans #-}
-{- git-annex output messages, including concurrent output
+{- git-annex output messages, including concurrent output to display regions
-
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
-
-}
concurrentMessage :: Bool -> String -> Annex () -> Annex ()
#ifdef WITH_CONCURRENTOUTPUT
-concurrentMessage iserror msg _ = go =<< Annex.getState Annex.consoleregion
+concurrentMessage iserror msg _ = go =<< consoleRegion <$> Annex.getState Annex.output
where
go Nothing
| iserror = liftIO $ Console.errorConcurrent msg
- | otherwise = liftIO $ Console.outputConcurrent msg
+ | otherwise = do
+ liftIO $ Console.outputConcurrent ("REGION MESSAGE NO REGION" ++ show msg)
+ liftIO $ Console.outputConcurrent msg
go (Just r) = do
+ liftIO $ Console.outputConcurrent ("REGION MESSAGE " ++ show msg)
-- Can't display the error to stdout while
-- console regions are in use, so set the errflag
-- to get it to display to stderr later.
- when iserror $
- Annex.changeState $ \s -> s { Annex.consoleregionerrflag = True }
+ when iserror $ do
+ Annex.changeState $ \s ->
+ s { Annex.output = (Annex.output s) { consoleRegionErrFlag = True } }
liftIO $ Regions.appendConsoleRegion r msg
#else
concurrentMessage _ _ fallback = fallback
#endif
-{- Enable concurrent output when that has been requested.
- -
- - This should only be run once per git-annex lifetime, with
- - everything that might generate messages run inside it.
- -}
-withConcurrentOutput :: Annex a -> Annex a
+{- Do concurrent output when that has been requested. -}
+allowConcurrentOutput :: Annex a -> Annex a
#ifdef WITH_CONCURRENTOUTPUT
-withConcurrentOutput a = withOutputType go
+allowConcurrentOutput a = go =<< Annex.getState Annex.concurrentjobs
where
- go (ConcurrentOutput _) = Console.withConcurrentOutput a
- go _ = a
+ go (Just n) = Regions.displayConsoleRegions $ bracket_
+ (Annex.setOutput (ConcurrentOutput n))
+ (Annex.setOutput NormalOutput)
+ a
+ go Nothing = a
#else
-withConcurrentOutput = id
+allowConcurrentOutput = id
#endif
{- Runs an action in its own dedicated region of the console.
setregion (Just r)
a `finally` removeregion r
where
- setregion v = Annex.changeState $ \s -> s { Annex.consoleregion = v }
+ setregion r = Annex.changeState $ \s -> s { Annex.output = (Annex.output s) { consoleRegion = r } }
removeregion r = do
- errflag <- Annex.getState Annex.consoleregionerrflag
+ errflag <- consoleRegionErrFlag <$> Annex.getState Annex.output
let h = if errflag then Console.StdErr else Console.StdOut
- Annex.changeState $ \s -> s { Annex.consoleregionerrflag = False }
+ Annex.changeState $ \s ->
+ s { Annex.output = (Annex.output s) { consoleRegionErrFlag = False } }
setregion Nothing
liftIO $ atomically $ do
t <- Regions.getConsoleRegion r
return r
#else
-- Old progress bar code, not suitable for concurrent output.
- go _ (ConcurrentOutput _) = do
- r <- nometer
- liftIO $ putStrLn $ fromMaybe (key2file key) af
- return r
+ go _ (ConcurrentOutput _) = nometer
go size NormalOutput = do
showOutput
progress <- liftIO $ newProgress "" size
- Licensed under the GNU GPL version 3 or higher.
-}
+{-# LANGUAGE CPP #-}
+
module Types.Messages where
import Data.Default
+#ifdef WITH_CONCURRENTOUTPUT
+import System.Console.Regions (ConsoleRegion)
+#endif
+
data OutputType = NormalOutput | QuietOutput | ConcurrentOutput Int | JSONOutput
+ deriving (Show)
data SideActionBlock = NoBlock | StartBlock | InBlock
deriving (Eq)
data MessageState = MessageState
{ outputType :: OutputType
, sideActionBlock :: SideActionBlock
+ , consoleRegion :: Maybe ConsoleRegion
+ , consoleRegionErrFlag :: Bool
}
instance Default MessageState
where
- def = MessageState NormalOutput NoBlock
+ def = MessageState NormalOutput NoBlock Nothing False