tests/seq.py
author Arun Kulshreshtha <akulshreshtha@janestreet.com>
Tue, 30 Aug 2022 15:29:55 -0400
changeset 49491 c6a1beba27e9
parent 49285 56f98406831b
permissions -rwxr-xr-x
bisect: avoid copying ancestor list for non-merge commits During a bisection, hg needs to compute a list of all ancestors for every candidate commit. This is accomplished via a bottom-up traversal of the set of candidates, during which each revision's ancestor list is populated using the ancestor list of its parent(s). Previously, this involved copying the entire list, which could be very long in if the bisection range was large. To help improve this, we can observe that each candidate commit is visited exactly once, at which point its ancestor list is copied into its children's lists and then dropped. In the case of non-merge commits, a commit's ancestor list consists exactly of its parent's list plus itself. This means that we can trivially reuse the parent's existing list for one of its non-merge children, which avoids copying entirely if that commit is the parent's only child. This makes bisections over linear ranges of commits much faster. During some informal testing in the large publicly-available `mozilla-central` repository, this noticeably sped up bisections over large ranges of history: Setup: $ cd mozilla-central $ hg bisect --reset $ hg bisect --good 0 $ hg log -r tip -T '{rev}\n' 628417 Test: $ time hg bisect --bad tip --noupdate Before: real 3m35.927s user 3m35.553s sys 0m0.319s After: real 1m41.142s user 1m40.810s sys 0m0.285s
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45830
c102b704edb5 global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43076
diff changeset
     1
#!/usr/bin/env python3
24360
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     2
#
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     3
# A portable replacement for 'seq'
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     4
#
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     5
# Usage:
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     6
#   seq STOP              [1, STOP] stepping by 1
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     7
#   seq START STOP        [START, STOP] stepping by 1
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     8
#   seq START STEP STOP   [START, STOP] stepping by STEP
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     9
40773
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    10
import os
24360
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    11
import sys
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    12
40773
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    13
try:
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    14
    import msvcrt
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40773
diff changeset
    15
40773
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    16
    msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    17
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    18
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    19
except ImportError:
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    20
    pass
0605726179a0 tests: apply binary mode to output in seq.py
Matt Harbison <matt_harbison@yahoo.com>
parents: 35150
diff changeset
    21
24360
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    22
start = 1
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    23
if len(sys.argv) > 2:
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    24
    start = int(sys.argv[1])
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    25
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    26
step = 1
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    27
if len(sys.argv) > 3:
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    28
    step = int(sys.argv[2])
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    29
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    30
stop = int(sys.argv[-1]) + 1
f554f89a2038 tests: introduce 'seq.py' as a portable replacement for 'seq'
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    31
49285
56f98406831b py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents: 48875
diff changeset
    32
for i in range(start, stop, step):
28722
2cd8c3b0bd11 py3: use print_function in seq.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28721
diff changeset
    33
    print(i)