tests/dummyssh
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 09 Apr 2024 22:36:35 +0200
changeset 51594 e3a5ec2d236a
parent 48875 6000f5b25c9b
permissions -rwxr-xr-x
outgoing: rework the handling of the `missingroots` case to be faster The previous implementation was slow, to the point it was taking a significant amount of `hg bundle --type none-streamv2` call. We rework the code to compute the same value much faster, making the operation disappear from the `hg bundle --type none-streamv2` profile. Someone would remark that producing a streamclone does not requires an `outgoing` object. However that is a matter for another day. There is other user of `missingroots` (non stream `hg bundle` call for example), and they will also benefit from this rework. We implement an old TODO in the process, directly computing the missing and common attribute as we have most element at hand already. ### benchmark.name = hg.command.bundle # bin-env-vars.hg.flavor = default # bin-env-vars.hg.py-re2-module = default # benchmark.variants.revs = all # benchmark.variants.type = none-streamv2 ## data-env-vars.name = heptapod-public-2024-03-25-zstd-sparse-revlog before: 7.750458 after: 6.665565 (-14.00%, -1.08) ## data-env-vars.name = mercurial-public-2024-03-22-zstd-sparse-revlog before: 0.700229 after: 0.496050 (-29.16%, -0.20) ## data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog before: 346.508952 after: 316.749699 (-8.59%, -29.76) ## data-env-vars.name = pypy-2024-03-22-zstd-sparse-revlog before: 3.401700 after: 2.915810 (-14.28%, -0.49) ## data-env-vars.name = tryton-public-2024-03-22-zstd-sparse-revlog before: 1.870798 after: 1.461583 (-21.87%, -0.41) note: this whole `missingroots` of outgoing has a limited number of callers and could likely be replace by something simpler (like taking an explicit "missing_revs" set for example). However this is a wider change and we focus on a small impact, quick rework that does not change the API for now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45830
c102b704edb5 global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36121
diff changeset
     1
#!/usr/bin/env python3
14186
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     2
29159
26d4ce8ca2bd py3: make tests/dummyssh use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 19320
diff changeset
     3
26d4ce8ca2bd py3: make tests/dummyssh use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 19320
diff changeset
     4
import os
47641
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
     5
import shlex
47640
119673fb37aa dummyssh: use subprocess instead of os.call
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45830
diff changeset
     6
import subprocess
14186
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     7
import sys
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     8
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
     9
os.chdir(os.getenv('TESTTMP'))
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    10
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    11
if sys.argv[1] != "user@dummy":
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    12
    sys.exit(-1)
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    13
31007
bfdb0741f9f2 dummyssh: use LOCALIP
Jun Wu <quark@fb.com>
parents: 29159
diff changeset
    14
os.environ["SSH_CLIENT"] = "%s 1 2" % os.environ.get('LOCALIP', '127.0.0.1')
14186
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    15
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    16
log = open("dummylog", "ab")
35570
3e3f4c03876b tests: add b'' to string literals where bytes are required
Pulkit Goyal <7895pulkit@gmail.com>
parents: 31007
diff changeset
    17
log.write(b"Got arguments")
14186
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    18
for i, arg in enumerate(sys.argv[1:]):
36121
3a763d7f40e1 py3: make dummyssh compatible with Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35570
diff changeset
    19
    log.write(b" %d:%s" % (i + 1, arg.encode('latin1')))
3a763d7f40e1 py3: make dummyssh compatible with Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35570
diff changeset
    20
log.write(b"\n")
14186
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    21
log.close()
15768
cdf9c43445df tests: make simple single quotes work with dummyssh on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 14186
diff changeset
    22
hgcmd = sys.argv[2]
cdf9c43445df tests: make simple single quotes work with dummyssh on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 14186
diff changeset
    23
if os.name == 'nt':
cdf9c43445df tests: make simple single quotes work with dummyssh on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 14186
diff changeset
    24
    # hack to make simple unix single quote quoting work on windows
cdf9c43445df tests: make simple single quotes work with dummyssh on windows
Mads Kiilerich <mads@kiilerich.com>
parents: 14186
diff changeset
    25
    hgcmd = hgcmd.replace("'", '"')
47641
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
    26
    cmds = shlex.split(hgcmd)
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
    27
    if cmds[0].endswith('.py'):
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
    28
        python_exe = os.environ['PYTHON']
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
    29
        cmds.insert(0, python_exe)
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
    30
    hgcmd = shlex.join(cmds)
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
    31
    # shlex generate windows incompatible string...
5d9f89cd4984 dummyssh: call python script with python
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47640
diff changeset
    32
    hgcmd = hgcmd.replace("'", '"')
47774
fb8389f227a0 dummyssh: make sure we don't inherit files descriptor to the children
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47641
diff changeset
    33
r = subprocess.call(hgcmd, shell=True, close_fds=True)
14186
8513bd2e7259 tests: share dummyssh
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
    34
sys.exit(bool(r))