# HG changeset patch # User Pierre-Yves David # Date 2021-10-01 14:52:44 # Node ID fe66177154648861591e2ab7b09f604258211ef3 # Parent aec5b0981c268c272a502afe681326374fb403c3 dirstatemap: use a common __init__ for dirstatemap This is the first and simplest things to put in common. Differential Revision: https://phab.mercurial-scm.org/D11565 diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py --- a/mercurial/dirstatemap.py +++ b/mercurial/dirstatemap.py @@ -41,6 +41,20 @@ class _dirstatemapcommon(object): 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 @@ class dirstatemap(_dirstatemapcommon): """ 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 @@ if rustmod is not None: 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,