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.
This commit is contained in:
parent
26d23e38f1
commit
339464e847
11 changed files with 190 additions and 2 deletions
2
Annex.hs
2
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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 <id@joeyh.name> Fri, 06 Jan 2017 15:22:06 -0400
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
65
Command/Config.hs
Normal file
65
Command/Config.hs
Normal file
|
@ -0,0 +1,65 @@
|
|||
{- git-annex command
|
||||
-
|
||||
- Copyright 2017 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- 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
|
3
Logs.hs
3
Logs.hs
|
@ -63,6 +63,9 @@ uuidLog = "uuid.log"
|
|||
numcopiesLog :: FilePath
|
||||
numcopiesLog = "numcopies.log"
|
||||
|
||||
configLog :: FilePath
|
||||
configLog = "config.log"
|
||||
|
||||
remoteLog :: FilePath
|
||||
remoteLog = "remote.log"
|
||||
|
||||
|
|
56
doc/git-annex-config.mdwn
Normal file
56
doc/git-annex-config.mdwn
Normal file
|
@ -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 <id@joeyh.name>
|
||||
|
||||
Warning: Automatically converted into a man page by mdwn2man. Edit with care.
|
|
@ -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`
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
"""]]
|
Loading…
Reference in a new issue