changeset 45401:ede4c121239e

mergestate: use collections.defaultdict(dict) for _stateextras 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. Differential Revision: https://phab.mercurial-scm.org/D8919
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 10 Aug 2020 15:09:44 +0530
parents f0735f2ce542
children 0652a533fe3c
files mercurial/mergestate.py
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mergestate.py	Mon Aug 03 23:41:50 2020 -0700
+++ b/mercurial/mergestate.py	Mon Aug 10 15:09:44 2020 +0530
@@ -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`.