From patchwork Thu Sep 17 20:11:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D9037: mergestate: initialize all properties in __init__() From: phabricator X-Patchwork-Id: 47196 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Thu, 17 Sep 2020 20:11:05 +0000 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 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)