diff mercurial/dirstate.py @ 48089:c87844960a35

dirstate: move verification code within the dirstate itself This move implementation details further down the stack and make it the verification code easier to discover. Differential Revision: https://phab.mercurial-scm.org/D11526
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 30 Sep 2021 12:00:15 +0200
parents 6a78715e56c8
children dcd97b082b3b
line wrap: on
line diff
--- a/mercurial/dirstate.py	Wed Sep 29 14:52:44 2021 +0200
+++ b/mercurial/dirstate.py	Thu Sep 30 12:00:15 2021 +0200
@@ -1525,3 +1525,22 @@
     def clearbackup(self, tr, backupname):
         '''Clear backup file'''
         self._opener.unlink(backupname)
+
+    def verify(self, m1, m2):
+        """check the dirstate content again the parent manifest and yield errors"""
+        missing_from_p1 = b"%s in state %s, but not in manifest1\n"
+        unexpected_in_p1 = b"%s in state %s, but also in manifest1\n"
+        missing_from_ps = b"%s in state %s, but not in either manifest\n"
+        missing_from_ds = b"%s in manifest1, but listed as state %s\n"
+        for f, entry in self.items():
+            state = entry.state
+            if state in b"nr" and f not in m1:
+                yield (missing_from_p1, f, state)
+            if state in b"a" and f in m1:
+                yield (unexpected_in_p1, f, state)
+            if state in b"m" and f not in m1 and f not in m2:
+                yield (missing_from_ps, f, state)
+        for f in m1:
+            state = self.get_entry(f).state
+            if state not in b"nrm":
+                yield (missing_from_ds, f, state)