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/
hg-reviewers |
This is a redo of D1963 that has the added benefit of not breaking
Python 2. Oops.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
dirstate, | dirstate, | ||||
extensions, | extensions, | ||||
) | ) | ||||
def nonnormalentries(dmap): | def nonnormalentries(dmap): | ||||
"""Compute nonnormal entries from dirstate's dmap""" | """Compute nonnormal entries from dirstate's dmap""" | ||||
res = set() | res = set() | ||||
for f, e in dmap.iteritems(): | for f, e in dmap.iteritems(): | ||||
if e[0] != 'n' or e[3] == -1: | if e[0] != b'n' or e[3] == -1: | ||||
res.add(f) | res.add(f) | ||||
return res | return res | ||||
def checkconsistency(ui, orig, dmap, _nonnormalset, label): | def checkconsistency(ui, orig, dmap, _nonnormalset, label): | ||||
"""Compute nonnormalset from dmap, check that it matches _nonnormalset""" | """Compute nonnormalset from dmap, check that it matches _nonnormalset""" | ||||
nonnormalcomputedmap = nonnormalentries(dmap) | nonnormalcomputedmap = nonnormalentries(dmap) | ||||
if _nonnormalset != nonnormalcomputedmap: | if _nonnormalset != nonnormalcomputedmap: | ||||
ui.develwarn("%s call to %s\n" % (label, orig), config='dirstate') | ui.develwarn(b"%s call to %s\n" % (label, orig), config=b'dirstate') | ||||
ui.develwarn("inconsistency in nonnormalset\n", config='dirstate') | ui.develwarn(b"inconsistency in nonnormalset\n", config=b'dirstate') | ||||
ui.develwarn("[nonnormalset] %s\n" % _nonnormalset, config='dirstate') | ui.develwarn(b"[nonnormalset] %s\n" % _nonnormalset, config=b'dirstate') | ||||
ui.develwarn("[map] %s\n" % nonnormalcomputedmap, config='dirstate') | ui.develwarn(b"[map] %s\n" % nonnormalcomputedmap, config=b'dirstate') | ||||
def _checkdirstate(orig, self, arg): | def _checkdirstate(orig, self, arg): | ||||
"""Check nonnormal set consistency before and after the call to orig""" | """Check nonnormal set consistency before and after the call to orig""" | ||||
checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, | checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, | ||||
"before") | b"before") | ||||
r = orig(self, arg) | r = orig(self, arg) | ||||
checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, "after") | checkconsistency(self._ui, orig, self._map, self._map.nonnormalset, | ||||
b"after") | |||||
return r | return r | ||||
def extsetup(ui): | def extsetup(ui): | ||||
"""Wrap functions modifying dirstate to check nonnormalset consistency""" | """Wrap functions modifying dirstate to check nonnormalset consistency""" | ||||
dirstatecl = dirstate.dirstate | dirstatecl = dirstate.dirstate | ||||
devel = ui.configbool('devel', 'all-warnings') | devel = ui.configbool(b'devel', b'all-warnings') | ||||
paranoid = ui.configbool('experimental', 'nonnormalparanoidcheck') | paranoid = ui.configbool(b'experimental', b'nonnormalparanoidcheck') | ||||
if devel: | if devel: | ||||
extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate) | extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate) | ||||
if paranoid: | if paranoid: | ||||
# We don't do all these checks when paranoid is disable as it would | # We don't do all these checks when paranoid is disable as it would | ||||
# make the extension run very slowly on large repos | # make the extension run very slowly on large repos | ||||
extensions.wrapfunction(dirstatecl, 'normallookup', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'normallookup', _checkdirstate) | ||||
extensions.wrapfunction(dirstatecl, 'otherparent', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'otherparent', _checkdirstate) | ||||
extensions.wrapfunction(dirstatecl, 'normal', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'normal', _checkdirstate) | ||||
extensions.wrapfunction(dirstatecl, 'write', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'write', _checkdirstate) | ||||
extensions.wrapfunction(dirstatecl, 'add', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'add', _checkdirstate) | ||||
extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate) | ||||
extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate) | ||||
extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate) | extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate) |
self.setparents(nullid, nullid) | self.setparents(nullid, nullid) | ||||
util.clearcachedproperty(self, "_dirs") | util.clearcachedproperty(self, "_dirs") | ||||
util.clearcachedproperty(self, "_alldirs") | util.clearcachedproperty(self, "_alldirs") | ||||
util.clearcachedproperty(self, "filefoldmap") | util.clearcachedproperty(self, "filefoldmap") | ||||
util.clearcachedproperty(self, "dirfoldmap") | util.clearcachedproperty(self, "dirfoldmap") | ||||
util.clearcachedproperty(self, "nonnormalset") | util.clearcachedproperty(self, "nonnormalset") | ||||
util.clearcachedproperty(self, "otherparentset") | util.clearcachedproperty(self, "otherparentset") | ||||
def iteritems(self): | def items(self): | ||||
return self._map.iteritems() | return self._map.iteritems() | ||||
# forward for python2,3 compat | |||||
iteritems = items | |||||
def __len__(self): | def __len__(self): | ||||
return len(self._map) | return len(self._map) | ||||
def __iter__(self): | def __iter__(self): | ||||
return iter(self._map) | return iter(self._map) | ||||
def get(self, key, default=None): | def get(self, key, default=None): | ||||
return self._map.get(key, default) | return self._map.get(key, default) |