cache the trustmap
Doubles the speed of fsck, and speeds up drop as well.
This commit is contained in:
parent
a61154baf5
commit
69d3c1cec9
4 changed files with 24 additions and 10 deletions
4
Annex.hs
4
Annex.hs
|
@ -24,7 +24,7 @@ import Types.Backend
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
import Types.Crypto
|
import Types.Crypto
|
||||||
import Types.BranchState
|
import Types.BranchState
|
||||||
import TrustLevel
|
import Types.TrustLevel
|
||||||
import Types.UUID
|
import Types.UUID
|
||||||
|
|
||||||
-- git-annex's monad
|
-- git-annex's monad
|
||||||
|
@ -48,6 +48,7 @@ data AnnexState = AnnexState
|
||||||
, fromremote :: Maybe String
|
, fromremote :: Maybe String
|
||||||
, exclude :: [String]
|
, exclude :: [String]
|
||||||
, forcetrust :: [(UUID, TrustLevel)]
|
, forcetrust :: [(UUID, TrustLevel)]
|
||||||
|
, trustmap :: Maybe TrustMap
|
||||||
, cipher :: Maybe Cipher
|
, cipher :: Maybe Cipher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +70,7 @@ newState allbackends gitrepo = AnnexState
|
||||||
, fromremote = Nothing
|
, fromremote = Nothing
|
||||||
, exclude = []
|
, exclude = []
|
||||||
, forcetrust = []
|
, forcetrust = []
|
||||||
|
, trustmap = Nothing
|
||||||
, cipher = Nothing
|
, cipher = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import CmdLine
|
||||||
import Command
|
import Command
|
||||||
import Options
|
import Options
|
||||||
import Utility
|
import Utility
|
||||||
import TrustLevel
|
import Types.TrustLevel
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
|
|
||||||
|
|
19
Trust.hs
19
Trust.hs
|
@ -9,15 +9,13 @@ module Trust (
|
||||||
TrustLevel(..),
|
TrustLevel(..),
|
||||||
trustLog,
|
trustLog,
|
||||||
trustGet,
|
trustGet,
|
||||||
trustMap,
|
|
||||||
trustMapParse,
|
|
||||||
trustSet
|
trustSet
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
|
||||||
import TrustLevel
|
import Types.TrustLevel
|
||||||
import qualified Branch
|
import qualified Branch
|
||||||
import Types
|
import Types
|
||||||
import UUID
|
import UUID
|
||||||
|
@ -35,11 +33,17 @@ trustGet level = do
|
||||||
|
|
||||||
{- Read the trustLog into a map, overriding with any
|
{- Read the trustLog into a map, overriding with any
|
||||||
- values from forcetrust -}
|
- values from forcetrust -}
|
||||||
trustMap :: Annex (M.Map UUID TrustLevel)
|
trustMap :: Annex TrustMap
|
||||||
trustMap = do
|
trustMap = do
|
||||||
overrides <- Annex.getState Annex.forcetrust
|
cached <- Annex.getState Annex.trustmap
|
||||||
s <- Branch.get trustLog
|
case cached of
|
||||||
return $ M.fromList $ trustMapParse s ++ overrides
|
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. -}
|
{- Trust map parser. -}
|
||||||
trustMapParse :: String -> [(UUID, TrustLevel)]
|
trustMapParse :: String -> [(UUID, TrustLevel)]
|
||||||
|
@ -62,6 +66,7 @@ trustSet uuid level = do
|
||||||
when (M.lookup uuid m /= Just level) $ do
|
when (M.lookup uuid m /= Just level) $ do
|
||||||
let m' = M.insert uuid level m
|
let m' = M.insert uuid level m
|
||||||
Branch.change trustLog (serialize m')
|
Branch.change trustLog (serialize m')
|
||||||
|
Annex.changeState $ \s -> s { Annex.trustmap = Just m' }
|
||||||
where
|
where
|
||||||
serialize m = unlines $ map showpair $ M.toList m
|
serialize m = unlines $ map showpair $ M.toList m
|
||||||
showpair (u, t) = u ++ " " ++ show t
|
showpair (u, t) = u ++ " " ++ show t
|
||||||
|
|
|
@ -5,10 +5,15 @@
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module TrustLevel (
|
module Types.TrustLevel (
|
||||||
TrustLevel(..),
|
TrustLevel(..),
|
||||||
|
TrustMap
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import qualified Data.Map as M
|
||||||
|
|
||||||
|
import Types.UUID
|
||||||
|
|
||||||
data TrustLevel = SemiTrusted | UnTrusted | Trusted
|
data TrustLevel = SemiTrusted | UnTrusted | Trusted
|
||||||
deriving Eq
|
deriving Eq
|
||||||
|
|
||||||
|
@ -21,3 +26,5 @@ instance Read TrustLevel where
|
||||||
readsPrec _ "1" = [(Trusted, "")]
|
readsPrec _ "1" = [(Trusted, "")]
|
||||||
readsPrec _ "0" = [(UnTrusted, "")]
|
readsPrec _ "0" = [(UnTrusted, "")]
|
||||||
readsPrec _ _ = [(SemiTrusted, "")]
|
readsPrec _ _ = [(SemiTrusted, "")]
|
||||||
|
|
||||||
|
type TrustMap = M.Map UUID TrustLevel
|
Loading…
Add table
Add a link
Reference in a new issue