remoteConfig rework
remoteAnnexConfig will avoid bugs like
a3a674d15b
Use now more generic remoteConfig in a couple places that built
non-annex config settings manually before.
This commit is contained in:
parent
a3a674d15b
commit
69f2d1dd43
17 changed files with 30 additions and 26 deletions
|
@ -95,7 +95,7 @@ autoEnable = do
|
|||
Left e -> warning (show e)
|
||||
Right (_c, _u) ->
|
||||
when (cu /= u) $
|
||||
setConfig (remoteConfig c "config-uuid") (fromUUID cu)
|
||||
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
||||
_ -> return ()
|
||||
where
|
||||
configured rc = fromMaybe False $
|
||||
|
|
|
@ -81,7 +81,7 @@ getRepoUUID r = do
|
|||
updatecache u = do
|
||||
g <- gitRepo
|
||||
when (g /= r) $ storeUUIDIn cachekey u
|
||||
cachekey = remoteConfig r "uuid"
|
||||
cachekey = remoteAnnexConfig r "uuid"
|
||||
|
||||
removeRepoUUID :: Annex ()
|
||||
removeRepoUUID = do
|
||||
|
|
|
@ -113,7 +113,7 @@ setupSpecialRemote' setdesc name remotetype config mcreds (mu, ss, c) mcu = do
|
|||
Nothing ->
|
||||
configSet u c'
|
||||
Just (Annex.SpecialRemote.ConfigFrom cu) -> do
|
||||
setConfig (remoteConfig c' "config-uuid") (fromUUID cu)
|
||||
setConfig (remoteAnnexConfig c' "config-uuid") (fromUUID cu)
|
||||
configSet cu c'
|
||||
when setdesc $
|
||||
whenM (isNothing . M.lookup u <$> uuidDescMap) $
|
||||
|
|
|
@ -265,7 +265,7 @@ changeSyncable (Just r) False = do
|
|||
changeSyncFlag :: Remote -> Bool -> Annex ()
|
||||
changeSyncFlag r enabled = do
|
||||
repo <- Remote.getRepo r
|
||||
let key = Config.remoteConfig repo "sync"
|
||||
let key = Config.remoteAnnexConfig repo "sync"
|
||||
Config.setConfig key (boolConfig enabled)
|
||||
void Remote.remoteListRefresh
|
||||
|
||||
|
|
|
@ -306,7 +306,7 @@ getUpgradeRepositoryR r = go =<< liftAnnex (repoIdRemote r)
|
|||
liftAnnex $ do
|
||||
repo <- Remote.getRepo rmt
|
||||
setConfig
|
||||
(remoteConfig repo "ignore")
|
||||
(remoteAnnexConfig repo "ignore")
|
||||
(Git.Config.boolConfig False)
|
||||
liftAnnex $ void Remote.remoteListRefresh
|
||||
liftAssistant updateSyncRemotes
|
||||
|
|
|
@ -94,7 +94,7 @@ cleanupSpecialRemote u c mcu = do
|
|||
Nothing ->
|
||||
Logs.Remote.configSet u c
|
||||
Just (SpecialRemote.ConfigFrom cu) -> do
|
||||
setConfig (remoteConfig c "config-uuid") (fromUUID cu)
|
||||
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
||||
Logs.Remote.configSet cu c
|
||||
Remote.byUUID u >>= \case
|
||||
Nothing -> noop
|
||||
|
|
|
@ -81,7 +81,7 @@ seek o = do
|
|||
|
||||
-- handle deprecated option
|
||||
when (exportTracking o) $
|
||||
setConfig (remoteConfig r "tracking-branch")
|
||||
setConfig (remoteAnnexConfig r "tracking-branch")
|
||||
(fromRef $ exportTreeish o)
|
||||
|
||||
tree <- filterPreferredContent r =<<
|
||||
|
|
|
@ -107,7 +107,7 @@ cleanup u name c o = do
|
|||
Logs.Remote.configSet u c
|
||||
Just _ -> do
|
||||
cu <- liftIO genUUID
|
||||
setConfig (remoteConfig c "config-uuid") (fromUUID cu)
|
||||
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
||||
Logs.Remote.configSet cu c
|
||||
return True
|
||||
|
||||
|
|
|
@ -320,7 +320,7 @@ setupLink remotename (P2PAddressAuth addr authtoken) = do
|
|||
, Param (formatP2PAddress addr)
|
||||
]
|
||||
when ok $ do
|
||||
storeUUIDIn (remoteConfig remotename "uuid") theiruuid
|
||||
storeUUIDIn (remoteAnnexConfig remotename "uuid") theiruuid
|
||||
storeP2PRemoteAuthToken addr authtoken
|
||||
return LinkSuccess
|
||||
go (Right Nothing) = return $ AuthenticationError "Unable to authenticate with peer. Please check the address and try again."
|
||||
|
|
|
@ -788,7 +788,7 @@ seekExportContent o rs (currbranch, _) = or <$> forM rs go
|
|||
]
|
||||
_ -> noop
|
||||
where
|
||||
gitconfig = show (remoteConfig r "tracking-branch")
|
||||
gitconfig = show (remoteAnnexConfig r "tracking-branch")
|
||||
|
||||
fillexport _ _ [] _ = return False
|
||||
fillexport r db (tree:[]) mtbcommitsha = do
|
||||
|
|
16
Config.hs
16
Config.hs
|
@ -1,6 +1,6 @@
|
|||
{- Git configuration
|
||||
-
|
||||
- Copyright 2011-2019 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -65,7 +65,11 @@ instance RemoteNameable Remote where
|
|||
{- A per-remote config setting in git config. -}
|
||||
remoteConfig :: RemoteNameable r => r -> UnqualifiedConfigKey -> ConfigKey
|
||||
remoteConfig r key = ConfigKey $
|
||||
"remote." <> encodeBS' (getRemoteName r) <> ".annex-" <> key
|
||||
"remote." <> encodeBS' (getRemoteName r) <> "." <> key
|
||||
|
||||
{- A per-remote config annex setting in git config. -}
|
||||
remoteAnnexConfig :: RemoteNameable r => r -> UnqualifiedConfigKey -> ConfigKey
|
||||
remoteAnnexConfig r key = remoteConfig r ("annex-" <> key)
|
||||
|
||||
{- A global annex setting in git config. -}
|
||||
annexConfig :: UnqualifiedConfigKey -> ConfigKey
|
||||
|
@ -81,16 +85,16 @@ remoteCost' :: RemoteGitConfig -> Annex (Maybe Cost)
|
|||
remoteCost' = liftIO . getDynamicConfig . remoteAnnexCost
|
||||
|
||||
setRemoteCost :: Git.Repo -> Cost -> Annex ()
|
||||
setRemoteCost r c = setConfig (remoteConfig r "cost") (show c)
|
||||
setRemoteCost r c = setConfig (remoteAnnexConfig r "cost") (show c)
|
||||
|
||||
setRemoteAvailability :: Git.Repo -> Availability -> Annex ()
|
||||
setRemoteAvailability r c = setConfig (remoteConfig r "availability") (show c)
|
||||
setRemoteAvailability r c = setConfig (remoteAnnexConfig r "availability") (show c)
|
||||
|
||||
setRemoteIgnore :: Git.Repo -> Bool -> Annex ()
|
||||
setRemoteIgnore r b = setConfig (remoteConfig r "ignore") (Git.Config.boolConfig b)
|
||||
setRemoteIgnore r b = setConfig (remoteAnnexConfig r "ignore") (Git.Config.boolConfig b)
|
||||
|
||||
setRemoteBare :: Git.Repo -> Bool -> Annex ()
|
||||
setRemoteBare r b = setConfig (remoteConfig r "bare") (Git.Config.boolConfig b)
|
||||
setRemoteBare r b = setConfig (remoteAnnexConfig r "bare") (Git.Config.boolConfig b)
|
||||
|
||||
isBareRepo :: Annex Bool
|
||||
isBareRepo = fromRepo Git.repoIsLocalBare
|
||||
|
|
|
@ -131,7 +131,7 @@ byNameWithUUID = checkuuid <=< byName
|
|||
repo <- getRepo r
|
||||
ifM (liftIO $ getDynamicConfig $ remoteAnnexIgnore (gitconfig r))
|
||||
( giveup $ noRemoteUUIDMsg r ++
|
||||
" (" ++ show (remoteConfig repo "ignore") ++
|
||||
" (" ++ show (remoteAnnexConfig repo "ignore") ++
|
||||
" is set)"
|
||||
, giveup $ noRemoteUUIDMsg r
|
||||
)
|
||||
|
|
|
@ -169,7 +169,7 @@ externalSetup _ mu _ c gc = do
|
|||
|
||||
c'' <- case getRemoteConfigValue readonlyField pc of
|
||||
Just True -> do
|
||||
setConfig (remoteConfig (fromJust (lookupName c)) "readonly") (boolConfig True)
|
||||
setConfig (remoteAnnexConfig (fromJust (lookupName c)) "readonly") (boolConfig True)
|
||||
return c'
|
||||
_ -> do
|
||||
pc' <- either giveup return $ parseRemoteConfig c' lenientRemoteConfigParser
|
||||
|
|
|
@ -113,7 +113,7 @@ gen baser u c gc rs = do
|
|||
. parseRemoteConfig c'
|
||||
=<< configParser remote c'
|
||||
setGcryptEncryption pc remotename
|
||||
storeUUIDIn (remoteConfig baser "uuid") u'
|
||||
storeUUIDIn (remoteAnnexConfig baser "uuid") u'
|
||||
setConfig (Git.GCrypt.remoteConfigKey "gcrypt-id" remotename) gcryptid
|
||||
gen' r u' pc gc rs
|
||||
_ -> do
|
||||
|
|
|
@ -98,10 +98,10 @@ list autoinit = do
|
|||
rs <- mapM (tweakurl c) =<< Annex.getGitRemotes
|
||||
mapM (configRead autoinit) rs
|
||||
where
|
||||
annexurl n = Git.ConfigKey ("remote." <> encodeBS' n <> ".annexurl")
|
||||
annexurl r = remoteConfig r "annexurl"
|
||||
tweakurl c r = do
|
||||
let n = fromJust $ Git.remoteName r
|
||||
case M.lookup (annexurl n) c of
|
||||
case M.lookup (annexurl r) c of
|
||||
Nothing -> return r
|
||||
Just url -> inRepo $ \g ->
|
||||
Git.Construct.remoteNamed n $
|
||||
|
@ -256,7 +256,7 @@ tryGitConfigRead autoinit r
|
|||
| otherwise -> configlist_failed
|
||||
Left _ -> configlist_failed
|
||||
| Git.repoIsHttp r = storeUpdatedRemote geturlconfig
|
||||
| Git.GCrypt.isEncrypted r = handlegcrypt =<< getConfigMaybe (remoteConfig r "uuid")
|
||||
| Git.GCrypt.isEncrypted r = handlegcrypt =<< getConfigMaybe (remoteAnnexConfig r "uuid")
|
||||
| Git.repoIsUrl r = return r
|
||||
| otherwise = storeUpdatedRemote $ liftIO $
|
||||
readlocalannexconfig `catchNonAsync` (const $ return r)
|
||||
|
|
|
@ -166,7 +166,7 @@ mySetup _ mu _ c gc = do
|
|||
-- (so it's also usable by git as a non-special remote),
|
||||
-- and set remote.name.annex-git-lfs = true
|
||||
gitConfigSpecialRemote u c' [("git-lfs", "true")]
|
||||
setConfig (Git.ConfigKey ("remote." <> encodeBS' (getRemoteName c) <> ".url")) url
|
||||
setConfig (remoteConfig (getRemoteName c) "url") url
|
||||
return (c', u)
|
||||
where
|
||||
url = maybe (giveup "Specify url=") fromProposedAccepted
|
||||
|
@ -201,7 +201,7 @@ configKnownUrl r
|
|||
set "config-uuid" (fromUUID cu) r'
|
||||
Nothing -> return r'
|
||||
set k v r' = do
|
||||
let k' = remoteConfig r' k
|
||||
let k' = remoteAnnexConfig r' k
|
||||
setConfig k' v
|
||||
return $ Git.Config.store' k' (Git.ConfigValue (encodeBS' v)) r'
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ findSpecialRemotes s = do
|
|||
gitConfigSpecialRemote :: UUID -> RemoteConfig -> [(String, String)] -> Annex ()
|
||||
gitConfigSpecialRemote u c cfgs = do
|
||||
forM_ cfgs $ \(k, v) ->
|
||||
setConfig (remoteConfig c (encodeBS' k)) v
|
||||
storeUUIDIn (remoteConfig c "uuid") u
|
||||
setConfig (remoteAnnexConfig c (encodeBS' k)) v
|
||||
storeUUIDIn (remoteAnnexConfig c "uuid") u
|
||||
|
||||
-- RetrievalVerifiableKeysSecure unless overridden by git config.
|
||||
--
|
||||
|
|
Loading…
Add table
Reference in a new issue