From 652f844e2348165062868cb197ee725d42198f03 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 29 Dec 2012 23:10:18 -0400 Subject: type based git config handling Now there's a Config type, that's extracted from the git config at startup. Note that laziness means that individual config values are only looked up and parsed on demand, and so we get implicit memoization for all of them. So this is not only prettier and more type safe, it optimises several places that didn't have explicit memoization before. As well as getting rid of the ugly explicit memoization code. Not yet done for annex..* configuration settings. --- Backend.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'Backend.hs') diff --git a/Backend.hs b/Backend.hs index 1e3d8f94f..4972288c3 100644 --- a/Backend.hs +++ b/Backend.hs @@ -18,7 +18,6 @@ module Backend ( import System.Posix.Files import Common.Annex -import Config import qualified Annex import Annex.CheckAttr import Types.Key @@ -39,17 +38,18 @@ orderedList = do l <- Annex.getState Annex.backends -- list is cached here if not $ null l then return l - else handle =<< Annex.getState Annex.forcebackend + else do + f <- Annex.getState Annex.forcebackend + case f of + Just name | not (null name) -> + return [lookupBackendName name] + _ -> do + l' <- gen . annexBackends <$> Annex.getConfig + Annex.changeState $ \s -> s { Annex.backends = l' } + return l' where - handle Nothing = standard - handle (Just "") = standard - handle (Just name) = do - l' <- (lookupBackendName name :) <$> standard - Annex.changeState $ \s -> s { Annex.backends = l' } - return l' - standard = parseBackendList <$> getConfig (annexConfig "backends") "" - parseBackendList [] = list - parseBackendList s = map lookupBackendName $ words s + gen [] = list + gen l = map lookupBackendName l {- Generates a key for a file, trying each backend in turn until one - accepts it. -} -- cgit v1.2.3