author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Tue, 24 Aug 2021 21:08:09 +0200 | |
changeset 47909 | f89ac1ed2bc6 |
parent 47908 | 74a8d5c6fdc6 |
child 47910 | 50bed873a765 |
permissions | -rw-r--r-- |
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:
35878
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:
35878
diff
changeset
|
26 |
|
27591
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
27 |
def checkconsistency(ui, orig, dmap, _nonnormalset, label): |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
28 |
"""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
|
29 |
nonnormalcomputedmap = nonnormalentries(dmap) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
30 |
if _nonnormalset != nonnormalcomputedmap: |
47547
20b37ef33ebc
dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47546
diff
changeset
|
31 |
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
|
32 |
ui.develwarn(b"%s call to %s\n" % (label, b_orig), config=b'dirstate') |
35878
6e7fae8f1c6c
contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents:
34674
diff
changeset
|
33 |
ui.develwarn(b"inconsistency in nonnormalset\n", config=b'dirstate') |
47547
20b37ef33ebc
dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47546
diff
changeset
|
34 |
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
|
35 |
ui.develwarn(b"[nonnormalset] %s\n" % b_nonnormal, config=b'dirstate') |
20b37ef33ebc
dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47546
diff
changeset
|
36 |
b_nonnormalcomputed = pycompat.sysbytes(repr(nonnormalcomputedmap)) |
20b37ef33ebc
dirstatenonnormalcheck: fix some bytes formating on python3
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47546
diff
changeset
|
37 |
ui.develwarn(b"[map] %s\n" % b_nonnormalcomputed, config=b'dirstate') |
27591
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
38 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
39 |
|
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47547
diff
changeset
|
40 |
def _checkdirstate(orig, self, *args, **kwargs): |
27591
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
41 |
"""Check nonnormal set consistency before and after the call to orig""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
42 |
checkconsistency( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
43 |
self._ui, orig, self._map, self._map.nonnormalset, b"before" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
44 |
) |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47547
diff
changeset
|
45 |
r = orig(self, *args, **kwargs) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
46 |
checkconsistency( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
47 |
self._ui, orig, self._map, self._map.nonnormalset, b"after" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
48 |
) |
27591
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
49 |
return r |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
50 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
35878
diff
changeset
|
51 |
|
27591
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
52 |
def extsetup(ui): |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
53 |
"""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
|
54 |
dirstatecl = dirstate.dirstate |
35878
6e7fae8f1c6c
contrib: fix dirstatenonnormalcheck to work in Python 3
Augie Fackler <augie@google.com>
parents:
34674
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
if devel: |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
58 |
extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
59 |
if paranoid: |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
60 |
# 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
|
61 |
# 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
|
62 |
extensions.wrapfunction(dirstatecl, 'normallookup', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
63 |
extensions.wrapfunction(dirstatecl, 'otherparent', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
64 |
extensions.wrapfunction(dirstatecl, 'write', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
65 |
extensions.wrapfunction(dirstatecl, 'add', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
66 |
extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
67 |
extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
68 |
extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate) |
47908
74a8d5c6fdc6
dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47674
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
extensions.wrapfunction( |
74a8d5c6fdc6
dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47674
diff
changeset
|
72 |
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
|
73 |
) |
74a8d5c6fdc6
dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47674
diff
changeset
|
74 |
extensions.wrapfunction( |
74a8d5c6fdc6
dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47674
diff
changeset
|
75 |
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
|
76 |
) |
74a8d5c6fdc6
dirstate: also wrap the new method in `dirstatenonnormalcheck`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47674
diff
changeset
|
77 |
extensions.wrapfunction(dirstatecl, 'update_file', _checkdirstate) |