config: use level to properly deal with value priority
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 29 Jan 2021 12:17:11 +0100
changeset 46662 b91a695b3b08
parent 46661 a3dced4b7b04
child 46663 357d2ea95ce9
config: use level to properly deal with value priority A higher priority alias will now take precedence over lower priority ones. This was a requirements step before using alias more widely, especially to rename existing and established config option. Differential Revision: https://phab.mercurial-scm.org/D9927
mercurial/ui.py
tests/test-config.t
--- a/mercurial/ui.py	Fri Jan 29 11:21:49 2021 +0100
+++ b/mercurial/ui.py	Fri Jan 29 12:17:11 2021 +0100
@@ -662,11 +662,18 @@
             msg %= (section, name, pycompat.bytestr(default))
             self.develwarn(msg, 2, b'warn-config-default')
 
+        candidates = []
+        config = self._data(untrusted)
         for s, n in alternates:
-            candidate = self._data(untrusted).get(s, n, None)
+            candidate = config.get(s, n, None)
             if candidate is not None:
-                value = candidate
-                break
+                candidates.append((s, n, candidate))
+        if candidates:
+
+            def level(x):
+                return config.level(x[0], x[1])
+
+            value = max(candidates, key=level)[2]
 
         if self.debugflag and not untrusted and self._reportuntrusted:
             for s, n in alternates:
--- a/tests/test-config.t	Fri Jan 29 11:21:49 2021 +0100
+++ b/tests/test-config.t	Fri Jan 29 12:17:11 2021 +0100
@@ -476,15 +476,12 @@
 earlier will be considered "lower level" and the config read later would be
 considered "higher level". And higher level values wins.
 
-BROKEN: currently not the case.
-
   $ HGRCPATH="file-A.rc" hg log -r .
   value-A
   $ HGRCPATH="file-B.rc" hg log -r .
   value-B
   $ HGRCPATH="file-A.rc:file-B.rc" hg log -r .
-  value-A (known-bad-output !)
-  value-B (missing-correct-output !)
+  value-B
 
 Alias and include
 -----------------
@@ -493,15 +490,12 @@
 See the case above for details about the two config options used.
 
   $ HGRCPATH="file-C.rc" hg log -r .
-  value-included (known-bad-output !)
-  value-C (missing-correct-output !)
+  value-C
   $ HGRCPATH="file-D.rc" hg log -r .
-  value-D (known-bad-output !)
-  value-included (missing-correct-output !)
+  value-included
 
 command line override
 ---------------------
 
   $ HGRCPATH="file-A.rc:file-B.rc" hg log -r . --config ui.logtemplate="value-CLI\n"
-  value-A (known-bad-output !)
-  value-CLI (missing-correct-output !)
+  value-CLI