D2623: dispatch: adding config items for overriding flag defaults
rdamazio (Rodrigo Damazio Bovendorp)
phabricator at mercurial-scm.org
Sat Mar 3 23:58:52 UTC 2018
rdamazio updated this revision to Diff 6523.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D2623?vs=6521&id=6523
REVISION DETAIL
https://phab.mercurial-scm.org/D2623
AFFECTED FILES
mercurial/configitems.py
mercurial/dispatch.py
mercurial/ui.py
tests/test-dispatch.t
CHANGE DETAILS
diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t
--- a/tests/test-dispatch.t
+++ b/tests/test-dispatch.t
@@ -8,8 +8,10 @@
$ hg -v log -v x
$ echo a > a
+ $ echo b > b
$ hg ci -Ama
adding a
+ adding b
Missing arg:
@@ -52,10 +54,10 @@
Parsing of early options should stop at "--":
$ hg cat -- --config=hooks.pre-cat=false
- --config=hooks.pre-cat=false: no such file in rev cb9a9f314b8b
+ --config=hooks.pre-cat=false: no such file in rev 0cd96de13884
[1]
$ hg cat -- --debugger
- --debugger: no such file in rev cb9a9f314b8b
+ --debugger: no such file in rev 0cd96de13884
[1]
Unparsable form of early options:
@@ -155,31 +157,75 @@
abort: pre-log hook exited with status 1
[255]
$ HGPLAIN=+strictflags hg --cwd .. -q -Ra log -b default
- 0:cb9a9f314b8b
+ 0:0cd96de13884
$ HGPLAIN=+strictflags hg --cwd .. -q --repository a log -b default
- 0:cb9a9f314b8b
+ 0:0cd96de13884
$ HGPLAIN=+strictflags hg --cwd .. -q --repo a log -b default
- 0:cb9a9f314b8b
+ 0:0cd96de13884
For compatibility reasons, HGPLAIN=+strictflags is not enabled by plain HGPLAIN:
$ HGPLAIN= hg log --config='hooks.pre-log=false' -b default
abort: pre-log hook exited with status 1
[255]
$ HGPLAINEXCEPT= hg log --cwd .. -q -Ra -b default
- 0:cb9a9f314b8b
+ 0:0cd96de13884
[defaults]
$ hg cat a
a
+ $ cp $HGRCPATH hgrc.bak
$ cat >> $HGRCPATH <<EOF
> [defaults]
> cat = -r null
> EOF
$ hg cat a
a: no such file in rev 000000000000
[1]
+ $ cp -f hgrc.bak $HGRCPATH
+
+new-style [commands] defaults and overrides
+
+ $ hg cat a
+ a
+ $ cat >> $HGRCPATH <<EOF
+ > [commands]
+ > cat.default.rev = null
+ > EOF
+ $ hg cat a
+ a: no such file in rev 000000000000
+ [1]
+
+ $ mv -f hgrc.bak $HGRCPATH
+ $ echo foo >> a
+ $ hg rm b
+ $ echo bar > c
+ $ hg add c
+ $ hg status
+ M a
+ A c
+ R b
+ ? bad.py
+ ? bad.pyc
+ $ cat >> $HGRCPATH <<EOF
+ > [commands]
+ > status.default.removed = 1
+ > EOF
+ $ hg status
+ R b
+ $ hg status --modified
+ M a
+ R b
+ $ hg status --modified --no-removed
+ M a
+ $ hg status --no-removed
+ M a
+ A c
+ R b
+ ? bad.py
+ ? bad.pyc
+ $ hg revert a b c
$ cd "$TESTTMP"
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -379,10 +379,15 @@
del cfg['defaults'][k]
for k, v in cfg.items('commands'):
del cfg['commands'][k]
- # Don't remove aliases from the configuration if in the exceptionlist
+ # Don't remove specific sections from the configuration if in the
+ # exception list.
if self.plain('alias'):
for k, v in cfg.items('alias'):
del cfg['alias'][k]
+ if self.plain('commanddefaults'):
+ for k, v in cfg.items('commands'):
+ if '.default.' in k:
+ del cfg['commands'][k]
if self.plain('revsetalias'):
for k, v in cfg.items('revsetalias'):
del cfg['revsetalias'][k]
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -611,6 +611,21 @@
args = pycompat.maplist(
util.expandpath, pycompat.shlexsplit(defaults)) + args
c = list(entry[1])
+
+ # Apply new-style defaults from config file by actually changing the
+ # option defaults. We still let old-style defaults trump these (since
+ # those are added to the command line).
+ for idx, opt in enumerate(c):
+ optname = opt[1]
+ olddefault = opt[2]
+ defaulttype = type(olddefault)
+ cfgitem = "%s.default.%s" % (cmd, optname)
+ # parse the new default as the same type as the original.
+ newdefault = ui.configtyped("commands", cfgitem, defaulttype, olddefault)
+ if olddefault != newdefault:
+ # override the default in the flag declaration.
+ c[idx] = (opt[0], opt[1], newdefault, opt[3])
+
else:
cmd = None
c = []
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -184,6 +184,10 @@
coreconfigitem('color', 'pagermode',
default=dynamicdefault,
)
+coreconfigitem('commands', '.*\.default\..*',
+ generic=True,
+ default=dynamicdefault,
+)
coreconfigitem('commands', 'show.aliasprefix',
default=list,
)
To: rdamazio, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list