Patchwork [03,of,10,RFC,v2] ui: don't return certain layers when they are supposed to be displayed

login
register
mail settings
Submitter David Soria Parra
Date March 12, 2017, 10:40 p.m.
Message ID <ef5ce5325596fe5fef01.1489358426@davidsp-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/19247/
State Changes Requested
Headers show

Comments

David Soria Parra - March 12, 2017, 10:40 p.m.
# HG changeset patch
# User David Soria Parra <davidsp@fb.com>
# Date 1489349206 25200
#      Sun Mar 12 13:06:46 2017 -0700
# Node ID ef5ce5325596fe5fef014a320abae0f0d5980f3d
# Parent  084a30b54810d05c8b44d22fcab2ef6f783a9f7c
ui: don't return certain layers when they are supposed to be displayed

This is a hack to distinguish visibility for a certain configuration. As we have
layers in place, we can give them a visibility, allowing us to have internal
settings switched on without them showing up in `hg showconfig`. This is useful
for extension to set a list of default flags to trigger behavior.
Jun Wu - March 15, 2017, 5:43 a.m.
Excerpts from David Soria Parra's message of 2017-03-12 15:40:26 -0700:

[...]
  
> -    def _data(self, untrusted):
> +    def _data(self, untrusted, includeinternal=True):
> +        res = {}

This does not seem to work. I guess you mean "res = config.config()".

> +        if includeinternal:
> +            res = self._cfg['defaults']
>          if untrusted:
> -            return self._cfg['user']
> +            res.update(self._cfg['user'])
>          else:
> -            return self._cfg['trusted']
> +            res.update(self._cfg['trusted'])
> +        return res

Two questions:

  - Performance: Constructing empty configs, and "update" them every time
    when "_data" gets called seems to be expensive. Maybe some caching (and
    invalidation may be tricky).

  - Correctness: "%unset" does not seem to be handled correctly.

Maybe I should try polish and send my immutable series, which handles
"%unset" and has some caching stuff.

>  
>      def configsource(self, section, name, untrusted=False):
>          return self._data(untrusted).source(section, name)
> @@ -670,7 +674,7 @@
>          return items
>  
>      def walkconfig(self, untrusted=False):
> -        cfg = self._data(untrusted)
> +        cfg = self._data(untrusted, includeinternal=False)
>          for section in cfg.sections():
>              for name, value in self.configitems(section, untrusted):
>                  yield section, name, value

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -360,11 +360,15 @@ 
             cfg.set(section, name, value, source)
         self.fixconfig(section=section)
 
-    def _data(self, untrusted):
+    def _data(self, untrusted, includeinternal=True):
+        res = {}
+        if includeinternal:
+            res = self._cfg['defaults']
         if untrusted:
-            return self._cfg['user']
+            res.update(self._cfg['user'])
         else:
-            return self._cfg['trusted']
+            res.update(self._cfg['trusted'])
+        return res
 
     def configsource(self, section, name, untrusted=False):
         return self._data(untrusted).source(section, name)
@@ -670,7 +674,7 @@ 
         return items
 
     def walkconfig(self, untrusted=False):
-        cfg = self._data(untrusted)
+        cfg = self._data(untrusted, includeinternal=False)
         for section in cfg.sections():
             for name, value in self.configitems(section, untrusted):
                 yield section, name, value