summaryrefslogtreecommitdiff
path: root/Backend.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-08 15:34:10 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-08 16:27:20 -0400
commitbf460a0a98d7e4c7f4eac525fcf300629db582b6 (patch)
treebff7cd09529c40fa8cb76fd92428cc41e24ad808 /Backend.hs
parent2ff8915365099501382183af9855e739fc234861 (diff)
reorder repo parameters last
Many functions took the repo as their first parameter. Changing it consistently to be the last parameter allows doing some useful things with currying, that reduce boilerplate. In particular, g <- gitRepo is almost never needed now, instead use inRepo to run an IO action in the repo, and fromRepo to get a value from the repo. This also provides more opportunities to use monadic and applicative combinators.
Diffstat (limited to 'Backend.hs')
-rw-r--r--Backend.hs19
1 files changed, 7 insertions, 12 deletions
diff --git a/Backend.hs b/Backend.hs
index 9a40e5459..f7990c22c 100644
--- a/Backend.hs
+++ b/Backend.hs
@@ -47,10 +47,7 @@ orderedList = do
l' <- (lookupBackendName name :) <$> standard
Annex.changeState $ \s -> s { Annex.backends = l' }
return l'
- standard = do
- g <- gitRepo
- return $ parseBackendList $
- Git.configGet g "annex.backends" ""
+ standard = fromRepo $ parseBackendList . Git.configGet "annex.backends" ""
parseBackendList [] = list
parseBackendList s = map lookupBackendName $ words s
@@ -96,16 +93,14 @@ type BackendFile = (Maybe (Backend Annex), FilePath)
- That can be configured on a per-file basis in the gitattributes file.
-}
chooseBackends :: [FilePath] -> Annex [BackendFile]
-chooseBackends fs = do
- g <- gitRepo
- forced <- Annex.getState Annex.forcebackend
- if isJust forced
- then do
+chooseBackends fs = Annex.getState Annex.forcebackend >>= go
+ where
+ go Nothing = do
+ pairs <- inRepo $ Git.checkAttr "annex.backend" fs
+ return $ map (\(f,b) -> (maybeLookupBackendName b, f)) pairs
+ go (Just _) = do
l <- orderedList
return $ map (\f -> (Just $ head l, f)) fs
- else do
- pairs <- liftIO $ Git.checkAttr g "annex.backend" fs
- return $ map (\(f,b) -> (maybeLookupBackendName b, f)) pairs
{- Looks up a backend by name. May fail if unknown. -}
lookupBackendName :: String -> Backend Annex