[PATCH 2 of 2] config: use the alternative with highest level

Boris Feld boris.feld at octobus.net
Mon Jul 9 06:12:22 EDT 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1530895697 -7200
#      Fri Jul 06 18:48:17 2018 +0200
# Node ID 2eac4bcf6e050eeb55f6872b816ed3a328818614
# Parent  1019d8a4f6b810aaa63651ed56b29668650f590e
# EXP-Topic config-order
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 2eac4bcf6e05
config: use the alternative with highest level

With this change, an alias defined in an higher level configuration file will
take precedence over values from other alternatives.

Change the case from 'r' to 'R' to make sure the sorting is made over the
configuration file priority and not on the values themselves.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -552,13 +552,17 @@ class ui(object):
             msg %= (section, name, pycompat.bytestr(default))
             self.develwarn(msg, 2, 'warn-config-default')
 
-        for s, n in alternates:
+        found = []
+        for idx, (s, n) in enumerate(alternates):
             candidate = self._data(untrusted).get(s, n, None)
             if candidate is not None:
                 value = candidate
                 section = s
                 name = n
-                break
+                level = self._data(untrusted).level(s, n)
+                found.append((level, -idx, value))
+        if found:
+            value = max(found)[-1]
 
         if self.debugflag and not untrusted and self._reportuntrusted:
             for s, n in alternates:
diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -202,12 +202,36 @@ alias has lower priority
   $ cat > .hg/hgrc << EOF
   > [ui]
   > user = alias user
-  > username = repo user
+  > username = Repo user
   > EOF
   $ touch index
   $ unset HGUSER
   $ hg ci -Am test
   adding index
   $ hg log --template '{author}\n'
-  repo user
+  Repo user
   $ cd ..
+
+Unless alias are specified at an higher level
+
+  $ hg init aliaspriority-level
+  $ cd aliaspriority-level
+  $ cat >> $HGRCPATH << EOF
+  > [ui]
+  > username = repo user
+  > EOF
+  $ cat > .hg/hgrc << EOF
+  > [ui]
+  > user = alias user
+  > EOF
+  $ touch index
+  $ unset HGUSER
+  $ hg ci -Am test
+  adding index
+  $ hg log --template '{author}\n'
+  alias user
+  $ echo foo >> index
+  $ hg ci -m test --config ui.username=cmd-user
+  $ hg log --template '{author}\n' -r .
+  cmd-user
+  $ cd ..


More information about the Mercurial-devel mailing list