diff options
-rw-r--r-- | Annex.hs | 4 | ||||
-rw-r--r-- | GitAnnex.hs | 2 | ||||
-rw-r--r-- | Trust.hs | 19 | ||||
-rw-r--r-- | Types/TrustLevel.hs (renamed from TrustLevel.hs) | 9 |
4 files changed, 24 insertions, 10 deletions
@@ -24,7 +24,7 @@ import Types.Backend import Types.Remote import Types.Crypto import Types.BranchState -import TrustLevel +import Types.TrustLevel import Types.UUID -- git-annex's monad @@ -48,6 +48,7 @@ data AnnexState = AnnexState , fromremote :: Maybe String , exclude :: [String] , forcetrust :: [(UUID, TrustLevel)] + , trustmap :: Maybe TrustMap , cipher :: Maybe Cipher } @@ -69,6 +70,7 @@ newState allbackends gitrepo = AnnexState , fromremote = Nothing , exclude = [] , forcetrust = [] + , trustmap = Nothing , cipher = Nothing } diff --git a/GitAnnex.hs b/GitAnnex.hs index 727e0c396..49ba63b8a 100644 --- a/GitAnnex.hs +++ b/GitAnnex.hs @@ -14,7 +14,7 @@ import CmdLine import Command import Options import Utility -import TrustLevel +import Types.TrustLevel import qualified Annex import qualified Remote @@ -9,15 +9,13 @@ module Trust ( TrustLevel(..), trustLog, trustGet, - trustMap, - trustMapParse, trustSet ) where import Control.Monad.State import qualified Data.Map as M -import TrustLevel +import Types.TrustLevel import qualified Branch import Types import UUID @@ -35,11 +33,17 @@ trustGet level = do {- Read the trustLog into a map, overriding with any - values from forcetrust -} -trustMap :: Annex (M.Map UUID TrustLevel) +trustMap :: Annex TrustMap trustMap = do - overrides <- Annex.getState Annex.forcetrust - s <- Branch.get trustLog - return $ M.fromList $ trustMapParse s ++ overrides + cached <- Annex.getState Annex.trustmap + case cached of + Just m -> return m + Nothing -> do + overrides <- Annex.getState Annex.forcetrust + l <- Branch.get trustLog + let m = M.fromList $ trustMapParse l ++ overrides + Annex.changeState $ \s -> s { Annex.trustmap = Just m } + return m {- Trust map parser. -} trustMapParse :: String -> [(UUID, TrustLevel)] @@ -62,6 +66,7 @@ trustSet uuid level = do when (M.lookup uuid m /= Just level) $ do let m' = M.insert uuid level m Branch.change trustLog (serialize m') + Annex.changeState $ \s -> s { Annex.trustmap = Just m' } where serialize m = unlines $ map showpair $ M.toList m showpair (u, t) = u ++ " " ++ show t diff --git a/TrustLevel.hs b/Types/TrustLevel.hs index 5da142ca3..058ce4595 100644 --- a/TrustLevel.hs +++ b/Types/TrustLevel.hs @@ -5,10 +5,15 @@ - Licensed under the GNU GPL version 3 or higher. -} -module TrustLevel ( +module Types.TrustLevel ( TrustLevel(..), + TrustMap ) where +import qualified Data.Map as M + +import Types.UUID + data TrustLevel = SemiTrusted | UnTrusted | Trusted deriving Eq @@ -21,3 +26,5 @@ instance Read TrustLevel where readsPrec _ "1" = [(Trusted, "")] readsPrec _ "0" = [(UnTrusted, "")] readsPrec _ _ = [(SemiTrusted, "")] + +type TrustMap = M.Map UUID TrustLevel |