diff --git a/Annex/Concurrent.hs b/Annex/Concurrent.hs index f341e21d0d..cb22b6a463 100644 --- a/Annex/Concurrent.hs +++ b/Annex/Concurrent.hs @@ -1,6 +1,6 @@ {- git-annex concurrent state - - - Copyright 2015-2020 Joey Hess + - Copyright 2015-2021 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -19,8 +19,10 @@ import Types.Concurrency import Types.CatFileHandles import Annex.CheckAttr import Annex.CheckIgnore +import Utility.ThreadScheduler import qualified Data.Map as M +import Control.Concurrent.Async setConcurrency :: ConcurrencySetting -> Annex () setConcurrency (ConcurrencyCmdLine s) = setConcurrency' s ConcurrencyCmdLine @@ -98,3 +100,23 @@ mergeState st = do uncurry addCleanupAction Annex.Queue.mergeFrom st' changeState $ \s -> s { errcounter = errcounter s + errcounter st' } + +{- Display a message, only when the action runs for a long enough + - amount of time. + - + - The action should not display any other messages, progress, etc; + - if it did there could be some scrambling of the display since the + - message display could happen at the same time as other output, + - or after it. + -} +showSideActionAfter :: Microseconds -> String -> Annex a -> Annex a +showSideActionAfter t m a = do + waiter <- liftIO $ async $ unboundDelay t + let display = liftIO (waitCatch waiter) >>= \case + Left _ -> return () + Right _ -> showSideAction m + displayer <- liftIO . async =<< forkState display + let cleanup = do + liftIO $ cancel waiter + join (liftIO (wait displayer)) + a `finally` cleanup diff --git a/Annex/Init.hs b/Annex/Init.hs index 124e28865b..4bd0955eaa 100644 --- a/Annex/Init.hs +++ b/Annex/Init.hs @@ -37,6 +37,7 @@ import Annex.UUID import Annex.WorkTree import Annex.Fixup import Annex.Path +import Annex.Concurrent import Config import Config.Files import Config.Smudge @@ -133,8 +134,8 @@ initialize' mversion = checkInitializeAllowed $ do then configureSmudgeFilter else deconfigureSmudgeFilter unlessM isBareRepo $ do - showSideAction "scanning for annexed files" - scanAnnexedFiles + showSideActionAfter oneSecond "scanning for annexed files" $ + scanAnnexedFiles hookWrite postCheckoutHook hookWrite postMergeHook AdjustedBranch.checkAdjustedClone >>= \case diff --git a/Utility/ThreadScheduler.hs b/Utility/ThreadScheduler.hs index ef69ead81f..9ab94d911e 100644 --- a/Utility/ThreadScheduler.hs +++ b/Utility/ThreadScheduler.hs @@ -15,6 +15,7 @@ module Utility.ThreadScheduler ( threadDelaySeconds, waitForTermination, oneSecond, + unboundDelay, ) where import Control.Monad diff --git a/doc/todo/init__58__do_not_bother_scanning_if_in_git-annex_branch/comment_2_2cbfb22e8f1d89d4f78ade565554cb1c._comment b/doc/todo/init__58__do_not_bother_scanning_if_in_git-annex_branch/comment_2_2cbfb22e8f1d89d4f78ade565554cb1c._comment new file mode 100644 index 0000000000..0142d78551 --- /dev/null +++ b/doc/todo/init__58__do_not_bother_scanning_if_in_git-annex_branch/comment_2_2cbfb22e8f1d89d4f78ade565554cb1c._comment @@ -0,0 +1,9 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 2""" + date="2021-06-04T17:14:42Z" + content=""" +Made the scanning message not be displayed unless it takes at least 1 +second. Of course, if some test suite is still looking at that message, +it will break.. +"""]]