[PATCH 2 of 9] chgserver: add a top-level run method
Jun Wu
quark at fb.com
Sun Nov 13 16:55:46 EST 2016
# 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:]))
More information about the Mercurial-devel
mailing list