summaryrefslogtreecommitdiff
path: root/Types
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-02-03 13:40:14 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-02-03 13:58:53 -0400
commit4cded2bc85d530dd335738cb870daf3a2d4e4a2f (patch)
tree6b84dd8cf04f9fa17d3de55c17e4139278f398bd /Types
parentc35b2728cffdb98fa3b962505ebb0f1d2304ecce (diff)
annex.autocommit can be configured via git-annex config
... to control the default behavior in all clones of a repository. This includes a new Configurable data type, so the GitConfig type indicates which values can be configured this way. The implementation should be quite efficient; the config log is only read once, and only when a Configurable value has not already been set by git-config. Indeed, it would be nice in the future to extend this, so that git-config is itself only read on demand. Some commands may not need to look at the git configuration at all. This commit was sponsored by Trenton Cronholm on Patreon.
Diffstat (limited to 'Types')
-rw-r--r--Types/GitConfig.hs31
1 files changed, 29 insertions, 2 deletions
diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs
index 33f102e1d..b972697d7 100644
--- a/Types/GitConfig.hs
+++ b/Types/GitConfig.hs
@@ -6,8 +6,10 @@
-}
module Types.GitConfig (
+ Configurable(..),
GitConfig(..),
extractGitConfig,
+ mergeGitConfig,
RemoteGitConfig(..),
extractRemoteGitConfig,
) where
@@ -29,6 +31,14 @@ import Utility.HumanTime
import Utility.Gpg (GpgCmd, mkGpgCmd)
import Utility.ThreadScheduler (Seconds(..))
+-- | A configurable value, that may not be fully determined yet.
+data Configurable a
+ = HasConfig a
+ -- ^ Value is fully determined.
+ | DefaultConfig a
+ -- ^ A default value is known, but not all config sources
+ -- have been read yet.
+
{- Main git-annex settings. Each setting corresponds to a git-config key
- such as annex.foo -}
data GitConfig = GitConfig
@@ -46,7 +56,7 @@ data GitConfig = GitConfig
, annexDelayAdd :: Maybe Int
, annexHttpHeaders :: [String]
, annexHttpHeadersCommand :: Maybe String
- , annexAutoCommit :: Bool
+ , annexAutoCommit :: Configurable Bool
, annexDebug :: Bool
, annexWebOptions :: [String]
, annexQuviOptions :: [String]
@@ -93,7 +103,8 @@ extractGitConfig r = GitConfig
, annexDelayAdd = getmayberead (annex "delayadd")
, annexHttpHeaders = getlist (annex "http-headers")
, annexHttpHeadersCommand = getmaybe (annex "http-headers-command")
- , annexAutoCommit = getbool (annex "autocommit") True
+ , annexAutoCommit = configurable True $
+ getmaybebool (annex "autocommit")
, annexDebug = getbool (annex "debug") False
, annexWebOptions = getwords (annex "web-options")
, annexQuviOptions = getwords (annex "quvi-options")
@@ -133,10 +144,26 @@ extractGitConfig r = GitConfig
getlist k = Git.Config.getList k r
getwords k = fromMaybe [] $ words <$> getmaybe k
+ configurable d Nothing = DefaultConfig d
+ configurable _ (Just v) = HasConfig v
+
annex k = "annex." ++ k
onemegabyte = 1000000
+{- Merge a GitConfig that comes from git-config with one containing
+ - repository-global defaults. -}
+mergeGitConfig :: GitConfig -> GitConfig -> GitConfig
+mergeGitConfig gitconfig repoglobals = gitconfig
+ { annexAutoCommit = merge annexAutoCommit
+ }
+ where
+ merge f = case f gitconfig of
+ HasConfig v -> HasConfig v
+ DefaultConfig d -> case f repoglobals of
+ HasConfig v -> HasConfig v
+ DefaultConfig _ -> HasConfig d
+
{- Per-remote git-annex settings. Each setting corresponds to a git-config
- key such as <remote>.annex-foo, or if that is not set, a default from
- annex.foo -}