contrib/dirstatenonnormalcheck.py
author Matt Harbison <matt_harbison@yahoo.com>
Mon, 20 Sep 2021 11:03:46 -0400
changeset 48035 406a7e629946
parent 47971 fea24454f919
permissions -rw-r--r--
archival: force a `CompressionError` to bytes before passing to `error.Abort` I'm not sure what changed before pytype 09-09-2021 (from 04-15-2021), but this started getting flagged. This fixes: File "/mnt/c/Users/Matt/hg/mercurial/archival.py", line 199, in taropen: Function bytestr.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, ints: Iterable[int]) Actually passed: (self, ints: tarfile.CompressionError) Attributes of protocol Iterable[int] are not implemented on tarfile.CompressionError: __iter__ Differential Revision: https://phab.mercurial-scm.org/D11472
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     1
# dirstatenonnormalcheck.py - extension to check the consistency of the
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     2
# dirstate's non-normal map
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     3
#
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     4
# For most operations on dirstate, this extensions checks that the nonnormalset
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     5
# contains the right entries.
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     6
# It compares the nonnormal file to a nonnormalset built from the map of all
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     7
# the files in the dirstate to check that they contain the same files.
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     8
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     9
from __future__ import absolute_import
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    10
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    11
from mercurial import (
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    12
    dirstate,
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    13
    extensions,
47547
20b37ef33ebc dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47546
diff changeset
    14
    pycompat,
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    15
)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    16
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    17
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    18
def nonnormalentries(dmap):
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    19
    """Compute nonnormal entries from dirstate's dmap"""
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    20
    res = set()
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    21
    for f, e in dmap.iteritems():
47546
35295f5a5b9f dirstate-item: use the properties in `contrib/dirstatenonnormalcheck.py`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43076
diff changeset
    22
        if e.state != b'n' or e.mtime == -1:
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    23
            res.add(f)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    24
    return res
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    25
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    26
47971
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    27
INCONSISTENCY_MESSAGE = b"""%s call to %s
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    28
  inconsistency in nonnormalset
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    29
  result from dirstatemap: %s
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    30
  expected nonnormalset:   %s
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    31
"""
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    32
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    33
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    34
def checkconsistency(ui, orig, dmap, _nonnormalset, label):
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    35
    """Compute nonnormalset from dmap, check that it matches _nonnormalset"""
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    36
    nonnormalcomputedmap = nonnormalentries(dmap)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    37
    if _nonnormalset != nonnormalcomputedmap:
47547
20b37ef33ebc dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47546
diff changeset
    38
        b_orig = pycompat.sysbytes(repr(orig))
20b37ef33ebc dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47546
diff changeset
    39
        b_nonnormal = pycompat.sysbytes(repr(_nonnormalset))
20b37ef33ebc dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47546
diff changeset
    40
        b_nonnormalcomputed = pycompat.sysbytes(repr(nonnormalcomputedmap))
47971
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    41
        msg = INCONSISTENCY_MESSAGE % (
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    42
            label,
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    43
            b_orig,
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    44
            b_nonnormal,
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    45
            b_nonnormalcomputed,
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    46
        )
fea24454f919 dirstate: clarify the message in nonnormal checking
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47946
diff changeset
    47
        ui.develwarn(msg, config=b'dirstate')
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    48
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    49
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47547
diff changeset
    50
def _checkdirstate(orig, self, *args, **kwargs):
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    51
    """Check nonnormal set consistency before and after the call to orig"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    52
    checkconsistency(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    53
        self._ui, orig, self._map, self._map.nonnormalset, b"before"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    54
    )
47674
ff97e793ed36 dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents: 47547
diff changeset
    55
    r = orig(self, *args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    56
    checkconsistency(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    57
        self._ui, orig, self._map, self._map.nonnormalset, b"after"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    58
    )
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    59
    return r
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    60
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 35918
diff changeset
    61
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    62
def extsetup(ui):
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    63
    """Wrap functions modifying dirstate to check nonnormalset consistency"""
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    64
    dirstatecl = dirstate.dirstate
35918
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 34674
diff changeset
    65
    devel = ui.configbool(b'devel', b'all-warnings')
6e7fae8f1c6c contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents: 34674
diff changeset
    66
    paranoid = ui.configbool(b'experimental', b'nonnormalparanoidcheck')
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    67
    if devel:
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    68
        extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    69
        if paranoid:
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    70
            # We don't do all these checks when paranoid is disable as it would
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    71
            # make the extension run very slowly on large repos
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    72
            extensions.wrapfunction(dirstatecl, 'write', _checkdirstate)
47939
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    73
            extensions.wrapfunction(dirstatecl, 'set_tracked', _checkdirstate)
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    74
            extensions.wrapfunction(dirstatecl, 'set_untracked', _checkdirstate)
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    75
            extensions.wrapfunction(
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    76
                dirstatecl, 'set_possibly_dirty', _checkdirstate
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    77
            )
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    78
            extensions.wrapfunction(
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    79
                dirstatecl, 'update_file_p1', _checkdirstate
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    80
            )
74a8d5c6fdc6 dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47674
diff changeset
    81
            extensions.wrapfunction(dirstatecl, 'update_file', _checkdirstate)