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
This commit is contained in:
Joey Hess 2021-06-04 13:16:48 -04:00
parent 95cec1bdfe
commit 0434674c85
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 36 additions and 3 deletions

View file

@ -1,6 +1,6 @@
{- git-annex concurrent state
-
- Copyright 2015-2020 Joey Hess <id@joeyh.name>
- Copyright 2015-2021 Joey Hess <id@joeyh.name>
-
- 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

View file

@ -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

View file

@ -15,6 +15,7 @@ module Utility.ThreadScheduler (
threadDelaySeconds,
waitForTermination,
oneSecond,
unboundDelay,
) where
import Control.Monad

View file

@ -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..
"""]]