[PATCH] py3: manually replace `None` with 'None' in ui.log() arguments

Yuya Nishihara yuya at tcha.org
Fri Feb 8 05:54:33 EST 2019


On Thu, 07 Feb 2019 17:55:47 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at 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.


More information about the Mercurial-devel mailing list