From 0434674c85d7c31a1d29561131340f7c8a96b101 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 4 Jun 2021 13:16:48 -0400 Subject: [PATCH] avoid displaying the scanning annexed files message when repo is not large Avoids users thinking this scan is a big deal, when it's not in the majority of repos. showSideActionAfter has some ugly caveats, since it has to display in the background of another action. I could not see a better way to do it and it works fine in this particular case. It also doesn't really belong in Annex.Concurrent, but cannot go in Messages due to an import loop. Sponsored-by: Dartmouth College's Datalad project --- Annex/Concurrent.hs | 24 ++++++++++++++++++- Annex/Init.hs | 5 ++-- Utility/ThreadScheduler.hs | 1 + ..._2cbfb22e8f1d89d4f78ade565554cb1c._comment | 9 +++++++ 4 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 doc/todo/init__58__do_not_bother_scanning_if_in_git-annex_branch/comment_2_2cbfb22e8f1d89d4f78ade565554cb1c._comment 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.. +"""]] -- 2.30.2