Add annex-trustlevel configuration settings, which can be used to override the trust level of a remote.

This overrides the trust.log, and is overridden by the command-line trust
parameters.

It would have been nicer to have Logs.Trust.trustMap just look up the
configuration for all remotes, but a dependency loop prevented that
(Remotes depends on Logs.Trust in several ways). So instead, look up
the configuration when building remotes, storing it in the same forcetrust
field used for the command-line trust parameters.
This commit is contained in:
Joey Hess 2012-01-09 23:31:44 -04:00
parent 9ffd97442b
commit 0d5c402210
7 changed files with 64 additions and 26 deletions

View file

@ -12,6 +12,8 @@ import qualified Git
import qualified Git.Config
import qualified Git.Command
import qualified Annex
import qualified Logs.Trust
import Types.TrustLevel
type ConfigKey = String
@ -30,7 +32,7 @@ getConfig r key def = do
def' <- fromRepo $ Git.Config.get ("annex." ++ key) def
fromRepo $ Git.Config.get (remoteConfig r key) def'
{- Looks up a per-remote config setting in git config. -}
{- A per-remote config setting in git config. -}
remoteConfig :: Git.Repo -> ConfigKey -> String
remoteConfig r key = "remote." ++ fromMaybe "" (Git.remoteName r) ++ ".annex-" ++ key
@ -67,9 +69,7 @@ prop_cost_sane = False `notElem`
, semiCheapRemoteCost + encryptedRemoteCostAdj < expensiveRemoteCost
]
{- Checks if a repo should be ignored, based either on annex-ignore
- setting, or on command-line options. Allows command-line to override
- annex-ignore. -}
{- Checks if a repo should be ignored. -}
repoNotIgnored :: Git.Repo -> Annex Bool
repoNotIgnored r = not . Git.configTrue <$> getConfig r "ignore" "false"
@ -83,3 +83,8 @@ getNumCopies v = perhaps (use v) =<< Annex.getState Annex.forcenumcopies
readMaybe <$> fromRepo (Git.Config.get config "1")
perhaps fallback = maybe fallback (return . id)
config = "annex.numcopies"
{- Gets the trust level set for a remote in git config. -}
getTrustLevel :: Git.Repo -> Annex (Maybe TrustLevel)
getTrustLevel r = maybe Nothing Logs.Trust.trustName <$>
fromRepo (Git.Config.getMaybe (remoteConfig r "trustlevel"))