[PATCH STABLE V2] zeroconf: use port from server instead of picking port from config (issue3746)
Augie Fackler
raf at durin42.com
Tue Jan 1 17:40:51 CST 2013
queued, thanks. Looks a lot cleaner than the old version.
On Dec 30, 2012, at 5:00 PM, Benoit Boissinot <benoit.boissinot at ens-lyon.org> wrote:
> # HG changeset patch
> # User Benoit Boissinot <benoit.boissinot at ens-lyon.org>
> # Date 1356891592 -3600
> # Branch stable
> # Node ID a10eb1fae5dd7bcafb08c803cd6e7465775e5781
> # Parent 52581d2b98ac5355c3b2ea304595f8cfee4cce59
> zeroconf: use port from server instead of picking port from config (issue3746)
>
> In order to get the port, wrap create server instead of
> hgweb_mod/hgwebdir_mod.
>
> diff --git a/hgext/zeroconf/__init__.py b/hgext/zeroconf/__init__.py
> --- a/hgext/zeroconf/__init__.py
> +++ b/hgext/zeroconf/__init__.py
> @@ -27,10 +27,9 @@
> import socket, time, os
>
> import Zeroconf
> -from mercurial import ui, hg, encoding, util, dispatch
> +from mercurial import ui, hg, encoding, dispatch
> from mercurial import extensions
> -from mercurial.hgweb import hgweb_mod
> -from mercurial.hgweb import hgwebdir_mod
> +from mercurial.hgweb import server as servermod
>
> testedwith = 'internal'
>
> @@ -102,27 +101,29 @@
> address = localip, weight = 0, priority = 0)
> server.registerService(svc)
>
> -class hgwebzc(hgweb_mod.hgweb):
> - def __init__(self, repo, name=None, baseui=None):
> - super(hgwebzc, self).__init__(repo, name=name, baseui=baseui)
> - name = self.reponame or os.path.basename(self.repo.root)
> - path = self.repo.ui.config("web", "prefix", "").strip('/')
> - desc = self.repo.ui.config("web", "description", name)
> - publish(name, desc, path,
> - util.getport(self.repo.ui.config("web", "port", 8000)))
> +def zc_create_server(create_server, ui, app):
> + httpd = create_server(ui, app)
> + port = httpd.port
>
> -class hgwebdirzc(hgwebdir_mod.hgwebdir):
> - def __init__(self, conf, baseui=None):
> - super(hgwebdirzc, self).__init__(conf, baseui=baseui)
> - prefix = self.ui.config("web", "prefix", "").strip('/') + '/'
> - for repo, path in self.repos:
> - u = self.ui.copy()
> + try:
> + repos = app.repos
> + except AttributeError:
> + # single repo
> + name = app.reponame or os.path.basename(app.repo.root)
> + path = app.repo.ui.config("web", "prefix", "").strip('/')
> + desc = app.repo.ui.config("web", "description", name)
> + publish(name, desc, path, port)
> + else:
> + # webdir
> + prefix = app.ui.config("web", "prefix", "").strip('/') + '/'
> + for repo, path in repos:
> + u = app.ui.copy()
> u.readconfig(os.path.join(path, '.hg', 'hgrc'))
> name = os.path.basename(repo)
> path = (prefix + repo).strip('/')
> desc = u.config('web', 'description', name)
> - publish(name, desc, path,
> - util.getport(u.config("web", "port", 8000)))
> + publish(name, desc, path, port)
> + return httpd
>
> # listen
>
> @@ -184,5 +185,4 @@
> extensions.wrapfunction(ui.ui, 'config', config)
> extensions.wrapfunction(ui.ui, 'configitems', configitems)
> extensions.wrapfunction(hg, 'defaultdest', defaultdest)
> -hgweb_mod.hgweb = hgwebzc
> -hgwebdir_mod.hgwebdir = hgwebdirzc
> +extensions.wrapfunction(servermod, 'create_server', zc_create_server)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list