[PATCH 01 of 10 RFC v2] ui: refactoring handling of trusted, user and overlay

Jun Wu quark at fb.com
Wed Mar 15 01:27:49 EDT 2017


The direction looks fine.

I'm especially interested in the performance and correctness of the "config
merging" part (not in this patch), I'll comment in that patch.

It seems it does not conflict with the immutable config objects I had
before. Maybe we want the immutable thing eventually. But that could be done
later. Or I could mix them with ui.compat if you think we should go
immutable directly.

Excerpts from David Soria Parra's message of 2017-03-12 15:40:24 -0700:

[...]

> +    def cfg(self):
> +        # Ordered in ascneding order of preference.
> +        return util.sortdict(
> +            [('user', config.config()),
> +            ('trusted', config.config()),
> +            ('overlay', config.config())])

Maybe make this a private static method. People may expect ui.cfg() to
return the "current" config, instead of new ones.

      @staticmethod
      def _emptyconfig():
          return ....

> +
>      def fixconfig(self, root=None, section=None):
>          if section in (None, 'paths'):
>              # expand vars and ~
>              # translate paths relative to root (or home) into absolute paths
>              root = root or pycompat.getcwd()
> -            for c in self._tcfg, self._ucfg, self._ocfg:
> +            for c in self._cfg.values():
>                  for n, p in c.items('paths'):
>                      # Ignore sub-options.
>                      if ':' in n:
> @@ -345,21 +348,22 @@
>              self._trustgroups.update(self.configlist('trusted', 'groups'))
>  
>      def backupconfig(self, section, item):
> -        return (self._ocfg.backup(section, item),
> -                self._tcfg.backup(section, item),
> -                self._ucfg.backup(section, item),)
> +        return {k: cfg.backup(section, item) for k, cfg in self._cfg.items()}

I guess we still prefer iteritems to reduce overheads on Python 2.
There is an AST transformer rewriting "iteritems" to "items" for Python 3.

[...]


More information about the Mercurial-devel mailing list