##// END OF EJS Templates
dirstate-item: use the properties in `contrib/dirstatenonnormalcheck.py`...
marmoute -
r48335:35295f5a default
parent child Browse files
Show More
@@ -1,65 +1,65 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 )
14 )
15
15
16
16
17 def nonnormalentries(dmap):
17 def nonnormalentries(dmap):
18 """Compute nonnormal entries from dirstate's dmap"""
18 """Compute nonnormal entries from dirstate's dmap"""
19 res = set()
19 res = set()
20 for f, e in dmap.iteritems():
20 for f, e in dmap.iteritems():
21 if e[0] != b'n' or e[3] == -1:
21 if e.state != b'n' or e.mtime == -1:
22 res.add(f)
22 res.add(f)
23 return res
23 return res
24
24
25
25
26 def checkconsistency(ui, orig, dmap, _nonnormalset, label):
26 def checkconsistency(ui, orig, dmap, _nonnormalset, label):
27 """Compute nonnormalset from dmap, check that it matches _nonnormalset"""
27 """Compute nonnormalset from dmap, check that it matches _nonnormalset"""
28 nonnormalcomputedmap = nonnormalentries(dmap)
28 nonnormalcomputedmap = nonnormalentries(dmap)
29 if _nonnormalset != nonnormalcomputedmap:
29 if _nonnormalset != nonnormalcomputedmap:
30 ui.develwarn(b"%s call to %s\n" % (label, orig), config=b'dirstate')
30 ui.develwarn(b"%s call to %s\n" % (label, orig), config=b'dirstate')
31 ui.develwarn(b"inconsistency in nonnormalset\n", config=b'dirstate')
31 ui.develwarn(b"inconsistency in nonnormalset\n", config=b'dirstate')
32 ui.develwarn(b"[nonnormalset] %s\n" % _nonnormalset, config=b'dirstate')
32 ui.develwarn(b"[nonnormalset] %s\n" % _nonnormalset, config=b'dirstate')
33 ui.develwarn(b"[map] %s\n" % nonnormalcomputedmap, config=b'dirstate')
33 ui.develwarn(b"[map] %s\n" % nonnormalcomputedmap, config=b'dirstate')
34
34
35
35
36 def _checkdirstate(orig, self, arg):
36 def _checkdirstate(orig, self, arg):
37 """Check nonnormal set consistency before and after the call to orig"""
37 """Check nonnormal set consistency before and after the call to orig"""
38 checkconsistency(
38 checkconsistency(
39 self._ui, orig, self._map, self._map.nonnormalset, b"before"
39 self._ui, orig, self._map, self._map.nonnormalset, b"before"
40 )
40 )
41 r = orig(self, arg)
41 r = orig(self, arg)
42 checkconsistency(
42 checkconsistency(
43 self._ui, orig, self._map, self._map.nonnormalset, b"after"
43 self._ui, orig, self._map, self._map.nonnormalset, b"after"
44 )
44 )
45 return r
45 return r
46
46
47
47
48 def extsetup(ui):
48 def extsetup(ui):
49 """Wrap functions modifying dirstate to check nonnormalset consistency"""
49 """Wrap functions modifying dirstate to check nonnormalset consistency"""
50 dirstatecl = dirstate.dirstate
50 dirstatecl = dirstate.dirstate
51 devel = ui.configbool(b'devel', b'all-warnings')
51 devel = ui.configbool(b'devel', b'all-warnings')
52 paranoid = ui.configbool(b'experimental', b'nonnormalparanoidcheck')
52 paranoid = ui.configbool(b'experimental', b'nonnormalparanoidcheck')
53 if devel:
53 if devel:
54 extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate)
54 extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate)
55 if paranoid:
55 if paranoid:
56 # We don't do all these checks when paranoid is disable as it would
56 # We don't do all these checks when paranoid is disable as it would
57 # make the extension run very slowly on large repos
57 # make the extension run very slowly on large repos
58 extensions.wrapfunction(dirstatecl, 'normallookup', _checkdirstate)
58 extensions.wrapfunction(dirstatecl, 'normallookup', _checkdirstate)
59 extensions.wrapfunction(dirstatecl, 'otherparent', _checkdirstate)
59 extensions.wrapfunction(dirstatecl, 'otherparent', _checkdirstate)
60 extensions.wrapfunction(dirstatecl, 'normal', _checkdirstate)
60 extensions.wrapfunction(dirstatecl, 'normal', _checkdirstate)
61 extensions.wrapfunction(dirstatecl, 'write', _checkdirstate)
61 extensions.wrapfunction(dirstatecl, 'write', _checkdirstate)
62 extensions.wrapfunction(dirstatecl, 'add', _checkdirstate)
62 extensions.wrapfunction(dirstatecl, 'add', _checkdirstate)
63 extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate)
63 extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate)
64 extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate)
64 extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate)
65 extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate)
65 extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate)
General Comments 0
You need to be logged in to leave comments. Login now