Patchwork D8919: mergestate: use collections.defaultdict(dict) for _stateextras

login
register
mail settings
Submitter phabricator
Date Aug. 10, 2020, 11:17 a.m.
Message ID <differential-rev-PHID-DREV-45ydbfuk2rasudprcdf4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47019/
State Superseded
Headers show

Comments

phabricator - Aug. 10, 2020, 11:17 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I want to use this _stateextras more in upcoming patches to store some commit
  time related information. Using defaultdict will help in cleaner code around
  checking whether a file exists or not.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/mergestate.py

CHANGE DETAILS




To: pulkit, #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
@@ -1,5 +1,6 @@ 
 from __future__ import absolute_import
 
+import collections
 import errno
 import shutil
 import struct
@@ -194,7 +195,7 @@ 
 
     def reset(self, node=None, other=None, labels=None):
         self._state = {}
-        self._stateextras = {}
+        self._stateextras = collections.defaultdict(dict)
         self._local = None
         self._other = None
         self._labels = labels
@@ -220,7 +221,7 @@ 
         of on disk file.
         """
         self._state = {}
-        self._stateextras = {}
+        self._stateextras = collections.defaultdict(dict)
         self._local = None
         self._other = None
         for var in ('localctx', 'otherctx'):
@@ -626,7 +627,7 @@ 
                 yield f
 
     def extras(self, filename):
-        return self._stateextras.setdefault(filename, {})
+        return self._stateextras[filename]
 
     def _resolve(self, preresolve, dfile, wctx):
         """rerun merge process for file path `dfile`.
@@ -697,7 +698,7 @@ 
         if merge_ret is None:
             # If return value of merge is None, then there are no real conflict
             del self._state[dfile]
-            self._stateextras.pop(dfile, None)
+            self._stateextras.pop(dfile)
             self._dirty = True
         elif not merge_ret:
             self.mark(dfile, MERGE_RECORD_RESOLVED)