Patchwork D9037: mergestate: initialize all properties in __init__()

login
register
mail settings
Submitter phabricator
Date Sept. 17, 2020, 8:11 p.m.
Message ID <differential-rev-PHID-DREV-kx5rnykk6x66rhcwxtkh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47196/
State Superseded
Headers show

Comments

phabricator - Sept. 17, 2020, 8:11 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is hopefully not very controverial. I found the initialization
  before this patch unorthodox. It wasn't clear which properties the
  object was supposed to have.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/mergestate.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/mergestate.py b/mercurial/mergestate.py
--- a/mercurial/mergestate.py
+++ b/mercurial/mergestate.py
@@ -196,8 +196,20 @@ 
 
         Do not use this directly! Instead call read() or clean()."""
         self._repo = repo
+        self._state = {}
+        self._stateextras = collections.defaultdict(dict)
+        self._local = None
+        self._other = None
+        self._labels = None
+        self._readmergedriver = None
+        self._mdstate = MERGE_DRIVER_STATE_UNMARKED
+        # contains a mapping of form:
+        # {filename : (merge_return_value, action_to_be_performed}
+        # these are results of re-running merge process
+        # this dict is used to perform actions on dirstate caused by re-running
+        # the merge
+        self._results = {}
         self._dirty = False
-        self._labels = None
 
     def reset(self):
         shutil.rmtree(self._repo.vfs.join(b'merge'), True)
@@ -206,15 +218,8 @@ 
         self._local = node
         self._other = other
         self._labels = labels
-        self._state = {}
-        self._stateextras = collections.defaultdict(dict)
-        self._readmergedriver = None
         if self.mergedriver:
             self._mdstate = MERGE_DRIVER_STATE_SUCCESS
-        else:
-            self._mdstate = MERGE_DRIVER_STATE_UNMARKED
-        self._results = {}
-        self._dirty = False
 
     def _read(self):
         """Analyse each record content to restore a serialized state from disk
@@ -222,11 +227,6 @@ 
         This function process "record" entry produced by the de-serialization
         of on disk file.
         """
-        self._state = {}
-        self._stateextras = collections.defaultdict(dict)
-        self._local = None
-        self._other = None
-        self._readmergedriver = None
         self._mdstate = MERGE_DRIVER_STATE_SUCCESS
         unsupported = set()
         records = self._readrecords()
@@ -278,13 +278,6 @@ 
                 self._labels = [l for l in labels if len(l) > 0]
             elif not rtype.islower():
                 unsupported.add(rtype)
-        # contains a mapping of form:
-        # {filename : (merge_return_value, action_to_be_performed}
-        # these are results of re-running merge process
-        # this dict is used to perform actions on dirstate caused by re-running
-        # the merge
-        self._results = {}
-        self._dirty = False
 
         if unsupported:
             raise error.UnsupportedMergeRecords(unsupported)