rename changeGitConfig to overrideGitConfig and avoid unncessary calls
authorJoey Hess <joeyh@joeyh.name>
Thu, 27 Feb 2020 05:06:35 +0000 (01:06 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 27 Feb 2020 05:11:53 +0000 (01:11 -0400)
It's important that it be clear that it overrides a config, such that
reloading the git config won't change it, and in particular, setConfig
won't change it.

Most of the calls to changeGitConfig were actually after setConfig,
which was redundant and unncessary. So removed those.

The only remaining one, besides --debug, is in the handling of
repository-global config values. That one's ok, because the
way mergeGitConfig is implemented, it does not override any value that
is set in git config. If a value with a repo-global setting was passed
to setConfig, it would set it in the git config, reload the git config,
re-apply mergeGitConfig, and use the newly set value, which is the right
thing.

Annex.hs
Annex/UUID.hs
CmdLine/Option.hs
Config.hs
Config/GitConfig.hs
Upgrade/V5.hs
Upgrade/V5/Direct.hs

index efdbe864d7ce5326b73daa9628d42b499b9ace45..9e0bcd3d81750c13303332fc6f96f68ca6c33951 100644 (file)
--- a/Annex.hs
+++ b/Annex.hs
@@ -28,7 +28,7 @@ module Annex (
        fromRepo,
        calcRepo,
        getGitConfig,
-       changeGitConfig,
+       overrideGitConfig,
        changeGitRepo,
        adjustGitRepo,
        getRemoteGitConfig,
@@ -316,10 +316,10 @@ calcRepo a = do
 getGitConfig :: Annex GitConfig
 getGitConfig = getState gitconfig
 
-{- Modifies a GitConfig setting. The modification persists across
+{- Overrides a GitConfig setting. The modification persists across
  - reloads of the repo's config. -}
-changeGitConfig :: (GitConfig -> GitConfig) -> Annex ()
-changeGitConfig f = changeState $ \s -> s
+overrideGitConfig :: (GitConfig -> GitConfig) -> Annex ()
+overrideGitConfig f = changeState $ \s -> s
        { gitconfigadjustment = gitconfigadjustment s . f
        , gitconfig = f (gitconfig s)
        }
index 1032acd14e29c5932640a13e77eb64faef5f431b..f4e6b85648a1a245da2dd89fdb1c2f9e112f843f 100644 (file)
@@ -102,9 +102,7 @@ prepUUID = whenM ((==) NoUUID <$> getUUID) $
        storeUUID =<< liftIO genUUID
 
 storeUUID :: UUID -> Annex ()
-storeUUID u = do
-       Annex.changeGitConfig $ \c -> c { annexUUID = u }
-       storeUUIDIn configkeyUUID u
+storeUUID = storeUUIDIn configkeyUUID
 
 storeUUIDIn :: ConfigKey -> UUID -> Annex ()
 storeUUIDIn configfield = setConfig configfield . fromUUID
index ccc49bfc21952e76e966b1c0d274be88aad57a0a..7957ba852d89d8a6cbc354938ce2814dd6f85f3b 100644 (file)
@@ -59,5 +59,5 @@ commonGlobalOptions =
        setforce v = Annex.changeState $ \s -> s { Annex.force = v }
        setfast v = Annex.changeState $ \s -> s { Annex.fast = v }
        setforcebackend v = Annex.changeState $ \s -> s { Annex.forcebackend = Just v }
-       setdebug = Annex.changeGitConfig $ \c -> c { annexDebug = True }
-       unsetdebug = Annex.changeGitConfig $ \c -> c { annexDebug = False }
+       setdebug = Annex.overrideGitConfig $ \c -> c { annexDebug = True }
+       unsetdebug = Annex.overrideGitConfig $ \c -> c { annexDebug = False }
index 0f5f14d9133586998765efef32ead78692bda607..0196c1614511308073660224fab0d2db96313c7a 100644 (file)
--- a/Config.hs
+++ b/Config.hs
@@ -106,9 +106,8 @@ crippledFileSystem :: Annex Bool
 crippledFileSystem = annexCrippledFileSystem <$> Annex.getGitConfig
 
 setCrippledFileSystem :: Bool -> Annex ()
-setCrippledFileSystem b = do
+setCrippledFileSystem b =
        setConfig (annexConfig "crippledfilesystem") (Git.Config.boolConfig b)
-       Annex.changeGitConfig $ \c -> c { annexCrippledFileSystem = b }
 
 yesNo :: String -> Maybe Bool
 yesNo "yes" = Just True
index 6d5e161e781150199165854ca820137d839b7a99..1a63f7b7bbec6e98e647b4edb9bf4716ff1348af 100644 (file)
@@ -35,6 +35,6 @@ getGitConfigVal' f = (f <$> Annex.getGitConfig) >>= \case
                -- config makes all repository-global default
                -- values populate the GitConfig with HasGlobalConfig
                -- values, so it will only need to be done once.
-               Annex.changeGitConfig (\gc -> mergeGitConfig gc globalgc)
+               Annex.overrideGitConfig (\gc -> mergeGitConfig gc globalgc)
                f <$> Annex.getGitConfig
        c -> return c
index a8a84283b3e76fe5d95a128062b8e3f284921115..0e0368d11d6f240082e37b2b3f181a702ce64aa8 100644 (file)
@@ -10,7 +10,6 @@
 module Upgrade.V5 where
 
 import Annex.Common
-import qualified Annex
 import Config
 import Config.Smudge
 import Annex.InodeSentinal
@@ -84,7 +83,6 @@ convertDirect = do
         - space, with less preservation of old versions of files
         - as does annex.thin. -}
        setConfig (annexConfig "thin") (boolConfig True)
-       Annex.changeGitConfig $ \c -> c { annexThin = True }
        Direct.setIndirect
        cur <- fromMaybe (error "Somehow no branch is checked out")
                <$> inRepo Git.Branch.current
index 600efc616d19c7c61a1d23d7d1b26e207476947b..1fcf8c4eebe0d7af792510c5fe4ae541ebd041aa 100644 (file)
@@ -19,7 +19,6 @@ module Upgrade.V5.Direct (
 ) where
 
 import Annex.Common
-import qualified Annex
 import qualified Git
 import qualified Git.Config
 import qualified Git.Ref
@@ -35,7 +34,6 @@ setIndirect = do
        setbare
        switchHEADBack
        setConfig (annexConfig "direct") val
-       Annex.changeGitConfig $ \c -> c { annexDirect = False }
   where
        val = Git.Config.boolConfig False
        coreworktree = ConfigKey "core.worktree"