summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Annex.hs2
-rw-r--r--Assistant/Threads/Watcher.hs3
-rw-r--r--CHANGELOG2
-rw-r--r--Command/Sync.hs3
-rw-r--r--Config.hs5
-rw-r--r--Config/GitConfig.hs36
-rw-r--r--Logs/Config.hs16
-rw-r--r--Types/GitConfig.hs31
-rw-r--r--doc/git-annex-config.mdwn7
-rw-r--r--doc/git-annex.mdwn4
-rw-r--r--doc/todo/wishlist__58___per-repository_autocommit__61__false.mdwn2
-rw-r--r--git-annex.cabal1
12 files changed, 89 insertions, 23 deletions
diff --git a/Annex.hs b/Annex.hs
index 18b4f48c9..1ee6e837f 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -114,7 +114,6 @@ data AnnexState = AnnexState
, checkignorehandle :: Maybe (Maybe CheckIgnoreHandle)
, forcebackend :: Maybe String
, globalnumcopies :: Maybe NumCopies
- , globalconfig :: Maybe (M.Map String String)
, forcenumcopies :: Maybe NumCopies
, limit :: ExpandableMatcher Annex
, uuidmap :: Maybe UUIDMap
@@ -166,7 +165,6 @@ newState c r = do
, checkignorehandle = Nothing
, forcebackend = Nothing
, globalnumcopies = Nothing
- , globalconfig = Nothing
, forcenumcopies = Nothing
, limit = BuildingMatcher []
, uuidmap = Nothing
diff --git a/Assistant/Threads/Watcher.hs b/Assistant/Threads/Watcher.hs
index 4b82a799d..90bb3dc78 100644
--- a/Assistant/Threads/Watcher.hs
+++ b/Assistant/Threads/Watcher.hs
@@ -42,6 +42,7 @@ import Annex.InodeSentinal
import Git.Types
import Git.FilePath
import Config
+import Config.GitConfig
import Utility.ThreadScheduler
import Logs.Location
import qualified Database.Keys
@@ -83,7 +84,7 @@ instance E.Exception WatcherControl
watchThread :: NamedThread
watchThread = namedThread "Watcher" $
- ifM (liftAnnex $ annexAutoCommit <$> Annex.getGitConfig)
+ ifM (liftAnnex $ getGitConfigVal annexAutoCommit)
( runWatcher
, waitFor ResumeWatcher runWatcher
)
diff --git a/CHANGELOG b/CHANGELOG
index 2854b5f72..83a5f2300 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,8 @@ git-annex (6.20170102) UNRELEASED; urgency=medium
taken for --json.
* vicfg: Include the numcopies configuation.
* config: New command for storing configuration in the git-annex branch.
+ * annex.autocommit can be configured via git-annex config, to control
+ the default behavior in all clones of a repository.
* stack.yaml: Update to lts-7.18.
* Some optimisations to string splitting code.
* unused: When large files are checked right into git, avoid buffering
diff --git a/Command/Sync.hs b/Command/Sync.hs
index 85f1f2f2c..e69790799 100644
--- a/Command/Sync.hs
+++ b/Command/Sync.hs
@@ -39,6 +39,7 @@ import qualified Git.Ref
import qualified Git
import qualified Remote.Git
import Config
+import Config.GitConfig
import Annex.Wanted
import Annex.Content
import Command.Get (getKey')
@@ -237,7 +238,7 @@ commit o = stopUnless shouldcommit $ next $ next $ do
)
where
shouldcommit = pure (commitOption o)
- <&&> (annexAutoCommit <$> Annex.getGitConfig)
+ <&&> getGitConfigVal annexAutoCommit
commitMsg :: Annex String
commitMsg = do
diff --git a/Config.hs b/Config.hs
index 84736cac3..3eecf4a4e 100644
--- a/Config.hs
+++ b/Config.hs
@@ -1,6 +1,6 @@
{- Git configuration
-
- - Copyright 2011-2014 Joey Hess <id@joeyh.name>
+ - Copyright 2011-2017 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -24,7 +24,8 @@ data ConfigKey = ConfigKey String
instance Show ConfigKey where
show (ConfigKey s) = s
-{- Looks up a setting in git config. -}
+{- Looks up a setting in git config. This is not as efficient as using the
+ - GitConfig type. -}
getConfig :: ConfigKey -> String -> Annex String
getConfig (ConfigKey key) d = fromRepo $ Git.Config.get key d
diff --git a/Config/GitConfig.hs b/Config/GitConfig.hs
new file mode 100644
index 000000000..bac866f0e
--- /dev/null
+++ b/Config/GitConfig.hs
@@ -0,0 +1,36 @@
+{- git-annex configuration
+ -
+ - Copyright 2017 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Config.GitConfig where
+
+import Annex.Common
+import qualified Annex
+import Types.GitConfig
+import Git.Types
+import Logs.Config
+
+{- Gets a specific setting from GitConfig. If necessary, loads the
+ - repository-global defaults when the GitConfig does not yet
+ - have a value. -}
+getGitConfigVal :: (GitConfig -> Configurable a) -> Annex a
+getGitConfigVal f = do
+ v <- f <$> Annex.getGitConfig
+ case v of
+ HasConfig c -> return c
+ DefaultConfig _ -> do
+ r <- Annex.gitRepo
+ m <- loadGlobalConfig
+ let globalgc = extractGitConfig (r { config = m })
+ -- This merge of the repo-global config and the git
+ -- config makes all repository-global default
+ -- values populate the GitConfig with HasConfig
+ -- values, so it will only need to be done once.
+ Annex.changeGitConfig (\gc -> mergeGitConfig gc globalgc)
+ v' <- f <$> Annex.getGitConfig
+ case v' of
+ HasConfig c -> return c
+ DefaultConfig d -> return d
diff --git a/Logs/Config.hs b/Logs/Config.hs
index fc26db939..b16a64dba 100644
--- a/Logs/Config.hs
+++ b/Logs/Config.hs
@@ -1,4 +1,4 @@
-{- git-annex config log
+{- git-annex repository-global config log
-
- Copyright 2017 Joey Hess <id@joeyh.name>
-
@@ -15,7 +15,6 @@ module Logs.Config (
) where
import Annex.Common
-import qualified Annex
import Logs
import Logs.MapLog
import qualified Annex.Branch
@@ -44,18 +43,13 @@ unsetGlobalConfig name = do
when (curr /= Nothing) $
setGlobalConfig' name "" -- set to empty string to unset
+-- Reads the global config log every time.
getGlobalConfig :: ConfigName -> Annex (Maybe ConfigValue)
-getGlobalConfig name = do
- m <- maybe loadGlobalConfig return
- =<< Annex.getState Annex.globalconfig
- return (M.lookup name m)
+getGlobalConfig name = M.lookup name <$> loadGlobalConfig
parseGlobalConfig :: String -> MapLog ConfigName ConfigValue
parseGlobalConfig = parseMapLog Just Just
loadGlobalConfig :: Annex (M.Map ConfigName ConfigValue)
-loadGlobalConfig = do
- m <- M.filter (not . null) . simpleMap . parseGlobalConfig
- <$> Annex.Branch.get configLog
- Annex.changeState $ \s -> s { Annex.globalconfig = Just m }
- return m
+loadGlobalConfig = M.filter (not . null) . simpleMap . parseGlobalConfig
+ <$> Annex.Branch.get configLog
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 -}
diff --git a/doc/git-annex-config.mdwn b/doc/git-annex-config.mdwn
index 1e1819bb7..a6b7eb578 100644
--- a/doc/git-annex-config.mdwn
+++ b/doc/git-annex-config.mdwn
@@ -25,9 +25,12 @@ Only a few make sense to be able to set such that all clones of a
repository see the setting, and so git-annex only looks for these:
These settings can be overridden on a per-repository basis using
-`git config`:
+`git config`.
-None yet!
+* `annex.autocommit`
+
+ Set to false to prevent the git-annex assistant and git-annex sync
+ from automatically committing changes to files in the repository.
# EXAMPLE
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index af6342164..2763de22d 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -1006,8 +1006,8 @@ Here are all the supported configuration settings.
Set to false to prevent the git-annex assistant and git-annex sync
from automatically committing changes to files in the repository.
- To configure the behavior in all repositories, this can be set in
- [[git-annex-config]].
+ To configure the behavior in all clones of the repository,
+ this can be set in [[git-annex-config]].
* `annex.startupscan`
diff --git a/doc/todo/wishlist__58___per-repository_autocommit__61__false.mdwn b/doc/todo/wishlist__58___per-repository_autocommit__61__false.mdwn
index a71aaa363..40cdb0096 100644
--- a/doc/todo/wishlist__58___per-repository_autocommit__61__false.mdwn
+++ b/doc/todo/wishlist__58___per-repository_autocommit__61__false.mdwn
@@ -3,3 +3,5 @@ when using git-annex as a minority participant in a repository (eg. because in a
forgetting to do that explicit configuration results, in one sync command, easily results in an unwanted implicit commit that's pushed across remotes.
could there be a per-repository option (somewhere around .gitattributes, or maybe in the git-annex branch) that disables autocommits for the repository?
+
+> [[done]] --[[Joey]]
diff --git a/git-annex.cabal b/git-annex.cabal
index 2150be6f1..5bcc67315 100644
--- a/git-annex.cabal
+++ b/git-annex.cabal
@@ -793,6 +793,7 @@ Executable git-annex
Config
Config.Cost
Config.Files
+ Config.GitConfig
Creds
Crypto
Database.Fsck