From bf460a0a98d7e4c7f4eac525fcf300629db582b6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 8 Nov 2011 15:34:10 -0400 Subject: 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. --- Config.hs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'Config.hs') diff --git a/Config.hs b/Config.hs index bf929219d..c24ab9d04 100644 --- a/Config.hs +++ b/Config.hs @@ -16,19 +16,17 @@ type ConfigKey = String {- Changes a git config setting in both internal state and .git/config -} setConfig :: ConfigKey -> String -> Annex () setConfig k value = do - g <- gitRepo - liftIO $ Git.run g "config" [Param k, Param value] + inRepo $ Git.run "config" [Param k, Param value] -- re-read git config and update the repo's state - g' <- liftIO $ Git.configRead g - Annex.changeState $ \s -> s { Annex.repo = g' } + newg <- inRepo $ Git.configRead + Annex.changeState $ \s -> s { Annex.repo = newg } {- Looks up a per-remote config setting in git config. - Failing that, tries looking for a global config option. -} getConfig :: Git.Repo -> ConfigKey -> String -> Annex String getConfig r key def = do - g <- gitRepo - let def' = Git.configGet g ("annex." ++ key) def - return $ Git.configGet g (remoteConfig r key) def' + def' <- fromRepo $ Git.configGet ("annex." ++ key) def + fromRepo $ Git.configGet (remoteConfig r key) def' remoteConfig :: Git.Repo -> ConfigKey -> String remoteConfig r key = "remote." ++ fromMaybe "" (Git.repoRemoteName r) ++ ".annex-" ++ key @@ -87,7 +85,5 @@ getNumCopies v = Annex.getState Annex.forcenumcopies >>= maybe (use v) (return . id) where use (Just n) = return n - use Nothing = do - g <- gitRepo - return $ read $ Git.configGet g config "1" + use Nothing = read <$> fromRepo (Git.configGet config "1") config = "annex.numcopies" -- cgit v1.2.3