rename changeGitConfig to overrideGitConfig and avoid unncessary calls

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.
This commit is contained in:
Joey Hess 2020-02-27 01:06:35 -04:00
parent c089f395b0
commit c78b9b55b6
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 9 additions and 16 deletions

View file

@ -28,7 +28,7 @@ module Annex (
fromRepo, fromRepo,
calcRepo, calcRepo,
getGitConfig, getGitConfig,
changeGitConfig, overrideGitConfig,
changeGitRepo, changeGitRepo,
adjustGitRepo, adjustGitRepo,
getRemoteGitConfig, getRemoteGitConfig,
@ -316,10 +316,10 @@ calcRepo a = do
getGitConfig :: Annex GitConfig getGitConfig :: Annex GitConfig
getGitConfig = getState 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. -} - reloads of the repo's config. -}
changeGitConfig :: (GitConfig -> GitConfig) -> Annex () overrideGitConfig :: (GitConfig -> GitConfig) -> Annex ()
changeGitConfig f = changeState $ \s -> s overrideGitConfig f = changeState $ \s -> s
{ gitconfigadjustment = gitconfigadjustment s . f { gitconfigadjustment = gitconfigadjustment s . f
, gitconfig = f (gitconfig s) , gitconfig = f (gitconfig s)
} }

View file

@ -102,9 +102,7 @@ prepUUID = whenM ((==) NoUUID <$> getUUID) $
storeUUID =<< liftIO genUUID storeUUID =<< liftIO genUUID
storeUUID :: UUID -> Annex () storeUUID :: UUID -> Annex ()
storeUUID u = do storeUUID = storeUUIDIn configkeyUUID
Annex.changeGitConfig $ \c -> c { annexUUID = u }
storeUUIDIn configkeyUUID u
storeUUIDIn :: ConfigKey -> UUID -> Annex () storeUUIDIn :: ConfigKey -> UUID -> Annex ()
storeUUIDIn configfield = setConfig configfield . fromUUID storeUUIDIn configfield = setConfig configfield . fromUUID

View file

@ -59,5 +59,5 @@ commonGlobalOptions =
setforce v = Annex.changeState $ \s -> s { Annex.force = v } setforce v = Annex.changeState $ \s -> s { Annex.force = v }
setfast v = Annex.changeState $ \s -> s { Annex.fast = v } setfast v = Annex.changeState $ \s -> s { Annex.fast = v }
setforcebackend v = Annex.changeState $ \s -> s { Annex.forcebackend = Just v } setforcebackend v = Annex.changeState $ \s -> s { Annex.forcebackend = Just v }
setdebug = Annex.changeGitConfig $ \c -> c { annexDebug = True } setdebug = Annex.overrideGitConfig $ \c -> c { annexDebug = True }
unsetdebug = Annex.changeGitConfig $ \c -> c { annexDebug = False } unsetdebug = Annex.overrideGitConfig $ \c -> c { annexDebug = False }

View file

@ -106,9 +106,8 @@ crippledFileSystem :: Annex Bool
crippledFileSystem = annexCrippledFileSystem <$> Annex.getGitConfig crippledFileSystem = annexCrippledFileSystem <$> Annex.getGitConfig
setCrippledFileSystem :: Bool -> Annex () setCrippledFileSystem :: Bool -> Annex ()
setCrippledFileSystem b = do setCrippledFileSystem b =
setConfig (annexConfig "crippledfilesystem") (Git.Config.boolConfig b) setConfig (annexConfig "crippledfilesystem") (Git.Config.boolConfig b)
Annex.changeGitConfig $ \c -> c { annexCrippledFileSystem = b }
yesNo :: String -> Maybe Bool yesNo :: String -> Maybe Bool
yesNo "yes" = Just True yesNo "yes" = Just True

View file

@ -35,6 +35,6 @@ getGitConfigVal' f = (f <$> Annex.getGitConfig) >>= \case
-- config makes all repository-global default -- config makes all repository-global default
-- values populate the GitConfig with HasGlobalConfig -- values populate the GitConfig with HasGlobalConfig
-- values, so it will only need to be done once. -- 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 f <$> Annex.getGitConfig
c -> return c c -> return c

View file

@ -10,7 +10,6 @@
module Upgrade.V5 where module Upgrade.V5 where
import Annex.Common import Annex.Common
import qualified Annex
import Config import Config
import Config.Smudge import Config.Smudge
import Annex.InodeSentinal import Annex.InodeSentinal
@ -84,7 +83,6 @@ convertDirect = do
- space, with less preservation of old versions of files - space, with less preservation of old versions of files
- as does annex.thin. -} - as does annex.thin. -}
setConfig (annexConfig "thin") (boolConfig True) setConfig (annexConfig "thin") (boolConfig True)
Annex.changeGitConfig $ \c -> c { annexThin = True }
Direct.setIndirect Direct.setIndirect
cur <- fromMaybe (error "Somehow no branch is checked out") cur <- fromMaybe (error "Somehow no branch is checked out")
<$> inRepo Git.Branch.current <$> inRepo Git.Branch.current

View file

@ -19,7 +19,6 @@ module Upgrade.V5.Direct (
) where ) where
import Annex.Common import Annex.Common
import qualified Annex
import qualified Git import qualified Git
import qualified Git.Config import qualified Git.Config
import qualified Git.Ref import qualified Git.Ref
@ -35,7 +34,6 @@ setIndirect = do
setbare setbare
switchHEADBack switchHEADBack
setConfig (annexConfig "direct") val setConfig (annexConfig "direct") val
Annex.changeGitConfig $ \c -> c { annexDirect = False }
where where
val = Git.Config.boolConfig False val = Git.Config.boolConfig False
coreworktree = ConfigKey "core.worktree" coreworktree = ConfigKey "core.worktree"