Patchwork D11565: dirstatemap: use a common __init__ for dirstatemap

login
register
mail settings
Submitter phabricator
Date Oct. 2, 2021, 3:04 p.m.
Message ID <differential-rev-PHID-DREV-okqbduoxxrci2wbvrmvw-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49889/
State Superseded
Headers show

Comments

phabricator - Oct. 2, 2021, 3:04 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is the first and simplest things to put in common.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -41,6 +41,20 @@ 
     class, with and without Rust extensions enabled.
     """
 
+    def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
+        self._use_dirstate_v2 = use_dirstate_v2
+        self._nodeconstants = nodeconstants
+        self._ui = ui
+        self._opener = opener
+        self._root = root
+        self._filename = b'dirstate'
+        self._nodelen = 20  # Also update Rust code when changing this!
+        self._parents = None
+        self._dirtyparents = False
+
+        # for consistent view between _pl() and _read() invocations
+        self._pendingmode = None
+
 
 class dirstatemap(_dirstatemapcommon):
     """Map encapsulating the dirstate's contents.
@@ -77,21 +91,13 @@ 
     """
 
     def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
-        self._ui = ui
-        self._opener = opener
-        self._root = root
-        self._filename = b'dirstate'
-        self._nodelen = 20
-        self._nodeconstants = nodeconstants
-        assert (
-            not use_dirstate_v2
-        ), "should have detected unsupported requirement"
-
-        self._parents = None
-        self._dirtyparents = False
-
-        # for consistent view between _pl() and _read() invocations
-        self._pendingmode = None
+        super(dirstatemap, self).__init__(
+            ui, opener, root, nodeconstants, use_dirstate_v2
+        )
+        if self._use_dirstate_v2:
+            msg = "Dirstate V2 not supportedi"
+            msg += "(should have detected unsupported requirement)"
+            raise error.ProgrammingError(msg)
 
     @propertycache
     def _map(self):
@@ -469,20 +475,11 @@ 
 
     class dirstatemap(_dirstatemapcommon):
         def __init__(self, ui, opener, root, nodeconstants, use_dirstate_v2):
-            self._use_dirstate_v2 = use_dirstate_v2
-            self._nodeconstants = nodeconstants
-            self._ui = ui
-            self._opener = opener
-            self._root = root
-            self._filename = b'dirstate'
-            self._nodelen = 20  # Also update Rust code when changing this!
-            self._parents = None
-            self._dirtyparents = False
+            super(dirstatemap, self).__init__(
+                ui, opener, root, nodeconstants, use_dirstate_v2
+            )
             self._docket = None
 
-            # for consistent view between _pl() and _read() invocations
-            self._pendingmode = None
-
         def addfile(
             self,
             f,