summaryrefslogtreecommitdiff
path: root/Types
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2012-12-29 23:10:18 -0400
committerJoey Hess <joey@kitenet.net>2012-12-29 23:10:18 -0400
commit7f7c31df1cbc6fc7fadb61dab3991ba1d6578783 (patch)
tree798f4b506ab18eb8be932b1f8fc9b4457a7b2cd8 /Types
parentb62753c4757098606098841293bf0a81759e1e60 (diff)
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.
Diffstat (limited to 'Types')
-rw-r--r--Types/Config.hs64
1 files changed, 64 insertions, 0 deletions
diff --git a/Types/Config.hs b/Types/Config.hs
new file mode 100644
index 0000000000..898c153d56
--- /dev/null
+++ b/Types/Config.hs
@@ -0,0 +1,64 @@
+{- git-annex configuration
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Types.Config (
+ Config(..),
+ extractConfig,
+) where
+
+import Common
+import qualified Git
+import qualified Git.Config
+import Utility.DataUnits
+
+{- Main git-annex settings. Each setting corresponds to a git-config key
+ - such as annex.foo -}
+data Config = Config
+ { annexNumCopies :: Int
+ , annexDiskReserve :: Integer
+ , annexDirect :: Bool
+ , annexBackends :: [String]
+ , annexQueueSize :: Maybe Int
+ , annexBloomCapacity :: Maybe Int
+ , annexBloomAccuracy :: Maybe Int
+ , annexSshCaching :: Maybe Bool
+ , annexAlwaysCommit :: Bool
+ , annexDelayAdd :: Maybe Int
+ , annexHttpHeaders :: [String]
+ , annexHttpHeadersCommand :: Maybe String
+ }
+
+extractConfig :: Git.Repo -> Config
+extractConfig r = Config
+ { annexNumCopies = get "numcopies" 1
+ , annexDiskReserve = fromMaybe onemegabyte $
+ readSize dataUnits =<< getmaybe "diskreserve"
+ , annexDirect = getbool "direct" False
+ , annexBackends = fromMaybe [] $
+ words <$> getmaybe "backends"
+ , annexQueueSize = getmayberead "queuesize"
+ , annexBloomCapacity = getmayberead "bloomcapacity"
+ , annexBloomAccuracy = getmayberead "bloomaccuracy"
+ , annexSshCaching = getmaybebool "sshcaching"
+ , annexAlwaysCommit = getbool "alwayscommit" True
+ , annexDelayAdd = getmayberead "delayadd"
+ , annexHttpHeaders = getlist "http-headers"
+ , annexHttpHeadersCommand = getmaybe "http-headers-command"
+ }
+ where
+ get k def = fromMaybe def $ getmayberead k
+ getbool k def = fromMaybe def $ getmaybebool k
+ getmaybebool k = Git.Config.isTrue =<< getmaybe k
+ getmayberead k = readish =<< getmaybe k
+ getmaybe k = Git.Config.getMaybe (key k) r
+ getlist k = Git.Config.getList (key k) r
+ key k = "annex." ++ k
+
+ onemegabyte = 1000000
+
+{- Per-remote git-annex settings. Each setting corresponds to a git-config
+ - key such as annex.<remote>.foo -}