D2623: dispatch: adding config items for overriding flag defaults

2020-01-24 Thread baymax (Baymax, Your Personal Patch-care Companion)
This revision now requires changes to proceed.
baymax added a comment.
baymax requested changes to this revision.


  There seems to have been no activities on this Diff for the past 3 Months.
  
  By policy, we are automatically moving it out of the `need-review` state.
  
  Please, move it back to `need-review` without hesitation if this diff should 
still be discussed.
  
  :baymax:need-review-idle:

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D2623/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

To: rdamazio, #hg-reviewers, yuja, baymax
Cc: dploch, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-27 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio added inline comments.

INLINE COMMENTS

> dploch wrote in dispatch.py:625-626
> This doesn't handle callables properly.  I wonder if the something like the 
> following would work instead:
> 
> oldopt = fancyopts._defaultopt(olddefault)
> newdefault = old.opt.newstate(olddefault, ui.config("commands", cfgitem)
> c[idx] = (opt[0], opt[1], fancyopts._withnewdefault(oldopt, newdefault), 
> opt[3])
> 
> Where '_withnewdefault' is a wrapper customopt that just changes the default.

I thought callables were meant to be used to generate the default default, not 
with overridden values?

> dploch wrote in dispatch.py:639-640
> This makes me nervous.  What if someone re-uses a customopt instance in 
> multiple commands?  i.e.:
> 
> DATE_FLAG = mypkg.dateopt()
> ...
> ('b', 'before', DATE_FLAG, '')
> ('a', 'after', 'DATE_FLAG', '')
> 
> Now, setting commands.defaults.before=2018-03-05 also silently changes the 
> default for 'after'.  I suspect we need to introduce a wrapper class like 
> what I suggest on lines 625-625, that delegates and leaves the original 
> default unchanged.  And either way, we should probably clarify in the docs on 
> customopts what expected use of the class is (i.e., should we just forbid 
> reuse, is 'oldstate' safe to mutate, etc.)

Nobody should use the same *instance* on multiple flags. Even with the current 
flags, if you use e.g. the same list on many, that'll cause problems with 
listopt.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

To: rdamazio, #hg-reviewers, yuja
Cc: dploch, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-04 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio added inline comments.

INLINE COMMENTS

> yuja wrote in dispatch.py:624
> IIUC, an extension author may implement its own customopt subclasses, and
> put them into the command table, so we can't make ui.configtyped to
> support all of them.

Ah, makes sense. See if this addresses that case satisfactorily - it still has 
the caveat of not being able to "reset" container types, but that's true of the 
command line as well (if you have a list flag with a non-empty default, there's 
no way to remove that default item).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

To: rdamazio, #hg-reviewers, yuja
Cc: dploch, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-04 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio updated this revision to Diff 6609.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2623?vs=6548=6609

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 < [defaults]
   > cat = -r null
   > EOF
   $ hg cat a
   a: no such file in rev 
   [1]
+  $ cp -f hgrc.bak $HGRCPATH
+
+new-style [commands] defaults and overrides
+
+  $ hg cat a
+  a
+  $ cat >> $HGRCPATH < [commands]
+  > cat.default.rev = null
+  > EOF
+  $ hg cat a
+  a: no such file in rev 
+  [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 < [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
@@ -545,7 +545,8 @@
 
 return main, sub
 
-def configtyped(self, section, name, itemtype, default=_unset, 
untrusted=False):
+def configtyped(self, section, name, itemtype, default=_unset,
+untrusted=False):
 """Get a config item as the given type."""
 if itemtype is type(False) or itemtype is type(None):
 return self.configbool(section, name, default, untrusted)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -611,6 +611,37 @@
 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 isinstance(olddefault, fancyopts.customopt):
+def badvalue(s):
+raise error.Abort(
+_('invalid value %r for config option %s: %s') % (
+newdefault, cfgitem, s))
+
+# If it's a custom option, then configtyped must have parsed it
+# as string - ask the customopt to parse its new default.
+# Notice this does have limitations - since we have no way to
+# start with a "clean" old state, this is not overriding the
+# default, but rather adding to it - e.g. a non-empty list
+# default will be appended to.
+olddefault.defaultvalue = olddefault.newstate(
+olddefault.defaultvalue, newdefault, badvalue)
+elif olddefault != newdefault:
+# override the default in the flag declaration.
+c[idx] = (opt[0], opt[1], newdefault, opt[3])
+
 else:
 cmd = None
 

D2623: dispatch: adding config items for overriding flag defaults

2018-03-04 Thread yuja (Yuya Nishihara)
yuja added inline comments.

INLINE COMMENTS

> rdamazio wrote in dispatch.py:624
> The issue is that customopt (and all its children) assume the value type is 
> already the correct one, and thus do not perform any conversion. Since we're 
> parsing values from the config file, the conversion is desired to ensure they 
> don't all end up as text - the config{bool,int,etc} methods called by 
> configtyped perform the proper conversion. In most cases (all commands that 
> declare default values) no conversio is needed since those already have the 
> correct type.

IIUC, an extension author may implement its own customopt subclasses, and
put them into the command table, so we can't make ui.configtyped to
support all of them.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

To: rdamazio, #hg-reviewers, yuja
Cc: dploch, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-04 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio updated this revision to Diff 6548.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2623?vs=6523=6548

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

AFFECTED FILES
  mercurial/configitems.py
  mercurial/dispatch.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 < [defaults]
   > cat = -r null
   > EOF
   $ hg cat a
   a: no such file in rev 
   [1]
+  $ cp -f hgrc.bak $HGRCPATH
+
+new-style [commands] defaults and overrides
+
+  $ hg cat a
+  a
+  $ cat >> $HGRCPATH < [commands]
+  > cat.default.rev = null
+  > EOF
+  $ hg cat a
+  a: no such file in rev 
+  [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 < [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/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, yuja
Cc: dploch, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-04 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio added inline comments.

INLINE COMMENTS

> yuja wrote in dispatch.py:624
> Maybe this type conversion can be a `fancyopt.customopt` method since we've
> refactored the default handling by https://phab.mercurial-scm.org/D2090?
> 
>   # no idea if _defaultopt() should be made public or the whole 
> commands.default handling
>   # should be moved to fancyopts
>   x = fancyopts._defaultopt(olddefault)
>   newdefault = x.configdefault(ui, cmd, optname, ...)
> 
> @dploch, any suggestions?

The issue is that customopt (and all its children) assume the value type is 
already the correct one, and thus do not perform any conversion. Since we're 
parsing values from the config file, the conversion is desired to ensure they 
don't all end up as text - the config{bool,int,etc} methods called by 
configtyped perform the proper conversion. In most cases (all commands that 
declare default values) no conversio is needed since those already have the 
correct type.

> yuja wrote in ui.py:390
> Perhaps this is noop since `[commands]` is removed at all if `ui.plain()` 
> returns True.

You're right, I had the plain logic inverted in my head. Removed.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

To: rdamazio, #hg-reviewers, yuja
Cc: dploch, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-04 Thread yuja (Yuya Nishihara)
yuja requested changes to this revision.
yuja added a subscriber: dploch.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> dispatch.py:624
> +# parse the new default as the same type as the original.
> +newdefault = ui.configtyped("commands", cfgitem, defaulttype, 
> olddefault)
> +if olddefault != newdefault:

Maybe this type conversion can be a `fancyopt.customopt` method since we've
refactored the default handling by https://phab.mercurial-scm.org/D2090?

  # no idea if _defaultopt() should be made public or the whole 
commands.default handling
  # should be moved to fancyopts
  x = fancyopts._defaultopt(olddefault)
  newdefault = x.configdefault(ui, cmd, optname, ...)

@dploch, any suggestions?

> ui.py:390
> +if '.default.' in k:
> +del cfg['commands'][k]
>  if self.plain('revsetalias'):

Perhaps this is noop since `[commands]` is removed at all if `ui.plain()` 
returns True.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

To: rdamazio, #hg-reviewers, yuja
Cc: dploch, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-03 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio added a comment.


  FYI this is a change I had previously sent to the list as 
60b3222e01f96f91ece7eda9681a89bf3bb930a6, and Yuya reviewed . I just had never 
followed up on it.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2623

To: rdamazio, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2623: dispatch: adding config items for overriding flag defaults

2018-03-03 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio updated this revision to Diff 6523.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2623?vs=6521=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 < [defaults]
   > cat = -r null
   > EOF
   $ hg cat a
   a: no such file in rev 
   [1]
+  $ cp -f hgrc.bak $HGRCPATH
+
+new-style [commands] defaults and overrides
+
+  $ hg cat a
+  a
+  $ cat >> $HGRCPATH < [commands]
+  > cat.default.rev = null
+  > EOF
+  $ hg cat a
+  a: no such file in rev 
+  [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 < [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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org

D2623: dispatch: adding config items for overriding flag defaults

2018-03-03 Thread rdamazio (Rodrigo Damazio Bovendorp)
rdamazio created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This introduces the new defaults format "commandname.default.optionname" which
  directly overrides the default of the option, instead of prepending the
  command-line option. This is meant to replace the [defaults] section which is
  already deprecated in a manner that's easier and safer to use than creating
  aliases.

REPOSITORY
  rHG Mercurial

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 < [defaults]
   > cat = -r null
   > EOF
   $ hg cat a
   a: no such file in rev 
   [1]
+  $ cp -f hgrc.bak $HGRCPATH
+
+new-style [commands] defaults and overrides
+
+  $ hg cat a
+  a
+  $ cat >> $HGRCPATH < [commands]
+  > cat.default.rev = null
+  > EOF
+  $ hg cat a
+  a: no such file in rev 
+  [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 < [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,
 )