Patchwork D6193: config: read configs from directories in lexicographical order

login
register
mail settings
Submitter phabricator
Date April 3, 2019, 11:07 p.m.
Message ID <differential-rev-PHID-DREV-apixxunbirlqhbq6hl5s-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39465/
State Superseded
Headers show

Comments

phabricator - April 3, 2019, 11:07 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Mercurial currently reads the .rc files specified in HGRCPATH (and the
  system-default paths) in directory order, which is unspecified. My
  team at work maintains a set of .rc files. So far there has been no
  overlap between them, so we had not noticed this behavior. However, we
  would now like to release some common .rc files and then have another
  one with platform-specific overrides. It would be nice of we can
  determine the load order by choosing names carefully. This patch
  enables that by loading the .rc files in lexicographical order.
  
  Before this patch, the added test case would consistently say "30" on
  my file system (whatever I have -- some Linux FS).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6193

AFFECTED FILES
  mercurial/rcutil.py
  tests/test-config.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -211,3 +211,12 @@ 
   $ hg log --template '{author}\n'
   repo user
   $ cd ..
+
+configs should be readon in lexicographical order
+
+  $ mkdir configs
+  $ for i in `$TESTDIR/seq.py 10 99`; do
+  >    printf "[section]\nkey=$i" > configs/$i.rc
+  > done
+  $ HGRCPATH=configs hg config section.key
+  99
diff --git a/mercurial/rcutil.py b/mercurial/rcutil.py
--- a/mercurial/rcutil.py
+++ b/mercurial/rcutil.py
@@ -29,7 +29,8 @@ 
     p = util.expandpath(path)
     if os.path.isdir(p):
         join = os.path.join
-        return [join(p, f) for f, k in util.listdir(p) if f.endswith('.rc')]
+        return sorted(join(p, f) for f, k in util.listdir(p)
+                      if f.endswith('.rc'))
     return [p]
 
 def envrcitems(env=None):