sapling/edenscm/mercurial/entrypoint.py
Jun Wu b74ee0564d chg: make it incompatible with upstream chg server
Summary:
It would be massy if there are 2 chg servers running: one for fb hg, one for
upstream hg, and they share a same socket path.

Change socket path and the commandserver name so fb-hg chg can only talk to
fb-hg chg servers.

Reviewed By: markbt

Differential Revision: D13869319

fbshipit-source-id: f9d42af9bdfc542207f23c536b478fd5ef8d02a0
2019-02-08 16:12:53 -08:00

85 lines
2.8 KiB
Python
Executable File

#!/usr/bin/env python
# mercurial - scalable distributed SCM
#
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import os
import sys
def run(binaryexecution):
# entrypoint is in mercurial/ dir, while we want 'from mercurial import ...',
# 'from hgext import ...' and 'from hgdemandimport import ...' to work
# so we are adding their parent directory to be the first item of sys.path
# Do not follow symlinks (ex. do not use "realpath"). It breaks buck build.
filedir = os.path.dirname(os.path.abspath(__file__))
libdir = os.path.dirname(os.path.dirname(filedir))
if sys.path[0] != libdir:
sys.path.insert(0, libdir)
for element in list(sys.path):
if os.path.realpath(filedir) == os.path.realpath(element):
# the directory of entrypoint.py is mercurial/
# and it should not be present in sys.path, as we use absolute_import
sys.path.remove(element)
from edenscm import hgdemandimport
hgdemandimport.tryenableembedded()
from edenscm.mercurial import encoding
if encoding.environ.get("HGUNICODEPEDANTRY", False):
try:
reload(sys)
sys.setdefaultencoding("undefined")
except NameError:
pass
# Make available various deps that are either not new enough on the system
# or not provided by the system. These include a newer version of IPython
# for `hg dbsh` and the thrift runtime for the eden extension
from edenscm.mercurial import thirdparty
ipypath = os.path.join(os.path.dirname(thirdparty.__file__), "IPython.zip")
if ipypath not in sys.path and os.path.exists(ipypath):
sys.path.insert(0, ipypath)
from edenscm.mercurial import executionmodel
executionmodel.setbinaryexecution(binaryexecution)
if (
sys.argv[1:5] == ["serve", "--cmdserver", "chgunix2", "--address"]
and sys.argv[6:8] == ["--daemon-postexec", "chdir:/"]
and "CHGINTERNALMARK" in encoding.environ
):
# Shortcut path for chg server
from edenscm.mercurial import dispatch
dispatch.runchgserver()
else:
# Non-chg path
try:
if sys.version_info[0] < 3 or sys.version_info >= (3, 6):
hgdemandimport.enable()
except ImportError:
sys.stderr.write(
"abort: couldn't find mercurial libraries in [%s]\n"
% " ".join(sys.path)
)
sys.stderr.write("(check your install and PYTHONPATH)\n")
sys.exit(-1)
from edenscm.mercurial import dispatch
dispatch.run()
if __name__ == "__main__":
run(True)