summaryrefslogtreecommitdiff
path: root/Annex.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-12-29 23:10:18 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-12-29 23:10:18 -0400
commit652f844e2348165062868cb197ee725d42198f03 (patch)
tree2d6a26a3659e54428fdf893bc9919ffb0b6de5de /Annex.hs
parent69650c5989432cd83067614421c6bc3ef0cccab7 (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 'Annex.hs')
-rw-r--r--Annex.hs25
1 files changed, 22 insertions, 3 deletions
diff --git a/Annex.hs b/Annex.hs
index d314d3ec7..bb3548b00 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -1,6 +1,6 @@
{- git-annex monad
-
- - Copyright 2010-2011 Joey Hess <joey@kitenet.net>
+ - Copyright 2010-2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -28,6 +28,9 @@ module Annex (
gitRepo,
inRepo,
fromRepo,
+ getConfig,
+ changeConfig,
+ changeGitRepo,
) where
import "mtl" Control.Monad.State.Strict
@@ -43,6 +46,7 @@ import Git.CheckAttr
import Git.SharedRepository
import qualified Git.Queue
import Types.Backend
+import Types.Config
import qualified Types.Remote
import Types.Crypto
import Types.BranchState
@@ -88,6 +92,7 @@ type PreferredContentMap = M.Map UUID (Utility.Matcher.Matcher (S.Set UUID -> Fi
-- internal state storage
data AnnexState = AnnexState
{ repo :: Git.Repo
+ , config :: Config
, backends :: [BackendA Annex]
, remotes :: [Types.Remote.RemoteA Annex]
, output :: MessageState
@@ -99,7 +104,6 @@ data AnnexState = AnnexState
, catfilehandle :: Maybe CatFileHandle
, checkattrhandle :: Maybe CheckAttrHandle
, forcebackend :: Maybe String
- , forcenumcopies :: Maybe Int
, limit :: Matcher (FileInfo -> Annex Bool)
, uuidmap :: Maybe UUIDMap
, preferredcontentmap :: Maybe PreferredContentMap
@@ -118,6 +122,7 @@ data AnnexState = AnnexState
newState :: Git.Repo -> AnnexState
newState gitrepo = AnnexState
{ repo = gitrepo
+ , config = extractConfig gitrepo
, backends = []
, remotes = []
, output = defaultMessageState
@@ -129,7 +134,6 @@ newState gitrepo = AnnexState
, catfilehandle = Nothing
, checkattrhandle = Nothing
, forcebackend = Nothing
- , forcenumcopies = Nothing
, limit = Left []
, uuidmap = Nothing
, preferredcontentmap = Nothing
@@ -197,3 +201,18 @@ inRepo a = liftIO . a =<< gitRepo
{- Extracts a value from the annex's git repisitory. -}
fromRepo :: (Git.Repo -> a) -> Annex a
fromRepo a = a <$> gitRepo
+
+{- Gets the Config settings. -}
+getConfig :: Annex Config
+getConfig = getState config
+
+{- Modifies a Config setting. -}
+changeConfig :: (Config -> Config) -> Annex ()
+changeConfig a = changeState $ \s -> s { config = a (config s) }
+
+{- Changing the git Repo data also involves re-extracting its Config. -}
+changeGitRepo :: Git.Repo -> Annex ()
+changeGitRepo r = changeState $ \s -> s
+ { repo = r
+ , config = extractConfig r
+ }