diff options
author | Joey Hess <joey@kitenet.net> | 2012-12-29 23:10:18 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-12-29 23:10:18 -0400 |
commit | 652f844e2348165062868cb197ee725d42198f03 (patch) | |
tree | 2d6a26a3659e54428fdf893bc9919ffb0b6de5de /Backend.hs | |
parent | 69650c5989432cd83067614421c6bc3ef0cccab7 (diff) |
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.<remote>.* configuration settings.
Diffstat (limited to 'Backend.hs')
-rw-r--r-- | Backend.hs | 22 |
1 files changed, 11 insertions, 11 deletions
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. -} |