Mercurial > hg
annotate contrib/dirstatenonnormalcheck.py @ 47547:20b37ef33ebc
dirstatenonnormalcheck: fix some bytes formating on python3
Passing any object to `%s` no longer works, we need to explicitely convert the
representation to bytes.
Differential Revision: https://phab.mercurial-scm.org/D10993
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 05 Jul 2021 06:39:29 +0200 |
parents | 35295f5a5b9f |
children | ff97e793ed36 |
rev | line source |
---|---|
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 |
27591
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
40 def _checkdirstate(orig, self, arg): |
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 ) |
27637
b502138f5faa
cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents:
27591
diff
changeset
|
45 r = orig(self, arg) |
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, 'normal', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
65 extensions.wrapfunction(dirstatecl, 'write', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
66 extensions.wrapfunction(dirstatecl, 'add', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
67 extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
68 extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate) |
127cc7f78475
dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff
changeset
|
69 extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate) |