From 339464e847d52cbe8745605e07e7ffb7368647c4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 30 Jan 2017 16:41:29 -0400 Subject: [PATCH] config: New command for storing configuration in the git-annex branch. Any config names can be set using this; git-annex commands will only look at specific ones that make sense and are worth the overhead of querying the branch. This might also be useful for storing whatever other config-type stuff the user might want to shove into the git-annex branch. This commit was sponsored by Jochen Bartl on Patreon. --- Annex.hs | 2 + Annex/Branch.hs | 2 +- CHANGELOG | 1 + CmdLine/GitAnnex.hs | 2 + Command/Config.hs | 65 +++++++++++++++++++ Logs.hs | 3 + doc/git-annex-config.mdwn | 56 ++++++++++++++++ doc/git-annex-sync.mdwn | 4 +- doc/git-annex.mdwn | 9 +++ doc/internals.mdwn | 10 +++ ..._851483817d97de212932203c2e830293._comment | 38 +++++++++++ 11 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 Command/Config.hs create mode 100644 doc/git-annex-config.mdwn create mode 100644 doc/todo/wishlist__58___per-repository_autocommit__61__false/comment_1_851483817d97de212932203c2e830293._comment diff --git a/Annex.hs b/Annex.hs index 1ee6e837f1..18b4f48c9f 100644 --- a/Annex.hs +++ b/Annex.hs @@ -114,6 +114,7 @@ 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 @@ -165,6 +166,7 @@ newState c r = do , checkignorehandle = Nothing , forcebackend = Nothing , globalnumcopies = Nothing + , globalconfig = Nothing , forcenumcopies = Nothing , limit = BuildingMatcher [] , uuidmap = Nothing diff --git a/Annex/Branch.hs b/Annex/Branch.hs index c90958ab05..9d963f98b0 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -233,7 +233,7 @@ getHistorical date file = getRef :: Ref -> FilePath -> Annex String getRef ref file = withIndex $ decodeBS <$> catFile ref file -{- Applies a function to modifiy the content of a file. +{- Applies a function to modify the content of a file. - - Note that this does not cause the branch to be merged, it only - modifes the current content of the file on the branch. diff --git a/CHANGELOG b/CHANGELOG index 57994f1560..14dad2bfec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ git-annex (6.20170102) UNRELEASED; urgency=medium * Remove -j short option for --json-progress; that option was already taken for --json. * vicfg: Include the numcopies configuation. + * config: New command for storing configuration in the git-annex branch. -- Joey Hess Fri, 06 Jan 2017 15:22:06 -0400 diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs index 394bd173bf..99cf564cc1 100644 --- a/CmdLine/GitAnnex.hs +++ b/CmdLine/GitAnnex.hs @@ -84,6 +84,7 @@ import qualified Command.GroupWanted import qualified Command.Required import qualified Command.Schedule import qualified Command.Ungroup +import qualified Command.Config import qualified Command.Vicfg import qualified Command.Sync import qualified Command.Mirror @@ -158,6 +159,7 @@ cmds testoptparser testrunner = , Command.Required.cmd , Command.Schedule.cmd , Command.Ungroup.cmd + , Command.Config.cmd , Command.Vicfg.cmd , Command.LookupKey.cmd , Command.CalcKey.cmd diff --git a/Command/Config.hs b/Command/Config.hs new file mode 100644 index 0000000000..690c8d2888 --- /dev/null +++ b/Command/Config.hs @@ -0,0 +1,65 @@ +{- git-annex command + - + - Copyright 2017 Joey Hess + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.Config where + +import Command +import Logs.Config + +cmd :: Command +cmd = command "config" SectionSetup "configuration stored in git-annex branch" + paramNothing (seek <$$> optParser) + +data Action + = SetConfig ConfigName ConfigValue + | GetConfig ConfigName + | UnsetConfig ConfigName + +type Name = String +type Value = String + +optParser :: CmdParamsDesc -> Parser Action +optParser _ = setconfig <|> getconfig <|> unsetconfig + where + setconfig = SetConfig + <$> strOption + ( long "set" + <> help "set configuration" + <> metavar paramName + ) + <*> strArgument + ( metavar paramValue + ) + getconfig = GetConfig <$> strOption + ( long "get" + <> help "get configuration" + <> metavar paramName + ) + unsetconfig = UnsetConfig <$> strOption + ( long "unset" + <> help "unset configuration" + <> metavar paramName + ) + +seek :: Action -> CommandSeek +seek (SetConfig name val) = commandAction $ do + showStart name val + next $ next $ do + setGlobalConfig name val + return True +seek (UnsetConfig name) = commandAction $ do + showStart name "unset" + next $ next $ do + unsetGlobalConfig name + return True +seek (GetConfig name) = commandAction $ do + mv <- getGlobalConfig name + case mv of + Nothing -> stop + Just v -> do + liftIO $ putStrLn v + stop diff --git a/Logs.hs b/Logs.hs index a3dd968880..38bd1c0683 100644 --- a/Logs.hs +++ b/Logs.hs @@ -63,6 +63,9 @@ uuidLog = "uuid.log" numcopiesLog :: FilePath numcopiesLog = "numcopies.log" +configLog :: FilePath +configLog = "config.log" + remoteLog :: FilePath remoteLog = "remote.log" diff --git a/doc/git-annex-config.mdwn b/doc/git-annex-config.mdwn new file mode 100644 index 0000000000..1e1819bb7f --- /dev/null +++ b/doc/git-annex-config.mdwn @@ -0,0 +1,56 @@ +# NAME + +git-annex config - configuration stored in git-annex branch + +# SYNOPSIS + +git annex config --set name value + +git annex config --get name + +git annex config --unset name + +# DESCRIPTION + +Set or get configuration settings stored in the git-annex branch. + +Unlike `git config` settings, these settings can be seen +in all clones of the repository, once they have gotten their +git-annex branches in sync. + +# SUPPORTED SETTINGS + +git-annex does not check the git-annex branch for all settings. +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`: + +None yet! + +# EXAMPLE + +Suppose you want to prevent git annex sync from committing changes +to files, so a manual git commit workflow is used in all clones of the +repository. Then run: + + git annex config --set annex.autocommit false + +If you change your mind, you can get back to the default behavior: + + git annex config --unset annex.autocommit + +# SEE ALSO + +[[git-annex]](1) + +git-config(1) + +[[git-annex-vicfg]](1) + +# AUTHOR + +Joey Hess + +Warning: Automatically converted into a man page by mdwn2man. Edit with care. diff --git a/doc/git-annex-sync.mdwn b/doc/git-annex-sync.mdwn index d60033de45..f0dce81143 100644 --- a/doc/git-annex-sync.mdwn +++ b/doc/git-annex-sync.mdwn @@ -42,7 +42,9 @@ by running "git annex sync" on the remote. * `--commit`, `--no-commit` - A commit is done by default. Use --no-commit to avoid committing local changes. + A commit is done by default (unless annex.autocommit is set to false). + + Use --no-commit to avoid committing local changes. * `--message=msg` diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index ca1ac3620f..af6342164f 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -280,6 +280,12 @@ subdirectories). See [[git-annex-schedule]](1) for details. +* `config` + + Get and set other configuration stored in git-annex branch. + + See [[git-annex-config]](1) for details. + * `vicfg` Opens EDITOR on a temp file containing most of the above configuration @@ -1000,6 +1006,9 @@ 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]]. + * `annex.startupscan` Set to false to prevent the git-annex assistant from scanning the diff --git a/doc/internals.mdwn b/doc/internals.mdwn index 329961ccdb..78d0c8d472 100644 --- a/doc/internals.mdwn +++ b/doc/internals.mdwn @@ -100,6 +100,16 @@ Records the global numcopies setting. The file format is simply a timestamp followed by a number. +## `config.log` + +Records global configuration settings, which can be overridden by values +in `.git/config`. + +The file format is a timestamp, followed by the name of the configuration, +followed by the value. For example: + + 1317929189.157237s annex.autocommit false + ## `remote.log` Holds persistent configuration settings for [[special_remotes]] such as diff --git a/doc/todo/wishlist__58___per-repository_autocommit__61__false/comment_1_851483817d97de212932203c2e830293._comment b/doc/todo/wishlist__58___per-repository_autocommit__61__false/comment_1_851483817d97de212932203c2e830293._comment new file mode 100644 index 0000000000..7e5d850385 --- /dev/null +++ b/doc/todo/wishlist__58___per-repository_autocommit__61__false/comment_1_851483817d97de212932203c2e830293._comment @@ -0,0 +1,38 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2017-01-30T18:13:42Z" + content=""" +This could be put in the git-annex branch similarly to the `git annex +numcopies` configuration so all clones see it. + +As well as --no-commit, --content is the other option that I think +might make sense to have a clone-wide setting for. sync's --no-pull and +--no-push seem much less likely to need such a setting. + +I've been leaning toward eventually turning sync --content on by default, +and such a clone-wide configuration would be useful to let users get back +the current behavior. + +Hmm, this could be generalized all the way to having a file in the +git-annex branch that stores default settings for `annex.*` configs. +But then git-annex would have to pull that file out of the git-annex branch +every time it's run, which would slow down commands that get run a lot in +succession. So that's a generalization too far. + +Still, looking through the configs, I can see some other things +that it would similarly make sense to sometimes want to set clone-wide, +including: annex.genmetadata, annex.used-refspec, annex.diskreserve, +annex.addsmallfiles. + +So, we have some configs that are each only used by a few commands, +that make sense to be allowed to be set clone-wide. We can make the file +in the git-annex branch be only read by commands that look at those +configs, and can consider when implementing each whether it would slow +down any command too much to have it need to read the git-annex branch +file. + +I've added a `git annex config` command that can set such clone-wide +configurations. I have not yet made git annex sync look at it for +annex.autocommit. +"""]]