##// END OF EJS Templates
dirstate: clarify the message in nonnormal checking...
marmoute -
r48755:fea24454 default
parent child Browse files
Show More
@@ -1,71 +1,81 b''
1 1 # dirstatenonnormalcheck.py - extension to check the consistency of the
2 2 # dirstate's non-normal map
3 3 #
4 4 # For most operations on dirstate, this extensions checks that the nonnormalset
5 5 # contains the right entries.
6 6 # It compares the nonnormal file to a nonnormalset built from the map of all
7 7 # the files in the dirstate to check that they contain the same files.
8 8
9 9 from __future__ import absolute_import
10 10
11 11 from mercurial import (
12 12 dirstate,
13 13 extensions,
14 14 pycompat,
15 15 )
16 16
17 17
18 18 def nonnormalentries(dmap):
19 19 """Compute nonnormal entries from dirstate's dmap"""
20 20 res = set()
21 21 for f, e in dmap.iteritems():
22 22 if e.state != b'n' or e.mtime == -1:
23 23 res.add(f)
24 24 return res
25 25
26 26
27 INCONSISTENCY_MESSAGE = b"""%s call to %s
28 inconsistency in nonnormalset
29 result from dirstatemap: %s
30 expected nonnormalset: %s
31 """
32
33
27 34 def checkconsistency(ui, orig, dmap, _nonnormalset, label):
28 35 """Compute nonnormalset from dmap, check that it matches _nonnormalset"""
29 36 nonnormalcomputedmap = nonnormalentries(dmap)
30 37 if _nonnormalset != nonnormalcomputedmap:
31 38 b_orig = pycompat.sysbytes(repr(orig))
32 ui.develwarn(b"%s call to %s\n" % (label, b_orig), config=b'dirstate')
33 ui.develwarn(b"inconsistency in nonnormalset\n", config=b'dirstate')
34 39 b_nonnormal = pycompat.sysbytes(repr(_nonnormalset))
35 ui.develwarn(b"[nonnormalset] %s\n" % b_nonnormal, config=b'dirstate')
36 40 b_nonnormalcomputed = pycompat.sysbytes(repr(nonnormalcomputedmap))
37 ui.develwarn(b"[map] %s\n" % b_nonnormalcomputed, config=b'dirstate')
41 msg = INCONSISTENCY_MESSAGE % (
42 label,
43 b_orig,
44 b_nonnormal,
45 b_nonnormalcomputed,
46 )
47 ui.develwarn(msg, config=b'dirstate')
38 48
39 49
40 50 def _checkdirstate(orig, self, *args, **kwargs):
41 51 """Check nonnormal set consistency before and after the call to orig"""
42 52 checkconsistency(
43 53 self._ui, orig, self._map, self._map.nonnormalset, b"before"
44 54 )
45 55 r = orig(self, *args, **kwargs)
46 56 checkconsistency(
47 57 self._ui, orig, self._map, self._map.nonnormalset, b"after"
48 58 )
49 59 return r
50 60
51 61
52 62 def extsetup(ui):
53 63 """Wrap functions modifying dirstate to check nonnormalset consistency"""
54 64 dirstatecl = dirstate.dirstate
55 65 devel = ui.configbool(b'devel', b'all-warnings')
56 66 paranoid = ui.configbool(b'experimental', b'nonnormalparanoidcheck')
57 67 if devel:
58 68 extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate)
59 69 if paranoid:
60 70 # We don't do all these checks when paranoid is disable as it would
61 71 # make the extension run very slowly on large repos
62 72 extensions.wrapfunction(dirstatecl, 'write', _checkdirstate)
63 73 extensions.wrapfunction(dirstatecl, 'set_tracked', _checkdirstate)
64 74 extensions.wrapfunction(dirstatecl, 'set_untracked', _checkdirstate)
65 75 extensions.wrapfunction(
66 76 dirstatecl, 'set_possibly_dirty', _checkdirstate
67 77 )
68 78 extensions.wrapfunction(
69 79 dirstatecl, 'update_file_p1', _checkdirstate
70 80 )
71 81 extensions.wrapfunction(dirstatecl, 'update_file', _checkdirstate)
General Comments 0
You need to be logged in to leave comments. Login now