summaryrefslogtreecommitdiff
path: root/Config.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-05-05 20:15:32 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-05-05 20:16:56 -0400
commitf7d8982672fd330a466c2cb22f34388e7cc429c0 (patch)
treeb5739058cc2cb04fa4a119df2cecf449d4846c03 /Config.hs
parent657d09d49990af85c1a91b1154a195a30438477c (diff)
Fix use of several config settings
annex.ssh-options, annex.rsync-options, annex.bup-split-options. And adjust types to avoid the bugs that broke several config settings recently. Now "annex." prefixing is enforced at the type level.
Diffstat (limited to 'Config.hs')
-rw-r--r--Config.hs43
1 files changed, 28 insertions, 15 deletions
diff --git a/Config.hs b/Config.hs
index 3feb246e5..5f1ac8bb2 100644
--- a/Config.hs
+++ b/Config.hs
@@ -1,6 +1,6 @@
{- Git configuration
-
- - Copyright 2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2011-2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -14,29 +14,40 @@ import qualified Git.Command
import qualified Annex
import Utility.DataUnits
-type ConfigKey = String
+type UnqualifiedConfigKey = String
+data ConfigKey = ConfigKey String
{- Changes a git config setting in both internal state and .git/config -}
setConfig :: ConfigKey -> String -> Annex ()
-setConfig k value = do
- inRepo $ Git.Command.run "config" [Param k, Param value]
+setConfig (ConfigKey key) value = do
+ inRepo $ Git.Command.run "config" [Param key, Param value]
-- re-read git config and update the repo's state
newg <- inRepo Git.Config.read
Annex.changeState $ \s -> s { Annex.repo = newg }
-{- Looks up a git config setting in git config. -}
+{- Unsets a git config setting. (Leaves it in state currently.) -}
+unsetConfig :: ConfigKey -> Annex ()
+unsetConfig (ConfigKey key) = inRepo $ Git.Command.run "config"
+ [Param "--unset", Param key]
+
+{- Looks up a setting in git config. -}
getConfig :: ConfigKey -> String -> Annex String
-getConfig key def = fromRepo $ Git.Config.get key def
+getConfig (ConfigKey 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. -}
-getRemoteConfig :: Git.Repo -> ConfigKey -> String -> Annex String
-getRemoteConfig r key def =
- getConfig (remoteConfig r key) =<< getConfig key def
+getRemoteConfig :: Git.Repo -> UnqualifiedConfigKey -> String -> Annex String
+getRemoteConfig r key def =
+ getConfig (remoteConfig r key) =<< getConfig (annexConfig key) def
{- A per-remote config setting in git config. -}
-remoteConfig :: Git.Repo -> ConfigKey -> String
-remoteConfig r key = "remote." ++ fromMaybe "" (Git.remoteName r) ++ ".annex-" ++ key
+remoteConfig :: Git.Repo -> UnqualifiedConfigKey -> ConfigKey
+remoteConfig r key = ConfigKey $
+ "remote." ++ fromMaybe "" (Git.remoteName r) ++ ".annex-" ++ key
+
+{- A global annex setting in git config. -}
+annexConfig :: UnqualifiedConfigKey -> ConfigKey
+annexConfig key = ConfigKey $ "annex." ++ key
{- Calculates cost for a remote. Either the default, or as configured
- by remote.<name>.annex-cost, or if remote.<name>.annex-cost-command
@@ -83,17 +94,19 @@ getNumCopies v = perhaps (use v) =<< Annex.getState Annex.forcenumcopies
where
use (Just n) = return n
use Nothing = perhaps (return 1) =<<
- readish <$> getConfig "annex.numcopies" "1"
+ readish <$> getConfig (annexConfig "numcopies") "1"
perhaps fallback = maybe fallback (return . id)
{- Gets the trust level set for a remote in git config. -}
getTrustLevel :: Git.Repo -> Annex (Maybe String)
-getTrustLevel r = fromRepo $ Git.Config.getMaybe $ remoteConfig r "trustlevel"
+getTrustLevel r = fromRepo $ Git.Config.getMaybe key
+ where
+ (ConfigKey key) = remoteConfig r "trustlevel"
{- Gets annex.diskreserve setting. -}
getDiskReserve :: Annex Integer
getDiskReserve = fromMaybe megabyte . readSize dataUnits
- <$> getConfig "annex.diskreserve" ""
+ <$> getConfig (annexConfig "diskreserve") ""
where
megabyte = 1000000
@@ -101,7 +114,7 @@ getDiskReserve = fromMaybe megabyte . readSize dataUnits
- splitting it into lines. -}
getHttpHeaders :: Annex [String]
getHttpHeaders = do
- cmd <- getConfig "annex.http-headers-command" ""
+ cmd <- getConfig (annexConfig "http-headers-command") ""
if (null cmd)
then fromRepo $ Git.Config.getList "annex.http-headers"
else lines . snd <$> liftIO (pipeFrom "sh" ["-c", cmd])