Patchwork D11526: dirstate: move verification code within the dirstate itself

login
register
mail settings
Submitter phabricator
Date Oct. 1, 2021, 9:42 a.m.
Message ID <differential-rev-PHID-DREV-rb77ugzd7rgczt5a3se5-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49853/
State Superseded
Headers show

Comments

phabricator - Oct. 1, 2021, 9:42 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This move implementation details further down the stack and make it the
  verification code easier to discover.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11526

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/dirstate.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -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)
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -550,24 +550,9 @@ 
     m1 = repo[parent1].manifest()
     m2 = repo[parent2].manifest()
     errors = 0
-    for f in repo.dirstate:
-        state = repo.dirstate[f]
-        if state in b"nr" and f not in m1:
-            ui.warn(_(b"%s in state %s, but not in manifest1\n") % (f, state))
-            errors += 1
-        if state in b"a" and f in m1:
-            ui.warn(_(b"%s in state %s, but also in manifest1\n") % (f, state))
-            errors += 1
-        if state in b"m" and f not in m1 and f not in m2:
-            ui.warn(
-                _(b"%s in state %s, but not in either manifest\n") % (f, state)
-            )
-            errors += 1
-    for f in m1:
-        state = repo.dirstate[f]
-        if state not in b"nrm":
-            ui.warn(_(b"%s in manifest1, but listed as state %s") % (f, state))
-            errors += 1
+    for err in repo.dirstate.verify(m1, m2):
+        ui.warn(err[0] % err[1:])
+        errors += 1
     if errors:
         errstr = _(b".hg/dirstate inconsistent with current parent's manifest")
         raise error.Abort(errstr)