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