mergestate: initialize all properties in __init__()
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 16 Sep 2020 13:39:26 -0700
changeset 45496 ef3273ac5f6e
parent 45495 3dd481e11c25
child 45497 e833ff4dd0ea
mergestate: initialize all properties in __init__() 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. Differential Revision: https://phab.mercurial-scm.org/D9037
mercurial/mergestate.py
--- a/mercurial/mergestate.py	Thu Sep 17 19:33:55 2020 -0700
+++ b/mercurial/mergestate.py	Wed Sep 16 13:39:26 2020 -0700
@@ -195,8 +195,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)
@@ -205,15 +217,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
@@ -221,11 +226,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()
@@ -277,13 +277,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)