Patchwork py3: manually replace `None` with 'None' in ui.log() arguments

login
register
mail settings
Submitter Matt Harbison
Date Feb. 7, 2019, 10:55 p.m.
Message ID <b6bdc25edf05318a4571.1549580147@mharbison-pc.attotech.com>
Download mbox | patch
Permalink /patch/38537/
State New
Headers show

Comments

Matt Harbison - Feb. 7, 2019, 10:55 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1549312475 18000
#      Mon Feb 04 15:34:35 2019 -0500
# Node ID b6bdc25edf05318a4571b4f34a741754f5052567
# Parent  a263b7d71105414c9a1234414747533ce904ba39
py3: manually replace `None` with 'None' in ui.log() arguments

Pushing to a real server with py3 (while fixing the digest authentication
issues) spit out this:

  Traceback (most recent call last):
  ...
  File "c:\users\jenkins\mercurial\mercurial\commands.py", line 4635, in push
    opargs=opargs)
  File "c:\users\jenkins\mercurial\hgext\lfs\wrapper.py", line 340, in push
    return orig(repo, remote, *args, **kwargs)
  File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 566, in push
    _pushbundle2(pushop)
  File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 1138, in _pushbundle2
    ret = partgen(pushop, bundler)
  File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 909, in _pushb2ctx
    if not _pushcheckoutgoing(pushop):
  File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 804, in _pushcheckoutgoing
    discovery.checkheads(pushop)
  File "c:\users\jenkins\mercurial\mercurial\discovery.py", line 341, in checkheads
    headssum = _headssummary(pushop)
  File "c:\users\jenkins\mercurial\mercurial\discovery.py", line 244, in _headssummary
    newmap.update(repo, (ctx.rev() for ctx in missingctx))
  File "c:\users\jenkins\mercurial\mercurial\branchmap.py", line 344, in update
    repo.filtername, duration)
  File "c:\users\jenkins\mercurial\mercurial\ui.py", line 1813, in log
    msg = msgfmt % msgargs
TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'NoneType'

I don't think blackbox is at fault- we just need to have some loggers active.

Passing `repo.filtername or b''` at this branchmap call-site also fixed the
issue, but there are other places where `repo.filtername` is getting logged as
well.  This seems like the easiest fix.
Yuya Nishihara - Feb. 8, 2019, 10:54 a.m.
On Thu, 07 Feb 2019 17:55:47 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1549312475 18000
> #      Mon Feb 04 15:34:35 2019 -0500
> # Node ID b6bdc25edf05318a4571b4f34a741754f5052567
> # Parent  a263b7d71105414c9a1234414747533ce904ba39
> py3: manually replace `None` with 'None' in ui.log() arguments
> 
> Pushing to a real server with py3 (while fixing the digest authentication
> issues) spit out this:
> 
>   Traceback (most recent call last):
>   ...
>   File "c:\users\jenkins\mercurial\mercurial\commands.py", line 4635, in push
>     opargs=opargs)
>   File "c:\users\jenkins\mercurial\hgext\lfs\wrapper.py", line 340, in push
>     return orig(repo, remote, *args, **kwargs)
>   File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 566, in push
>     _pushbundle2(pushop)
>   File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 1138, in _pushbundle2
>     ret = partgen(pushop, bundler)
>   File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 909, in _pushb2ctx
>     if not _pushcheckoutgoing(pushop):
>   File "c:\users\jenkins\mercurial\mercurial\exchange.py", line 804, in _pushcheckoutgoing
>     discovery.checkheads(pushop)
>   File "c:\users\jenkins\mercurial\mercurial\discovery.py", line 341, in checkheads
>     headssum = _headssummary(pushop)
>   File "c:\users\jenkins\mercurial\mercurial\discovery.py", line 244, in _headssummary
>     newmap.update(repo, (ctx.rev() for ctx in missingctx))
>   File "c:\users\jenkins\mercurial\mercurial\branchmap.py", line 344, in update
>     repo.filtername, duration)
>   File "c:\users\jenkins\mercurial\mercurial\ui.py", line 1813, in log
>     msg = msgfmt % msgargs
> TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'NoneType'
> 
> I don't think blackbox is at fault- we just need to have some loggers active.
> 
> Passing `repo.filtername or b''` at this branchmap call-site also fixed the
> issue, but there are other places where `repo.filtername` is getting logged as
> well.  This seems like the easiest fix.
> 
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -1810,7 +1810,15 @@ class ui(object):
>                           if l.tracked(event)]
>          if not activeloggers:
>              return
> -        msg = msgfmt % msgargs
> +
> +        def _filternone(x):
> +            return x is None and b'None' or x
> +
> +        def _format(msgfmt, *msgargs):
> +            return msgfmt % msgargs
> +
> +        msg = _format(msgfmt, *[_filternone(a) for a in msgargs])

This is a bug of ui.log() caller. Maybe we should use '%r' instead.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1810,7 +1810,15 @@  class ui(object):
                          if l.tracked(event)]
         if not activeloggers:
             return
-        msg = msgfmt % msgargs
+
+        def _filternone(x):
+            return x is None and b'None' or x
+
+        def _format(msgfmt, *msgargs):
+            return msgfmt % msgargs
+
+        msg = _format(msgfmt, *[_filternone(a) for a in msgargs])
+
         opts = pycompat.byteskwargs(opts)
         # guard against recursion from e.g. ui.debug()
         registeredloggers = self._loggers
diff --git a/tests/test-push-http.t b/tests/test-push-http.t
--- a/tests/test-push-http.t
+++ b/tests/test-push-http.t
@@ -413,7 +413,7 @@  Pushing via hgwebdir works
   $ echo commit > a
   $ hg commit -m 'local commit'
 
-  $ hg push
+  $ hg push --config extensions.blackbox= --config 'blackbox.track=*'
   pushing to http://localhost:$HGPORT/hgwebdir
   searching for changes
   remote: adding changesets