[PATCH 1 of 8 v2] flags: allow specifying --no-boolean-flag on the command line (BC)

Yuya Nishihara yuya at tcha.org
Thu Sep 1 15:27:21 UTC 2016


On Tue, 30 Aug 2016 16:16:14 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1472586362 14400
> #      Tue Aug 30 15:46:02 2016 -0400
> # Node ID 4f76e8b136581d750cf98395ea8034dbb9666b96
> # Parent  12f8bef59bfa2739d0c5d8425ab494fd2fe38a81
> flags: allow specifying --no-boolean-flag on the command line (BC)
> 
> This makes it much easier to enable some anti-foot-shooting features
> (like update --check) by default, because now all boolean flags can be
> explicitly disabled on the command line without having to use HGPLAIN
> or similar.
> 
> This doesn't (yet) update help output, because I'm not quite sure how
> to do that cleanly.
> 
> diff --git a/mercurial/fancyopts.py b/mercurial/fancyopts.py
> --- a/mercurial/fancyopts.py
> +++ b/mercurial/fancyopts.py
> @@ -64,6 +64,7 @@ def fancyopts(args, options, state, gnu=
>      shortlist = ''
>      argmap = {}
>      defmap = {}
> +    notnegated = set()
>  
>      for option in options:
>          if len(option) == 5:
> @@ -87,10 +88,18 @@ def fancyopts(args, options, state, gnu=
>  
>          # does it take a parameter?
>          if not (default is None or default is True or default is False):
> +            if oname.startswith('no-'):
> +                notnegated.add(oname)
> +            # Note slight weirdness: this means flags like --no-backup
> +            # for revert can be negated with --no-no-backup. This
> +            # seems fine.
> +            namelist.append('no-' + oname)

--no-takesparam is allowed, which seems wrong and fixed by the patch 6.

> +Test that boolean flags allow --flag=false specification to override [defaults]

s/--flag=false/--no-flag/

> +  $ cat >> $HGRCPATH <<EOF
> +  > [defaults]
> +  > update = --check
> +  > EOF
> +  $ hg co 2
> +  abort: uncommitted changes
> +  [255]
> +  $ hg co --no-check 2


More information about the Mercurial-devel mailing list