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.
This commit is contained in:
Joey Hess 2012-12-29 23:10:18 -04:00
parent b62753c475
commit 7f7c31df1c
23 changed files with 151 additions and 103 deletions

View file

@ -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. -}