summaryrefslogtreecommitdiff
path: root/Config.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-03-21 23:41:01 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-03-22 17:32:47 -0400
commit4eb51126819fe01a003688267f481c6d8014ef47 (patch)
tree40f88312d53da654b65a7ed25617e5bdbd6be03c /Config.hs
parent52b90e5d4c2a22415d48a8e572eab328dfcc4407 (diff)
rationalize getConfig
getConfig got a remote-specific config, and this confusing name caused it to be used a couple of places that only were interested in global configs. Rename to getRemoteConfig and make getConfig only get global configs. There are no behavior changes here, but remote.<name>.annex-web-options never actually worked (and per-remote web options is a very unlikely to be useful case so I didn't make it work), so fix the documentation for it.
Diffstat (limited to 'Config.hs')
-rw-r--r--Config.hs20
1 files changed, 12 insertions, 8 deletions
diff --git a/Config.hs b/Config.hs
index aecf77a2a..39fe3333b 100644
--- a/Config.hs
+++ b/Config.hs
@@ -25,11 +25,15 @@ setConfig k value = do
newg <- inRepo Git.Config.read
Annex.changeState $ \s -> s { Annex.repo = newg }
+{- Looks up a git config setting in git config. -}
+getConfig :: ConfigKey -> String -> Annex String
+getConfig key def = fromRepo $ Git.Config.get key def
+
{- 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
- def' <- fromRepo $ Git.Config.get ("annex." ++ key) def
+getRemoteConfig :: Git.Repo -> ConfigKey -> String -> Annex String
+getRemoteConfig r key def = do
+ def' <- getConfig key def
fromRepo $ Git.Config.get (remoteConfig r key) def'
{- A per-remote config setting in git config. -}
@@ -41,11 +45,11 @@ remoteConfig r key = "remote." ++ fromMaybe "" (Git.remoteName r) ++ ".annex-" +
- is set and prints a number, that is used. -}
remoteCost :: Git.Repo -> Int -> Annex Int
remoteCost r def = do
- cmd <- getConfig r "cost-command" ""
+ cmd <- getRemoteConfig r "cost-command" ""
(fromMaybe def . readish) <$>
if not $ null cmd
then liftIO $ snd <$> pipeFrom "sh" ["-c", cmd]
- else getConfig r "cost" ""
+ else getRemoteConfig r "cost" ""
cheapRemoteCost :: Int
cheapRemoteCost = 100
@@ -71,7 +75,8 @@ prop_cost_sane = False `notElem`
{- Checks if a repo should be ignored. -}
repoNotIgnored :: Git.Repo -> Annex Bool
-repoNotIgnored r = not . fromMaybe False . Git.configTrue <$> getConfig r "ignore" ""
+repoNotIgnored r = not . fromMaybe False . Git.configTrue
+ <$> getRemoteConfig r "ignore" ""
{- If a value is specified, it is used; otherwise the default is looked up
- in git config. forcenumcopies overrides everything. -}
@@ -91,8 +96,7 @@ getTrustLevel r = fromRepo $ Git.Config.getMaybe $ remoteConfig r "trustlevel"
{- Gets annex.diskreserve setting. -}
getDiskReserve :: Bool -> Annex Integer
getDiskReserve sanitycheck = do
- g <- gitRepo
- r <- getConfig g "diskreserve" ""
+ r <- getConfig "diskreserve" ""
when sanitycheck $ check r
return $ fromMaybe megabyte $ readSize dataUnits r
where