tests/hghave
author Martin von Zweigbergk <martinvonz@google.com>
Mon, 06 Dec 2021 23:17:43 -0800
changeset 48507 58a3be48ddd2
parent 47500 23f5ed6dbcb1
child 48875 6000f5b25c9b
permissions -rwxr-xr-x
simplemerge: stop merging file flags As 384df4db6520 (merge: merge file flags together with file content, 2013-01-09) explains, we shouldn't do a 3-way merge of the symlink. However, since 84614212ae39 (flags: actually merge flags in simplemerge, 2020-05-16), we do that in `simplemerge.simplemerge()`. What's more, the merging of the executable flag there isn't actually necessary; it was made a no-op by the very next commit, i.e. 4234c9af515d (flags: read flag from dirstate/disk for workingcopyctx (issue5743), 2020-05-16). I found the overall flag-merging code (not the bit in `simplemerge.py`) very hard to follow, but I think I now finally understand how it works. `mergestate.resolve()` calculates the merged file flags and sets them on the local side of the merge (confusingly by calling `_restore_backup()`). Then it calls `filemerge.filemerge()`, which in turn calls `simplemerge.simplemerge()` (if premerge is enabled). That means that the flags on the local side `fcs.flags()` are already correct when the flag-merging code in `simplemerge.simplemerge()` runs. Interestingly, that code still works when the local side already has the merged value, it just doesn't change the value. Here's a truth table to explain why: ``` BLOMCAR 0000000 0011111 0101011 0111111 1000000 1010000 1100000 1111101 ``` B: Base L: Local O: Other M: Merged flags from `mergestate.resolve()`, i.e. what's called "local" when we get to `simplemerge.simplemerge()` C: `commonflags` in `simplemerge.simplemerge()`, i.e. `M & O` A: `addedflags` in `simplemerge.simplemerge()`, i.e. `(M ^ O) - B` R: Re-merged flags `simplemerge.simplemerge()`, i.e. `C | A` As you can see, the re-merged flags are always unchanged compared to the initial merged flags (R equals M). Therefore, this patch effectively backs out 84614212ae39. (I might later refactor this code to have the flags explicitly passed in.) `simplemerge.simplemerge()` is also called from `contrib/simplemerge.py`, but that code never passes any flags. Differential Revision: https://phab.mercurial-scm.org/D11879
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47500
23f5ed6dbcb1 run-tests: stop writing a `python3` symlink pointing to python2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 45830
diff changeset
     1
#!/usr/bin/env python
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     2
"""Test the running system for features availability. Exit with zero
5084
80309fa23cdb hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents: 5081
diff changeset
     3
if all features are there, non-zero otherwise. If a feature name is
80309fa23cdb hghave: feature absence can be checked by prefixing with 'no-'
Patrick Mezard <pmezard@gmail.com>
parents: 5081
diff changeset
     4
prefixed with "no-", the absence of feature is tested.
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     5
"""
28283
544444991c83 hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28047
diff changeset
     6
29161
f8b274df33dc py3: make tests/hghave use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29141
diff changeset
     7
from __future__ import absolute_import, print_function
28283
544444991c83 hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28047
diff changeset
     8
29161
f8b274df33dc py3: make tests/hghave use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29141
diff changeset
     9
import hghave
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    10
import optparse
29161
f8b274df33dc py3: make tests/hghave use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29141
diff changeset
    11
import os
f8b274df33dc py3: make tests/hghave use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 29141
diff changeset
    12
import sys
9446
57d682d7d2da test-gendoc: test documentation generation
Martin Geisler <mg@lazybytes.net>
parents: 9395
diff changeset
    13
16966
23f621ca04b5 tests/hghave: extract hghave.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 16891
diff changeset
    14
checks = hghave.checks
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    15
43691
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    16
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    17
def list_features():
29141
ba8999547f81 hghave: switch from iteritems to items
timeless <timeless@mozdev.org>
parents: 28283
diff changeset
    18
    for name, feature in sorted(checks.items()):
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    19
        desc = feature[1]
28283
544444991c83 hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28047
diff changeset
    20
        print(name + ':', desc)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    21
43691
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    22
8059
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    23
def test_features():
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    24
    failed = 0
29141
ba8999547f81 hghave: switch from iteritems to items
timeless <timeless@mozdev.org>
parents: 28283
diff changeset
    25
    for name, feature in checks.items():
8059
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    26
        check, _ = feature
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    27
        try:
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    28
            check()
28047
863075fd4cd0 misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26068
diff changeset
    29
        except Exception as e:
28283
544444991c83 hghave: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28047
diff changeset
    30
            print("feature %s failed:  %s" % (name, e))
8059
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    31
            failed += 1
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    32
    return failed
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    33
43691
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    34
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    35
parser = optparse.OptionParser("%prog [options] [features]")
43691
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    36
parser.add_option(
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    37
    "--test-features", action="store_true", help="test available features"
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    38
)
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    39
parser.add_option(
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    40
    "--list-features", action="store_true", help="list available features"
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    41
)
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    42
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    43
26068
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    44
def _loadaddon():
25732
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    45
    if 'TESTDIR' in os.environ:
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    46
        # loading from '.' isn't needed, because `hghave` should be
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    47
        # running at TESTTMP in this case
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    48
        path = os.environ['TESTDIR']
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    49
    else:
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    50
        path = '.'
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    51
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    52
    if not os.path.exists(os.path.join(path, 'hghaveaddon.py')):
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    53
        return
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    54
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    55
    sys.path.insert(0, path)
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    56
    try:
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    57
        import hghaveaddon
43691
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    58
29231
b1b35a9051c3 hghave: silence future pyflakes warning of unused import
Yuya Nishihara <yuya@tcha.org>
parents: 29161
diff changeset
    59
        assert hghaveaddon  # silence pyflakes
28047
863075fd4cd0 misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26068
diff changeset
    60
    except BaseException as inst:
43691
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    61
        sys.stderr.write(
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    62
            'failed to import hghaveaddon.py from %r: %s\n' % (path, inst)
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    63
        )
25732
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    64
        sys.exit(2)
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    65
    sys.path.pop(0)
b94df10cc3b5 hghave: allow adding customized features at runtime
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22762
diff changeset
    66
43691
47ef023d0165 black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 29231
diff changeset
    67
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    68
if __name__ == '__main__':
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    69
    options, args = parser.parse_args()
26068
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    70
    _loadaddon()
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    71
    if options.list_features:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    72
        list_features()
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    73
        sys.exit(0)
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5074
diff changeset
    74
8059
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    75
    if options.test_features:
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    76
        sys.exit(test_features())
41a2c5cbcb6a hghave: checking that all targets are Exception-free
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7823
diff changeset
    77
26068
05e7f57c74ac hghave: remove quiet option
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26067
diff changeset
    78
    hghave.require(args)