Patchwork [2,of,2] zeroconf: fix crash in "hg paths" when zeroconf server is up

login
register
mail settings
Submitter Danek Duvall
Date Feb. 25, 2016, 6:11 p.m.
Message ID <67d9ae798d19f92155bd.1456423881@smelly.us.oracle.com>
Download mbox | patch
Permalink /patch/13397/
State Accepted
Headers show

Comments

Danek Duvall - Feb. 25, 2016, 6:11 p.m.
# HG changeset patch
# User Danek Duvall <danek.duvall@oracle.com>
# Date 1456423319 28800
#      Thu Feb 25 10:01:59 2016 -0800
# Node ID 67d9ae798d19f92155bd58a9dfe5d9081e5203f5
# Parent  e996712094de22f8cc783b630baebed49d50fe57
zeroconf: fix crash in "hg paths" when zeroconf server is up

Running "hg paths" with zeroconf enabled and when a zeroconf server is up
and running gives a traceback with "ValueError: rawloc must be defined".
This is because zeroconf needs to wrap ui.configsuboptions(), introduced in
dccbebcff075.
Augie Fackler - Feb. 25, 2016, 8:12 p.m.
On Thu, Feb 25, 2016 at 10:11:21AM -0800, danek.duvall@oracle.com wrote:
> # HG changeset patch
> # User Danek Duvall <danek.duvall@oracle.com>
> # Date 1456423319 28800
> #      Thu Feb 25 10:01:59 2016 -0800
> # Node ID 67d9ae798d19f92155bd58a9dfe5d9081e5203f5
> # Parent  e996712094de22f8cc783b630baebed49d50fe57
> zeroconf: fix crash in "hg paths" when zeroconf server is up

Queued these, thanks!

>
> Running "hg paths" with zeroconf enabled and when a zeroconf server is up
> and running gives a traceback with "ValueError: rawloc must be defined".
> This is because zeroconf needs to wrap ui.configsuboptions(), introduced in
> dccbebcff075.
>
> diff --git a/hgext/zeroconf/__init__.py b/hgext/zeroconf/__init__.py
> --- a/hgext/zeroconf/__init__.py
> +++ b/hgext/zeroconf/__init__.py
> @@ -169,6 +169,16 @@ def configitems(orig, self, section, *ar
>          repos += getzcpaths()
>      return repos
>
> +def configsuboptions(orig, self, section, name, *args, **kwargs):
> +    opt, sub = orig(self, section, name, *args, **kwargs)
> +    if section == "paths" and name.startswith("zc-"):
> +        # We have to find the URL in the zeroconf paths.  We can't cons up any
> +        # suboptions, so we use any that we found in the original config.
> +        for zcname, zcurl in getzcpaths():
> +            if zcname == name:
> +                return zcurl, sub
> +    return opt, sub
> +
>  def defaultdest(orig, source):
>      for name, path in getzcpaths():
>          if path == source:
> @@ -189,5 +199,6 @@ extensions.wrapfunction(dispatch, '_runc
>
>  extensions.wrapfunction(ui.ui, 'config', config)
>  extensions.wrapfunction(ui.ui, 'configitems', configitems)
> +extensions.wrapfunction(ui.ui, 'configsuboptions', configsuboptions)
>  extensions.wrapfunction(hg, 'defaultdest', defaultdest)
>  extensions.wrapfunction(servermod, 'create_server', zc_create_server)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/zeroconf/__init__.py b/hgext/zeroconf/__init__.py
--- a/hgext/zeroconf/__init__.py
+++ b/hgext/zeroconf/__init__.py
@@ -169,6 +169,16 @@  def configitems(orig, self, section, *ar
         repos += getzcpaths()
     return repos
 
+def configsuboptions(orig, self, section, name, *args, **kwargs):
+    opt, sub = orig(self, section, name, *args, **kwargs)
+    if section == "paths" and name.startswith("zc-"):
+        # We have to find the URL in the zeroconf paths.  We can't cons up any
+        # suboptions, so we use any that we found in the original config.
+        for zcname, zcurl in getzcpaths():
+            if zcname == name:
+                return zcurl, sub
+    return opt, sub
+
 def defaultdest(orig, source):
     for name, path in getzcpaths():
         if path == source:
@@ -189,5 +199,6 @@  extensions.wrapfunction(dispatch, '_runc
 
 extensions.wrapfunction(ui.ui, 'config', config)
 extensions.wrapfunction(ui.ui, 'configitems', configitems)
+extensions.wrapfunction(ui.ui, 'configsuboptions', configsuboptions)
 extensions.wrapfunction(hg, 'defaultdest', defaultdest)
 extensions.wrapfunction(servermod, 'create_server', zc_create_server)