Patchwork [5,of,8,py3,v3] dispatch: enforce bytes when converting boolean flags to config items

login
register
mail settings
Submitter Augie Fackler
Date March 8, 2017, 11:22 p.m.
Message ID <9269a48bd35f1eaafdb0.1489015364@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/19035/
State Accepted
Headers show

Comments

Augie Fackler - March 8, 2017, 11:22 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1488570207 18000
#      Fri Mar 03 14:43:27 2017 -0500
# Node ID 9269a48bd35f1eaafdb00c58c6056382c6a0ba88
# Parent  aa38d91cc90fe6b4c600f0f096fe45755b383193
dispatch: enforce bytes when converting boolean flags to config items

This fixes --verbose on Python 3.
Martijn Pieters - March 11, 2017, 7:07 p.m.
On 8 March 2017 at 15:22, Augie Fackler <raf@durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1488570207 18000
> #      Fri Mar 03 14:43:27 2017 -0500
> # Node ID 9269a48bd35f1eaafdb00c58c6056382c6a0ba88
> # Parent  aa38d91cc90fe6b4c600f0f096fe45755b383193
> dispatch: enforce bytes when converting boolean flags to config items
>
> This fixes --verbose on Python 3.
>
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -745,6 +745,8 @@ def _dispatch(req):
>          if options['verbose'] or options['debug'] or options['quiet']:
>              for opt in ('verbose', 'debug', 'quiet'):
>                  val = str(bool(options[opt]))
> +                if pycompat.ispy3:
> +                    val = val.encode('latin1')
>

Why latin1? I'd use ASCII here, as that's plenty to encode `'True'` and
`'False'`, the two possible string values here.


>                  for ui_ in uis:
>                      ui_.setconfig('ui', opt, val, '--' + opt)
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Augie Fackler - March 11, 2017, 7:23 p.m.
> On Mar 11, 2017, at 11:07, Martijn Pieters <mj@zopatista.com> wrote:
> 
> On 8 March 2017 at 15:22, Augie Fackler <raf@durin42.com <mailto:raf@durin42.com>> wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com <mailto:raf@durin42.com>>
> # Date 1488570207 18000
> #      Fri Mar 03 14:43:27 2017 -0500
> # Node ID 9269a48bd35f1eaafdb00c58c6056382c6a0ba88
> # Parent  aa38d91cc90fe6b4c600f0f096fe45755b383193
> dispatch: enforce bytes when converting boolean flags to config items
> 
> This fixes --verbose on Python 3.
> 
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -745,6 +745,8 @@ def _dispatch(req):
>          if options['verbose'] or options['debug'] or options['quiet']:
>              for opt in ('verbose', 'debug', 'quiet'):
>                  val = str(bool(options[opt]))
> +                if pycompat.ispy3:
> +                    val = val.encode('latin1')
> 
> Why latin1? I'd use ASCII here, as that's plenty to encode `'True'` and `'False'`, the two possible string values here.

Bad reflexes. I'll fix that for a resend.

>  
>                  for ui_ in uis:
>                      ui_.setconfig('ui', opt, val, '--' + opt)
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org <mailto:Mercurial-devel@mercurial-scm.org>
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel <https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel>
> 
> 
> 
> -- 
> Martijn Pieters

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -745,6 +745,8 @@  def _dispatch(req):
         if options['verbose'] or options['debug'] or options['quiet']:
             for opt in ('verbose', 'debug', 'quiet'):
                 val = str(bool(options[opt]))
+                if pycompat.ispy3:
+                    val = val.encode('latin1')
                 for ui_ in uis:
                     ui_.setconfig('ui', opt, val, '--' + opt)