[PATCH 4 of 5 V5] dirstate: add test for non-normal map consistency
Laurent Charignon
lcharignon at fb.com
Thu Dec 17 17:44:45 CST 2015
# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1450380560 28800
# Thu Dec 17 11:29:20 2015 -0800
# Node ID 5e602abc66260d6ed561107076cdf45444b0faa8
# Parent b0ba042a2da3e232e6cb8e8c19df84c09fc27bb5
dirstate: add test for non-normal map consistency
This adds a test extension to check that the non-normal map contains the
expected entries. It wraps several methods of the dirstate to check that
the non-normal map has the correct values before and after the call. The
extension lives in contrib so that paranoid developers can easily
enable it to make sure that the non-normal map is consistent across more
complex operations than the included tests.
diff --git a/contrib/dirstatenonnormalcheck.py b/contrib/dirstatenonnormalcheck.py
new file mode 100644
--- /dev/null
+++ b/contrib/dirstatenonnormalcheck.py
@@ -0,0 +1,60 @@
+# dirstatenonnormalcheck.py - extension to check the consistency of the
+# dirstate's non-normal map
+#
+# For most operations on dirstate, this extensions checks that the nonnormalmap
+# contains the right entries.
+# It compares the nonnormal file to a nonnormalmap built from the map of all
+# the files in the dirstate to check that they contain the same files.
+
+from __future__ import absolute_import
+
+from mercurial import (
+ dirstate,
+ extensions,
+)
+
+def nonnormalentries(dmap):
+ """Compute nonnormal entries from dirstate's dmap"""
+ res = {}
+ for f, e in dmap.iteritems():
+ if e[0] != 'n' or e[3] == -1:
+ res[f] = tuple(e)
+ return res
+
+def checkconsistency(ui, orig, dmap, _nonnormalmap, label):
+ """Compute nonnormamap from dmap, check that it matches nonnormalmap"""
+ nonnormalcomputedmap = nonnormalentries(dmap)
+ nonnormalmap = {}
+ for k in _nonnormalmap:
+ nonnormalmap[k] = tuple(_nonnormalmap[k])
+ if nonnormalmap != nonnormalcomputedmap:
+ ui.develwarn("%s call to %s\n" % (label, orig))
+ ui.develwarn("inconsistency in nonnormalmap\n")
+ ui.develwarn("[nonnormalmap] %s\n" % nonnormalmap)
+ ui.develwarn("[map] %s\n" % nonnormalcomputedmap)
+
+def _checkdirstate(orig, self, arg):
+ """Check nonnormal map consistency before and after the call to orig"""
+ checkconsistency(self._ui, orig, self._map, self._nonnormalmap, "before")
+ r = orig(self, arg)
+ checkconsistency(self._ui, orig, self._map, self._nonnormalmap, "after")
+ return r
+
+def extsetup(ui):
+ """Wrap functions modifying dirstate to check nonnormalmap consistency"""
+ dirstatecl = dirstate.dirstate
+ devel = ui.configbool('devel', 'all-warnings')
+ paranoid = ui.configbool('experimental', 'nonnormalparanoidcheck')
+ if devel:
+ extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate)
+ if paranoid:
+ # We don't do all these checks when paranoid is disable as it would
+ # make the extension run very slowly on large repos
+ extensions.wrapfunction(dirstatecl, 'normallookup', _checkdirstate)
+ extensions.wrapfunction(dirstatecl, 'otherparent', _checkdirstate)
+ extensions.wrapfunction(dirstatecl, 'normal', _checkdirstate)
+ extensions.wrapfunction(dirstatecl, 'write', _checkdirstate)
+ extensions.wrapfunction(dirstatecl, 'add', _checkdirstate)
+ extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate)
+ extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate)
+ extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate)
diff --git a/tests/test-dirstate-nonnormalmap.t b/tests/test-dirstate-nonnormalmap.t
new file mode 100644
--- /dev/null
+++ b/tests/test-dirstate-nonnormalmap.t
@@ -0,0 +1,22 @@
+ $ cat >> $HGRCPATH << EOF
+ > [ui]
+ > logtemplate="{rev}:{node|short} ({phase}) [{tags} {bookmarks}] {desc|firstline}\n"
+ > [extensions]
+ > dirstateparanoidcheck = $TESTDIR/../contrib/dirstatenonnormalcheck.py
+ > [experimental]
+ > nonnormalparanoidcheck = True
+ > [devel]
+ > all-warnings=True
+ > EOF
+ $ mkcommit() {
+ > echo "$1" > "$1"
+ > hg add "$1"
+ > hg ci -m "add $1"
+ > }
+
+ $ hg init testrepo
+ $ cd testrepo
+ $ mkcommit a
+ $ mkcommit b
+ $ mkcommit c
+ $ hg status
More information about the Mercurial-devel
mailing list