From 8040ecf9b87bfd595d3bff1d26ef9cc232c4ae4c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 28 Jun 2022 16:02:01 -0400 Subject: [PATCH] final readonly values moves to AnnexRead At this point I've checked all AnnexState values and these were all that remained that could move. Pity that Annex.repo can't move, but it gets modified sometimes.. A couple of AnnexState values are set by options and could be AnnexRead, but happen to use Annex when being set. Sponsored-by: Max Thoursie on Patreon --- Annex.hs | 8 ++++---- Annex/Url.hs | 2 +- CmdLine/GitAnnex/Options.hs | 10 +++++----- doc/todo/move_readonly_values_to_AnnexRead.mdwn | 3 ++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Annex.hs b/Annex.hs index e4fbd51152..81ecb1a833 100644 --- a/Annex.hs +++ b/Annex.hs @@ -126,6 +126,8 @@ data AnnexRead = AnnexRead , forcenumcopies :: Maybe NumCopies , forcemincopies :: Maybe MinCopies , forcebackend :: Maybe String + , useragent :: Maybe String + , desktopnotify :: DesktopNotify } newAnnexRead :: GitConfig -> IO AnnexRead @@ -152,6 +154,8 @@ newAnnexRead c = do , forcebackend = Nothing , forcenumcopies = Nothing , forcemincopies = Nothing + , useragent = Nothing + , desktopnotify = mempty } -- Values that can change while running an Annex action. @@ -190,14 +194,12 @@ data AnnexState = AnnexState , fields :: M.Map String String , cleanupactions :: M.Map CleanupAction (Annex ()) , sentinalstatus :: Maybe SentinalStatus - , useragent :: Maybe String , errcounter :: Integer , skippedfiles :: Bool , adjustedbranchrefreshcounter :: Integer , unusedkeys :: Maybe (S.Set Key) , tempurls :: M.Map Key URLString , existinghooks :: M.Map Git.Hook.Hook Bool - , desktopnotify :: DesktopNotify , workers :: Maybe (TMVar (WorkerPool (AnnexState, AnnexRead))) , cachedcurrentbranch :: (Maybe (Maybe Git.Branch, Maybe Adjustment)) , cachedgitenv :: Maybe (AltIndexFile, FilePath, [(String, String)]) @@ -245,14 +247,12 @@ newAnnexState c r = do , fields = M.empty , cleanupactions = M.empty , sentinalstatus = Nothing - , useragent = Nothing , errcounter = 0 , skippedfiles = False , adjustedbranchrefreshcounter = 0 , unusedkeys = Nothing , tempurls = M.empty , existinghooks = M.empty - , desktopnotify = mempty , workers = Nothing , cachedcurrentbranch = Nothing , cachedgitenv = Nothing diff --git a/Annex/Url.hs b/Annex/Url.hs index 303e98e798..0d74fcb20b 100644 --- a/Annex/Url.hs +++ b/Annex/Url.hs @@ -48,7 +48,7 @@ defaultUserAgent :: U.UserAgent defaultUserAgent = "git-annex/" ++ BuildInfo.packageversion getUserAgent :: Annex U.UserAgent -getUserAgent = Annex.getState $ +getUserAgent = Annex.getRead $ fromMaybe defaultUserAgent . Annex.useragent getUrlOptions :: Annex U.UrlOptions diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 6526d3632d..d57305440b 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -78,7 +78,7 @@ gitAnnexGlobalOptions = commonGlobalOptions ++ <> help "override git configuration setting" <> hidden ) - , globalOption (setAnnexState . setuseragent) $ strOption + , globalOption setuseragent $ strOption ( long "user-agent" <> metavar paramName <> help "override default User-Agent" <> hidden @@ -88,12 +88,12 @@ gitAnnexGlobalOptions = commonGlobalOptions ++ <> help "deprecated, does not trust Amazon Glacier inventory" <> hidden ) - , globalFlag (setAnnexState $ setdesktopnotify mkNotifyFinish) + , globalFlag (setdesktopnotify mkNotifyFinish) ( long "notify-finish" <> help "show desktop notification after transfer finishes" <> hidden ) - , globalFlag (setAnnexState $ setdesktopnotify mkNotifyStart) + , globalFlag (setdesktopnotify mkNotifyStart) ( long "notify-start" <> help "show desktop notification after transfer starts" <> hidden @@ -102,9 +102,9 @@ gitAnnexGlobalOptions = commonGlobalOptions ++ where setnumcopies n = setAnnexRead $ \rd -> rd { Annex.forcenumcopies = Just $ configuredNumCopies n } setmincopies n = setAnnexRead $ \rd -> rd { Annex.forcemincopies = Just $ configuredMinCopies n } - setuseragent v = Annex.changeState $ \s -> s { Annex.useragent = Just v } + setuseragent v = setAnnexRead $ \rd -> rd { Annex.useragent = Just v } + setdesktopnotify v = setAnnexRead $ \rd -> rd { Annex.desktopnotify = Annex.desktopnotify rd <> v } setgitconfig v = Annex.addGitConfigOverride v - setdesktopnotify v = Annex.changeState $ \s -> s { Annex.desktopnotify = Annex.desktopnotify s <> v } {- Parser that accepts all non-option params. -} cmdParams :: CmdParamsDesc -> Parser CmdParams diff --git a/doc/todo/move_readonly_values_to_AnnexRead.mdwn b/doc/todo/move_readonly_values_to_AnnexRead.mdwn index 70c94f00e7..8aabd70b37 100644 --- a/doc/todo/move_readonly_values_to_AnnexRead.mdwn +++ b/doc/todo/move_readonly_values_to_AnnexRead.mdwn @@ -4,4 +4,5 @@ anything that never needs to be modified while git-annex is running can be moved to AnnexRead for a performance win and also to make clean how it's used. --[[Joey]] -Many things have been moved, but there are certainly others that can be. +> [[done]]; all AnnexState fields have been checked and all that can be +> made readonly are. --[[Joey]]