tests/generate-working-copy-states.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 09 Apr 2024 22:37:15 +0200
changeset 51595 3a6fae3bef35
parent 48875 6000f5b25c9b
permissions -rw-r--r--
outgoing: add a simple fastpath when there is no common This further speed up case like `hg bundle --all` for larger repository. ### data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog # 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 before: 316.749699 after: 311.165461 (-1.76%, -5.58) There is further work to be done in this area like not doing any outgoing computation in the stream case for example. however the recent changes already gives use a large win for a small amount of local work. ### 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 = mercurial-public-2024-03-22-zstd-sparse-revlog pre-%ln-change: 1.263859 the-%ln-change: 0.700229 (-44.60%, -0.56) prev-changeset: 0.496050 (-60.75%, -0.77) this-changeset: 0.495243 (-60.81%, -0.77) ## data-env-vars.name = tryton-public-2024-03-22-zstd-sparse-revlog pre-%ln-change: 2.975765 the-%ln-change: 1.870798 (-37.13%, -1.10) prev-changeset: 1.461583 (-50.88%, -1.51) this-changeset: 1.469185 (-50.63%, -1.51) ## data-env-vars.name = pypy-2024-03-22-zstd-sparse-revlog pre-%ln-change: 4.540080 the-%ln-change: 3.401700 (-25.07%, -1.14) prev-changeset: 2.915810 (-35.78%, -1.62) this-changeset: 2.911643 (-35.87%, -1.63) ## data-env-vars.name = heptapod-public-2024-03-25-zstd-sparse-revlog pre-%ln-change: 10.138396 the-%ln-change: 7.750458 (-23.55%, -2.39) prev-changeset: 6.665565 (-34.25%, -3.47) this-changeset: 6.672078 (-34.19%, -3.47) ## data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog pre-%ln-change: 399.484481 the-%ln-change: 346.508952 (-13.26%, -52.98) prev-changeset: 316.749699 (-20.71%, -82.73) this-changeset: 311.165461 (-22.11%, -88.32)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23447
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     1
# Helper script used for generating history and working copy files and content.
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     2
# The file's name corresponds to its history. The number of changesets can
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     3
# be specified on the command line. With 2 changesets, files with names like
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     4
# content1_content2_content1-untracked are generated. The first two filename
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     5
# segments describe the contents in the two changesets. The third segment
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     6
# ("content1-untracked") describes the state in the working copy, i.e.
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     7
# the file has content "content1" and is untracked (since it was previously
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     8
# tracked, it has been forgotten).
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
     9
#
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    10
# This script generates the filenames and their content, but it's up to the
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    11
# caller to tell hg about the state.
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    12
#
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    13
# There are two subcommands:
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    14
#   filelist <numchangesets>
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    15
#   state <numchangesets> (<changeset>|wc)
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    16
#
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    17
# Typical usage:
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    18
#
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    19
# $ python $TESTDIR/generate-working-copy-states.py state 2 1
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    20
# $ hg addremove --similarity 0
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    21
# $ hg commit -m 'first'
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    22
#
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    23
# $ python $TESTDIR/generate-working-copy-states.py state 2 1
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    24
# $ hg addremove --similarity 0
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    25
# $ hg commit -m 'second'
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    26
#
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    27
# $ python $TESTDIR/generate-working-copy-states.py state 2 wc
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    28
# $ hg addremove --similarity 0
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    29
# $ hg forget *_*_*-untracked
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    30
# $ rm *_*_missing-*
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    31
27295
a327a24acfea tests: use absolute_import in generate-working-copy-states.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23494
diff changeset
    32
a327a24acfea tests: use absolute_import in generate-working-copy-states.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23494
diff changeset
    33
import os
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    34
import sys
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    35
23446
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    36
# Generates pairs of (filename, contents), where 'contents' is a list
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    37
# describing the file's content at each revision (or in the working copy).
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    38
# At each revision, it is either None or the file's actual content. When not
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    39
# None, it may be either new content or the same content as an earlier
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    40
# revisions, so all of (modified,clean,added,removed) can be tested.
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    41
def generatestates(maxchangesets, parentcontents):
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    42
    depth = len(parentcontents)
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    43
    if depth == maxchangesets + 1:
36378
27ab9264dd61 py3: make sure we use bytes in generate-working-copy-states.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32291
diff changeset
    44
        for tracked in (b'untracked', b'tracked'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    45
            filename = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    46
                b"_".join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    47
                    [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    48
                        (content is None and b'missing' or content)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    49
                        for content in parentcontents
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    50
                    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    51
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    52
                + b"-"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    53
                + tracked
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    54
            )
23446
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    55
            yield (filename, parentcontents)
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    56
    else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    57
        for content in {None, b'content' + (b"%d" % (depth + 1))} | set(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    58
            parentcontents
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    59
        ):
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    60
            for combination in generatestates(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    61
                maxchangesets, parentcontents + [content]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    62
            ):
23446
e51027c85dcd generate-working-copy-states: generalize for depth
Martin von Zweigbergk <martinvonz@google.com>
parents: 23445
diff changeset
    63
                yield combination
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    64
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36786
diff changeset
    65
23447
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    66
# retrieve the command line arguments
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    67
target = sys.argv[1]
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    68
maxchangesets = int(sys.argv[2])
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    69
if target == 'state':
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    70
    depth = sys.argv[3]
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    71
23447
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    72
# sort to make sure we have stable output
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    73
combinations = sorted(generatestates(maxchangesets, []))
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    74
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    75
# compute file content
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    76
content = []
23447
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    77
for filename, states in combinations:
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    78
    if target == 'filelist':
36786
ed46d48453e8 py3: drop b'' from generate-working-copy-states.py output
Yuya Nishihara <yuya@tcha.org>
parents: 36378
diff changeset
    79
        print(filename.decode('ascii'))
23447
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    80
    elif target == 'state':
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    81
        if depth == 'wc':
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    82
            # Make sure there is content so the file gets written and can be
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    83
            # tracked. It will be deleted outside of this script.
36378
27ab9264dd61 py3: make sure we use bytes in generate-working-copy-states.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32291
diff changeset
    84
            content.append((filename, states[maxchangesets] or b'TOBEDELETED'))
23447
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    85
        else:
815e76a45b24 generate-working-copy-states: accept depth arguments on command line
Martin von Zweigbergk <martinvonz@google.com>
parents: 23446
diff changeset
    86
            content.append((filename, states[int(depth) - 1]))
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    87
    else:
28725
3cf1995dbdd5 py3: use print_function in generate-working-copy-states.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27295
diff changeset
    88
        print("unknown target:", target, file=sys.stderr)
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    89
        sys.exit(1)
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    90
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    91
# write actual content
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    92
for filename, data in content:
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    93
    if data is not None:
23494
3849b89459b0 generate-working-copy-states: open() in binary mode when writing content
Matt Harbison <matt_harbison@yahoo.com>
parents: 23447
diff changeset
    94
        f = open(filename, 'wb')
36378
27ab9264dd61 py3: make sure we use bytes in generate-working-copy-states.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32291
diff changeset
    95
        f.write(data + b'\n')
23195
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    96
        f.close()
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    97
    elif os.path.exists(filename):
29977b315be1 test-revert: move embedded script to its own file
Martin von Zweigbergk <martinvonz@google.com>
parents:
diff changeset
    98
        os.remove(filename)