Patchwork [STABLE] zeroconf: forward all arguments passed to ui.configitems() wrapper

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 10, 2016, 2:59 p.m.
Message ID <8d1f2c13cd6494bd061b.1455116345@mimosa>
Download mbox | patch
Permalink /patch/13098/
State Accepted
Delegated to: Martin von Zweigbergk
Headers show

Comments

Yuya Nishihara - Feb. 10, 2016, 2:59 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1455112397 -32400
#      Wed Feb 10 22:53:17 2016 +0900
# Branch stable
# Node ID 8d1f2c13cd6494bd061b6384e1b788b3c6f6bb03
# Parent  a586b649d1fcac9302f24c690fb9cb2aa4d75a30
zeroconf: forward all arguments passed to ui.configitems() wrapper

f43988e5954c added 'ignoresub' argument to ui.configitems(), but zeroconf
wrapper wasn't updated. It caused the following crash:

  Traceback (most recent call last):
    File "bin/hg", line 43, in <module>
      mercurial.dispatch.run()
    File "lib/python/mercurial/dispatch.py", line 54, in run
      sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
    File "lib/python/mercurial/dispatch.py", line 120, in dispatch
      ret = _runcatch(req)
    File "lib/python/mercurial/dispatch.py", line 191, in _runcatch
      return _dispatch(req)
    File "lib/python/mercurial/dispatch.py", line 924, in _dispatch
      cmdpats, cmdoptions)
    File "lib/python/mercurial/dispatch.py", line 681, in runcommand
      ret = _runcommand(ui, options, cmd, d)
    File "lib/python/mercurial/extensions.py", line 195, in closure
      return func(*(args + a), **kw)
    File "lib/python/hgext/zeroconf/__init__.py", line 180, in cleanupafterdispatch
      return orig(ui, options, cmd, cmdfunc)
    File "lib/python/mercurial/dispatch.py", line 1055, in _runcommand
      return checkargs()
    File "lib/python/mercurial/dispatch.py", line 1015, in checkargs
      return cmdfunc()
    File "lib/python/mercurial/dispatch.py", line 921, in <lambda>
      d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
    File "lib/python/mercurial/util.py", line 991, in check
      return func(*args, **kwargs)
    File "lib/python/mercurial/commands.py", line 5405, in paths
      pathitems = sorted(ui.paths.iteritems())
    File "lib/python/mercurial/util.py", line 723, in __get__
      result = self.func(obj)
    File "lib/python/mercurial/ui.py", line 619, in paths
      return paths(self)
    File "lib/python/mercurial/ui.py", line 1099, in __init__
      for name, loc in ui.configitems('paths', ignoresub=True):
    File "lib/python/mercurial/extensions.py", line 195, in closure
      return func(*(args + a), **kw)
  TypeError: configitems() got an unexpected keyword argument 'ignoresub'

We have no test coverage for zeroconf, so I've added a minimal test that
could reproduce this problem.
Sean Farley - Feb. 10, 2016, 6:43 p.m.
Yuya Nishihara <yuya@tcha.org> writes:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1455112397 -32400
> #      Wed Feb 10 22:53:17 2016 +0900
> # Branch stable
> # Node ID 8d1f2c13cd6494bd061b6384e1b788b3c6f6bb03
> # Parent  a586b649d1fcac9302f24c690fb9cb2aa4d75a30
> zeroconf: forward all arguments passed to ui.configitems() wrapper

Nice! Looks good to me.
Martin von Zweigbergk - Feb. 10, 2016, 9:08 p.m.
On Wed, Feb 10, 2016 at 10:43 AM, Sean Farley <sean@farley.io> wrote:
>
> Yuya Nishihara <yuya@tcha.org> writes:
>
>> # HG changeset patch
>> # User Yuya Nishihara <yuya@tcha.org>
>> # Date 1455112397 -32400
>> #      Wed Feb 10 22:53:17 2016 +0900
>> # Branch stable
>> # Node ID 8d1f2c13cd6494bd061b6384e1b788b3c6f6bb03
>> # Parent  a586b649d1fcac9302f24c690fb9cb2aa4d75a30
>> zeroconf: forward all arguments passed to ui.configitems() wrapper
>
> Nice! Looks good to me.

Queuing this for stable per Sean's review, thanks.

Patch

diff --git a/hgext/zeroconf/__init__.py b/hgext/zeroconf/__init__.py
--- a/hgext/zeroconf/__init__.py
+++ b/hgext/zeroconf/__init__.py
@@ -163,8 +163,8 @@  def config(orig, self, section, key, def
                 return path
     return orig(self, section, key, default, untrusted)
 
-def configitems(orig, self, section, untrusted=False):
-    repos = orig(self, section, untrusted)
+def configitems(orig, self, section, *args, **kwargs):
+    repos = orig(self, section, *args, **kwargs)
     if section == "paths":
         repos += getzcpaths()
     return repos
diff --git a/tests/test-paths.t b/tests/test-paths.t
--- a/tests/test-paths.t
+++ b/tests/test-paths.t
@@ -97,6 +97,14 @@  password should be masked in plain outpu
    }
   ]
 
+zeroconf wraps ui.configitems(), which shouldn't crash at least:
+
+  $ hg paths --config extensions.zeroconf=
+  dupe = $TESTTMP/b#tip (glob)
+  dupe:pushurl = https://example.com/dupe
+  expand = $TESTTMP/a/$SOMETHING/bar (glob)
+  insecure = http://foo:***@example.com/
+
   $ cd ..
 
 sub-options for an undeclared path are ignored