Mercurial > hg
comparison contrib/dirstatenonnormalcheck.py @ 35878:6e7fae8f1c6c
contrib: fix dirstatenonnormalcheck to work in Python 3
This is a redo of D1963 that has the added benefit of not breaking
Python 2. Oops.
# skip-blame because this is bytes prefixes and a s/iteritems/items/
Differential Revision: https://phab.mercurial-scm.org/D1970
author | Augie Fackler <augie@google.com> |
---|---|
date | Thu, 01 Feb 2018 16:01:43 -0500 |
parents | 60927b19ed65 |
children | 2372284d9457 |
comparison
equal
deleted
inserted
replaced
35877:11fdf1486519 | 35878:6e7fae8f1c6c |
---|---|
15 | 15 |
16 def nonnormalentries(dmap): | 16 def nonnormalentries(dmap): |
17 """Compute nonnormal entries from dirstate's dmap""" | 17 """Compute nonnormal entries from dirstate's dmap""" |
18 res = set() | 18 res = set() |
19 for f, e in dmap.iteritems(): | 19 for f, e in dmap.iteritems(): |
20 if e[0] != 'n' or e[3] == -1: | 20 if e[0] != b'n' or e[3] == -1: |
21 res.add(f) | 21 res.add(f) |
22 return res | 22 return res |
23 | 23 |
24 def checkconsistency(ui, orig, dmap, _nonnormalset, label): | 24 def checkconsistency(ui, orig, dmap, _nonnormalset, label): |
25 """Compute nonnormalset from dmap, check that it matches _nonnormalset""" | 25 """Compute nonnormalset from dmap, check that it matches _nonnormalset""" |
26 nonnormalcomputedmap = nonnormalentries(dmap) | 26 nonnormalcomputedmap = nonnormalentries(dmap) |
27 if _nonnormalset != nonnormalcomputedmap: | 27 if _nonnormalset != nonnormalcomputedmap: |
28 ui.develwarn("%s call to %s\n" % (label, orig), config='dirstate') | 28 ui.develwarn(b"%s call to %s\n" % (label, orig), config=b'dirstate') |
29 ui.develwarn("inconsistency in nonnormalset\n", config='dirstate') | 29 ui.develwarn(b"inconsistency in nonnormalset\n", config=b'dirstate') |
30 ui.develwarn("[nonnormalset] %s\n" % _nonnormalset, config='dirstate') | 30 ui.develwarn(b"[nonnormalset] %s\n" % _nonnormalset, config=b'dirstate') |
31 ui.develwarn("[map] %s\n" % nonnormalcomputedmap, config='dirstate') | 31 ui.develwarn(b"[map] %s\n" % nonnormalcomputedmap, config=b'dirstate') |
32 | 32 |
33 def _checkdirstate(orig, self, arg): | 33 def _checkdirstate(orig, self, arg): |
34 """Check nonnormal set consistency before and after the call to orig""" | 34 """Check nonnormal set consistency before and after the call to orig""" |
35 checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, | 35 checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, |
36 "before") | 36 b"before") |
37 r = orig(self, arg) | 37 r = orig(self, arg) |
38 checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, "after") | 38 checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, |
39 b"after") | |
39 return r | 40 return r |
40 | 41 |
41 def extsetup(ui): | 42 def extsetup(ui): |
42 """Wrap functions modifying dirstate to check nonnormalset consistency""" | 43 """Wrap functions modifying dirstate to check nonnormalset consistency""" |
43 dirstatecl = dirstate.dirstate | 44 dirstatecl = dirstate.dirstate |
44 devel = ui.configbool('devel', 'all-warnings') | 45 devel = ui.configbool(b'devel', b'all-warnings') |
45 paranoid = ui.configbool('experimental', 'nonnormalparanoidcheck') | 46 paranoid = ui.configbool(b'experimental', b'nonnormalparanoidcheck') |
46 if devel: | 47 if devel: |
47 extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate) | 48 extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate) |
48 if paranoid: | 49 if paranoid: |
49 # We don't do all these checks when paranoid is disable as it would | 50 # We don't do all these checks when paranoid is disable as it would |
50 # make the extension run very slowly on large repos | 51 # make the extension run very slowly on large repos |