def perfstartup(ui, repo, **opts): timer, fm = gettimer(ui, opts) cmd = " ".join(util.hgcmd()) def d(): if os.name != "nt": os.system("HGRCPATH= %s version -q > /dev/null" % cmd) else: os.environ["HGRCPATH"] = " " os.system("%s version -q > NUL" % cmd) timer(d) fm.end()
def testsetup(t: TestTmp): _checkenvironment() hgrcpath = t.path / "hgrc" hgrcpath.write_bytes(INITIAL_HGRC) # extra hgrc fixup via $TESTDIR/features.py testfile = t.getenv("TESTFILE") testdir = t.getenv("TESTDIR") featurespy = os.path.join(testdir, "features.py") if os.path.exists(featurespy): with open(featurespy, "r") as f: globalenv = {} exec(f.read(), globalenv) setup = globalenv.get("setup") if setup: testname = os.path.basename(testfile) setup(testname, str(hgrcpath)) # the 'f' utility in $TESTDIR/f fpath = os.path.join(testdir, "f") if os.path.exists(fpath): fmain = None @t.command def f(args, stdout, stdin, fs, fpath=fpath) -> int: nonlocal fmain if fmain is None: fmain = _execpython(fpath)["main"] os.chdir(fs.cwd()) try: fmain(args, stdout=stdout, stdin=stdin) except SystemExit as e: return int(e.code) else: return 0 environ = { "CHGDISABLE": "0", "COLUMNS": "80", "DAEMON_PIDS": str(t.path / "daemon.pids"), "EMAIL": "Foo Bar <*****@*****.**>", "HGCOLORS": "16", "HGEDITOR": "internal:none", "HGEMITWARNINGS": "1", "HGENCODINGMODE": "strict", "HGENCODING": "utf-8", "HGMERGE": "internal:merge", "HGOUTPUTENCODING": "utf-8", "HGRCPATH": str(hgrcpath), "HGUSER": "******", "LANG": "en_US.UTF-8", "LANGUAGE": "en_US.UTF-8", "LC_ALL": "en_US.UTF-8", "LOCALIP": "127.0.0.1", "TZ": "GMT", } # prepare chg with open(testfile, "rb") as f: header = f.read(256) usechg = b"#chg-compatible" in header if usechg: environ["CHGDISABLE"] = "0" environ["CHGSOCKNAME"] = str(t.path / "chgserver") else: environ["CHGDISABLE"] = "1" for k, v in environ.items(): t.setenv(k, v) # source tinit.sh tinitpath = os.path.join(testdir, "tinit.sh") if os.path.exists(tinitpath): with open(tinitpath, "rb") as f: t.sheval(f.read().decode()) hgpath = None run = None try: import bindings from edenscm.mercurial import util run = bindings.commands.run except ImportError: hgpath = os.environ.get("HG") if hgpath and not os.path.exists(hgpath): hgpath = None else: hgpath = util.hgcmd()[0] # provide access to the real binary t.requireexe("hg", hgpath) # change the 'hg' shell command to run inline without spawning # (about 2x faster than chg) if run is not None: t.command(hg)