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)
|
Left e -> warning (show e)
|
||||||
Right (_c, _u) ->
|
Right (_c, _u) ->
|
||||||
when (cu /= u) $
|
when (cu /= u) $
|
||||||
setConfig (remoteConfig c "config-uuid") (fromUUID cu)
|
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
where
|
where
|
||||||
configured rc = fromMaybe False $
|
configured rc = fromMaybe False $
|
||||||
|
|
|
@ -81,7 +81,7 @@ getRepoUUID r = do
|
||||||
updatecache u = do
|
updatecache u = do
|
||||||
g <- gitRepo
|
g <- gitRepo
|
||||||
when (g /= r) $ storeUUIDIn cachekey u
|
when (g /= r) $ storeUUIDIn cachekey u
|
||||||
cachekey = remoteConfig r "uuid"
|
cachekey = remoteAnnexConfig r "uuid"
|
||||||
|
|
||||||
removeRepoUUID :: Annex ()
|
removeRepoUUID :: Annex ()
|
||||||
removeRepoUUID = do
|
removeRepoUUID = do
|
||||||
|
|
|
@ -113,7 +113,7 @@ setupSpecialRemote' setdesc name remotetype config mcreds (mu, ss, c) mcu = do
|
||||||
Nothing ->
|
Nothing ->
|
||||||
configSet u c'
|
configSet u c'
|
||||||
Just (Annex.SpecialRemote.ConfigFrom cu) -> do
|
Just (Annex.SpecialRemote.ConfigFrom cu) -> do
|
||||||
setConfig (remoteConfig c' "config-uuid") (fromUUID cu)
|
setConfig (remoteAnnexConfig c' "config-uuid") (fromUUID cu)
|
||||||
configSet cu c'
|
configSet cu c'
|
||||||
when setdesc $
|
when setdesc $
|
||||||
whenM (isNothing . M.lookup u <$> uuidDescMap) $
|
whenM (isNothing . M.lookup u <$> uuidDescMap) $
|
||||||
|
|
|
@ -265,7 +265,7 @@ changeSyncable (Just r) False = do
|
||||||
changeSyncFlag :: Remote -> Bool -> Annex ()
|
changeSyncFlag :: Remote -> Bool -> Annex ()
|
||||||
changeSyncFlag r enabled = do
|
changeSyncFlag r enabled = do
|
||||||
repo <- Remote.getRepo r
|
repo <- Remote.getRepo r
|
||||||
let key = Config.remoteConfig repo "sync"
|
let key = Config.remoteAnnexConfig repo "sync"
|
||||||
Config.setConfig key (boolConfig enabled)
|
Config.setConfig key (boolConfig enabled)
|
||||||
void Remote.remoteListRefresh
|
void Remote.remoteListRefresh
|
||||||
|
|
||||||
|
|
|
@ -306,7 +306,7 @@ getUpgradeRepositoryR r = go =<< liftAnnex (repoIdRemote r)
|
||||||
liftAnnex $ do
|
liftAnnex $ do
|
||||||
repo <- Remote.getRepo rmt
|
repo <- Remote.getRepo rmt
|
||||||
setConfig
|
setConfig
|
||||||
(remoteConfig repo "ignore")
|
(remoteAnnexConfig repo "ignore")
|
||||||
(Git.Config.boolConfig False)
|
(Git.Config.boolConfig False)
|
||||||
liftAnnex $ void Remote.remoteListRefresh
|
liftAnnex $ void Remote.remoteListRefresh
|
||||||
liftAssistant updateSyncRemotes
|
liftAssistant updateSyncRemotes
|
||||||
|
|
|
@ -94,7 +94,7 @@ cleanupSpecialRemote u c mcu = do
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Logs.Remote.configSet u c
|
Logs.Remote.configSet u c
|
||||||
Just (SpecialRemote.ConfigFrom cu) -> do
|
Just (SpecialRemote.ConfigFrom cu) -> do
|
||||||
setConfig (remoteConfig c "config-uuid") (fromUUID cu)
|
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
||||||
Logs.Remote.configSet cu c
|
Logs.Remote.configSet cu c
|
||||||
Remote.byUUID u >>= \case
|
Remote.byUUID u >>= \case
|
||||||
Nothing -> noop
|
Nothing -> noop
|
||||||
|
|
|
@ -81,7 +81,7 @@ seek o = do
|
||||||
|
|
||||||
-- handle deprecated option
|
-- handle deprecated option
|
||||||
when (exportTracking o) $
|
when (exportTracking o) $
|
||||||
setConfig (remoteConfig r "tracking-branch")
|
setConfig (remoteAnnexConfig r "tracking-branch")
|
||||||
(fromRef $ exportTreeish o)
|
(fromRef $ exportTreeish o)
|
||||||
|
|
||||||
tree <- filterPreferredContent r =<<
|
tree <- filterPreferredContent r =<<
|
||||||
|
|
|
@ -107,7 +107,7 @@ cleanup u name c o = do
|
||||||
Logs.Remote.configSet u c
|
Logs.Remote.configSet u c
|
||||||
Just _ -> do
|
Just _ -> do
|
||||||
cu <- liftIO genUUID
|
cu <- liftIO genUUID
|
||||||
setConfig (remoteConfig c "config-uuid") (fromUUID cu)
|
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
||||||
Logs.Remote.configSet cu c
|
Logs.Remote.configSet cu c
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -320,7 +320,7 @@ setupLink remotename (P2PAddressAuth addr authtoken) = do
|
||||||
, Param (formatP2PAddress addr)
|
, Param (formatP2PAddress addr)
|
||||||
]
|
]
|
||||||
when ok $ do
|
when ok $ do
|
||||||
storeUUIDIn (remoteConfig remotename "uuid") theiruuid
|
storeUUIDIn (remoteAnnexConfig remotename "uuid") theiruuid
|
||||||
storeP2PRemoteAuthToken addr authtoken
|
storeP2PRemoteAuthToken addr authtoken
|
||||||
return LinkSuccess
|
return LinkSuccess
|
||||||
go (Right Nothing) = return $ AuthenticationError "Unable to authenticate with peer. Please check the address and try again."
|
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
|
_ -> noop
|
||||||
where
|
where
|
||||||
gitconfig = show (remoteConfig r "tracking-branch")
|
gitconfig = show (remoteAnnexConfig r "tracking-branch")
|
||||||
|
|
||||||
fillexport _ _ [] _ = return False
|
fillexport _ _ [] _ = return False
|
||||||
fillexport r db (tree:[]) mtbcommitsha = do
|
fillexport r db (tree:[]) mtbcommitsha = do
|
||||||
|
|
16
Config.hs
16
Config.hs
|
@ -1,6 +1,6 @@
|
||||||
{- Git configuration
|
{- 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.
|
- 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. -}
|
{- A per-remote config setting in git config. -}
|
||||||
remoteConfig :: RemoteNameable r => r -> UnqualifiedConfigKey -> ConfigKey
|
remoteConfig :: RemoteNameable r => r -> UnqualifiedConfigKey -> ConfigKey
|
||||||
remoteConfig r key = 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. -}
|
{- A global annex setting in git config. -}
|
||||||
annexConfig :: UnqualifiedConfigKey -> ConfigKey
|
annexConfig :: UnqualifiedConfigKey -> ConfigKey
|
||||||
|
@ -81,16 +85,16 @@ remoteCost' :: RemoteGitConfig -> Annex (Maybe Cost)
|
||||||
remoteCost' = liftIO . getDynamicConfig . remoteAnnexCost
|
remoteCost' = liftIO . getDynamicConfig . remoteAnnexCost
|
||||||
|
|
||||||
setRemoteCost :: Git.Repo -> Cost -> Annex ()
|
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 :: 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 :: 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 :: 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 :: Annex Bool
|
||||||
isBareRepo = fromRepo Git.repoIsLocalBare
|
isBareRepo = fromRepo Git.repoIsLocalBare
|
||||||
|
|
|
@ -131,7 +131,7 @@ byNameWithUUID = checkuuid <=< byName
|
||||||
repo <- getRepo r
|
repo <- getRepo r
|
||||||
ifM (liftIO $ getDynamicConfig $ remoteAnnexIgnore (gitconfig r))
|
ifM (liftIO $ getDynamicConfig $ remoteAnnexIgnore (gitconfig r))
|
||||||
( giveup $ noRemoteUUIDMsg r ++
|
( giveup $ noRemoteUUIDMsg r ++
|
||||||
" (" ++ show (remoteConfig repo "ignore") ++
|
" (" ++ show (remoteAnnexConfig repo "ignore") ++
|
||||||
" is set)"
|
" is set)"
|
||||||
, giveup $ noRemoteUUIDMsg r
|
, giveup $ noRemoteUUIDMsg r
|
||||||
)
|
)
|
||||||
|
|
|
@ -169,7 +169,7 @@ externalSetup _ mu _ c gc = do
|
||||||
|
|
||||||
c'' <- case getRemoteConfigValue readonlyField pc of
|
c'' <- case getRemoteConfigValue readonlyField pc of
|
||||||
Just True -> do
|
Just True -> do
|
||||||
setConfig (remoteConfig (fromJust (lookupName c)) "readonly") (boolConfig True)
|
setConfig (remoteAnnexConfig (fromJust (lookupName c)) "readonly") (boolConfig True)
|
||||||
return c'
|
return c'
|
||||||
_ -> do
|
_ -> do
|
||||||
pc' <- either giveup return $ parseRemoteConfig c' lenientRemoteConfigParser
|
pc' <- either giveup return $ parseRemoteConfig c' lenientRemoteConfigParser
|
||||||
|
|
|
@ -113,7 +113,7 @@ gen baser u c gc rs = do
|
||||||
. parseRemoteConfig c'
|
. parseRemoteConfig c'
|
||||||
=<< configParser remote c'
|
=<< configParser remote c'
|
||||||
setGcryptEncryption pc remotename
|
setGcryptEncryption pc remotename
|
||||||
storeUUIDIn (remoteConfig baser "uuid") u'
|
storeUUIDIn (remoteAnnexConfig baser "uuid") u'
|
||||||
setConfig (Git.GCrypt.remoteConfigKey "gcrypt-id" remotename) gcryptid
|
setConfig (Git.GCrypt.remoteConfigKey "gcrypt-id" remotename) gcryptid
|
||||||
gen' r u' pc gc rs
|
gen' r u' pc gc rs
|
||||||
_ -> do
|
_ -> do
|
||||||
|
|
|
@ -98,10 +98,10 @@ list autoinit = do
|
||||||
rs <- mapM (tweakurl c) =<< Annex.getGitRemotes
|
rs <- mapM (tweakurl c) =<< Annex.getGitRemotes
|
||||||
mapM (configRead autoinit) rs
|
mapM (configRead autoinit) rs
|
||||||
where
|
where
|
||||||
annexurl n = Git.ConfigKey ("remote." <> encodeBS' n <> ".annexurl")
|
annexurl r = remoteConfig r "annexurl"
|
||||||
tweakurl c r = do
|
tweakurl c r = do
|
||||||
let n = fromJust $ Git.remoteName r
|
let n = fromJust $ Git.remoteName r
|
||||||
case M.lookup (annexurl n) c of
|
case M.lookup (annexurl r) c of
|
||||||
Nothing -> return r
|
Nothing -> return r
|
||||||
Just url -> inRepo $ \g ->
|
Just url -> inRepo $ \g ->
|
||||||
Git.Construct.remoteNamed n $
|
Git.Construct.remoteNamed n $
|
||||||
|
@ -256,7 +256,7 @@ tryGitConfigRead autoinit r
|
||||||
| otherwise -> configlist_failed
|
| otherwise -> configlist_failed
|
||||||
Left _ -> configlist_failed
|
Left _ -> configlist_failed
|
||||||
| Git.repoIsHttp r = storeUpdatedRemote geturlconfig
|
| 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
|
| Git.repoIsUrl r = return r
|
||||||
| otherwise = storeUpdatedRemote $ liftIO $
|
| otherwise = storeUpdatedRemote $ liftIO $
|
||||||
readlocalannexconfig `catchNonAsync` (const $ return r)
|
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),
|
-- (so it's also usable by git as a non-special remote),
|
||||||
-- and set remote.name.annex-git-lfs = true
|
-- and set remote.name.annex-git-lfs = true
|
||||||
gitConfigSpecialRemote u c' [("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)
|
return (c', u)
|
||||||
where
|
where
|
||||||
url = maybe (giveup "Specify url=") fromProposedAccepted
|
url = maybe (giveup "Specify url=") fromProposedAccepted
|
||||||
|
@ -201,7 +201,7 @@ configKnownUrl r
|
||||||
set "config-uuid" (fromUUID cu) r'
|
set "config-uuid" (fromUUID cu) r'
|
||||||
Nothing -> return r'
|
Nothing -> return r'
|
||||||
set k v r' = do
|
set k v r' = do
|
||||||
let k' = remoteConfig r' k
|
let k' = remoteAnnexConfig r' k
|
||||||
setConfig k' v
|
setConfig k' v
|
||||||
return $ Git.Config.store' k' (Git.ConfigValue (encodeBS' v)) r'
|
return $ Git.Config.store' k' (Git.ConfigValue (encodeBS' v)) r'
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,8 @@ findSpecialRemotes s = do
|
||||||
gitConfigSpecialRemote :: UUID -> RemoteConfig -> [(String, String)] -> Annex ()
|
gitConfigSpecialRemote :: UUID -> RemoteConfig -> [(String, String)] -> Annex ()
|
||||||
gitConfigSpecialRemote u c cfgs = do
|
gitConfigSpecialRemote u c cfgs = do
|
||||||
forM_ cfgs $ \(k, v) ->
|
forM_ cfgs $ \(k, v) ->
|
||||||
setConfig (remoteConfig c (encodeBS' k)) v
|
setConfig (remoteAnnexConfig c (encodeBS' k)) v
|
||||||
storeUUIDIn (remoteConfig c "uuid") u
|
storeUUIDIn (remoteAnnexConfig c "uuid") u
|
||||||
|
|
||||||
-- RetrievalVerifiableKeysSecure unless overridden by git config.
|
-- RetrievalVerifiableKeysSecure unless overridden by git config.
|
||||||
--
|
--
|
||||||
|
|
Loading…
Add table
Reference in a new issue