final readonly values moves to AnnexRead
authorJoey Hess <joeyh@joeyh.name>
Tue, 28 Jun 2022 20:02:01 +0000 (16:02 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 28 Jun 2022 20:04:58 +0000 (16:04 -0400)
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
Annex/Url.hs
CmdLine/GitAnnex/Options.hs
doc/todo/move_readonly_values_to_AnnexRead.mdwn

index e4fbd51152b32c11fefe226aeb873ac827965b12..81ecb1a833e86e1a6de5b910d2aea41c8278cdf2 100644 (file)
--- 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
index 303e98e798802b9c5f7a956f291d0844f07cc7f0..0d74fcb20bf12b1d641796b913420b362407ad2a 100644 (file)
@@ -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
index 6526d3632ddd17b1aa618edef0700957a477b160..d57305440b2c23660ead1d68c9e1ad099ae2993f 100644 (file)
@@ -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
index 70c94f00e7c7bc57153f311238231fd51bc08cfe..8aabd70b378ac14ea29fdbc172f0621097b08377 100644 (file)
@@ -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]]