[PATCH] ui: don't read the same config file twice

David Soria Parra davidsp at fb.com
Tue Mar 14 02:47:47 UTC 2017


# HG changeset patch
# User David Soria Parra <davidsp at fb.com>
# Date 1489459557 25200
#      Mon Mar 13 19:45:57 2017 -0700
# Node ID 7e2222599b4f534e27a0462bb1263208cc1c8d71
# Parent  3d3109339b57341b333c1112beb41dd281fa944a
ui: don't read the same config file twice

During dispatch and localrepo setup we might read the same file twice if
the repository we are loading is the currnet working directory/.hg which is the
default case. We now keep a set of filenames we read around and abort
if we read the config already. It would be nice to do this in a decorator,
but I have not found a reliable, simple way to hash arguments.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -160,6 +160,7 @@
         self._colormode = None
         self._terminfoparams = {}
         self._styles = {}
+        self._readfilenames = set()
 
         if src:
             self.fout = src.fout
@@ -258,6 +259,9 @@
 
     def readconfig(self, filename, root=None, trust=False,
                    sections=None, remap=None):
+        if filename in self._readfilenames:
+            return
+
         try:
             fp = open(filename, u'rb')
         except IOError:
@@ -304,6 +308,7 @@
         if root is None:
             root = os.path.expanduser('~')
         self.fixconfig(root=root)
+        self._readfilenames.add(filename)
 
     def fixconfig(self, root=None, section=None):
         if section in (None, 'paths'):


More information about the Mercurial-devel mailing list