diff mercurial/ui.py @ 47272:a671832a8e41

urlutil: move url "fixing" at the time of `ui.paths` initialization Doing such fixing at the time is simpler and will be necessary to deal with urls list in a sane manner. It also reduce the size of fix-config which is always better. I wish we could get ride of the hackish way to pass the root around, I suspect that the `root` variable could be stored as part of the config value, along side the source. However getting to the end of this `root` business is a far too large detours to make now. The test change to `tests/test-hgrc.t` and `test-config.t` are expectied since we are not longer altering the config itself, but the way it is interpreted when building path. This seems more correct. I also added a couple of test call to `test-config.t` and `test-globalopts.t` to clarify that the expanding process is properly happening a the right time. Differential Revision: https://phab.mercurial-scm.org/D10451
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 15 Apr 2021 20:13:29 +0200
parents bcafcd779d2e
children c887bab2dccf
line wrap: on
line diff
--- a/mercurial/ui.py	Mon May 17 15:15:44 2021 -0700
+++ b/mercurial/ui.py	Thu Apr 15 20:13:29 2021 +0200
@@ -233,6 +233,8 @@
         self._trustusers = set()
         self._trustgroups = set()
         self.callhooks = True
+        # hold the root to use for each [paths] entry
+        self._path_to_root = {}
         # Insecure server connections requested.
         self.insecureconnections = False
         # Blocked time
@@ -264,6 +266,7 @@
             self._trustgroups = src._trustgroups.copy()
             self.environ = src.environ
             self.callhooks = src.callhooks
+            self._path_to_root = src._path_to_root
             self.insecureconnections = src.insecureconnections
             self._colormode = src._colormode
             self._terminfoparams = src._terminfoparams.copy()
@@ -545,22 +548,26 @@
             root = root or encoding.getcwd()
             for c in self._tcfg, self._ucfg, self._ocfg:
                 for n, p in c.items(b'paths'):
+                    old_p = p
+                    s = self.configsource(b'paths', n) or b'none'
+                    root_key = (n, p, s)
+                    if root_key not in self._path_to_root:
+                        self._path_to_root[root_key] = root
                     # Ignore sub-options.
                     if b':' in n:
                         continue
                     if not p:
                         continue
                     if b'%%' in p:
-                        s = self.configsource(b'paths', n) or b'none'
+                        if s is None:
+                            s = 'none'
                         self.warn(
                             _(b"(deprecated '%%' in path %s=%s from %s)\n")
                             % (n, p, s)
                         )
                         p = p.replace(b'%%', b'%')
-                    p = util.expandpath(p)
-                    if not urlutil.hasscheme(p) and not os.path.isabs(p):
-                        p = os.path.normpath(os.path.join(root, p))
-                    c.alter(b"paths", n, p)
+                    if p != old_p:
+                        c.alter(b"paths", n, p)
 
         if section in (None, b'ui'):
             # update ui options