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

Jun Wu quark at fb.com
Mon Mar 13 22:56:09 EDT 2017


This is a BC because loading order matters:

  # a.rc
  %include b.rc
  [ui]
  editor = foo
  %include b.rc

  # b.rc
  [ui]
  editor = bar

Since people should be able to arrange config files in a way that no files
are included twice. I prefer not being too smart in hg.

Excerpts from David Soria Parra's message of 2017-03-13 19:47:47 -0700:
> # 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