[PATCH 2 of 9] chgserver: add a top-level run method

Yuya Nishihara yuya at tcha.org
Sat Nov 19 04:09:18 EST 2016


On Sun, 13 Nov 2016 21:55:46 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1479070111 0
> #      Sun Nov 13 20:48:31 2016 +0000
> # Node ID ca7a76135db4a9b8a90665c8a42013debbdae3b7
> # Parent  c04847bc1bf1804cc7d8f5e74444c50a653a9526
> chgserver: add a top-level run method
> 
> Currently, chg server is implemented under the "hg serve" framework, which
> is actually too later: loading extensions, loading repo etc. are the things
> chg server wants to avoid.
> 
> This patch adds a "run" method, which would be the entry point of chg
> server, bypassing dispatch's code path.
> 
> diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
> --- a/mercurial/chgserver.py
> +++ b/mercurial/chgserver.py
> @@ -61,4 +61,5 @@ from . import (
>      extensions,
>      osutil,
> +    ui as uimod,
>      util,
>  )
> @@ -642,2 +643,22 @@ def uisetup(ui):
>      if 'CHGINTERNALMARK' in os.environ:
>          del os.environ['CHGINTERNALMARK']
> +
> +def _runchgservice(args):
> +    ui = uimod.ui()
> +
> +    addresses = dispatch._earlygetopt(['--address'], args)
> +    if not addresses:
> +        raise error.Abort(_('--address is required'))
> +
> +    opts = {
> +        'address': addresses[-1],
> +        'daemon': None,
> +        'daemon_postexec': ['chdir:/'],
> +        'pid_file': None,
> +    }
> +
> +    service = chgunixservice(ui, repo=None, opts=opts)
> +    return cmdutil.service(opts, initfn=service.init, runfn=service.run)
> +
> +def run():
> +    sys.exit(_runchgservice(sys.argv[1:]))

I'm in favor of going through dispatch.dispatch() with some special treatments
for chg, but you might be right in that it would be unnecessary complicated.
So I'll queue V2 even if it has a top-level run().

BTW, I have the patches to move chgserver.py to the core. If they help making
your series without the copy of chgserver.py, I'll send them out. But I guess
they wouldn't.

The series generally looks good to me.


More information about the Mercurial-devel mailing list