changeset 5583:1b5b81d9039b

win32: read system rcpath from registry Using the module name was not always helpful. It breaks down when Mercurial is installed as source and when the Mercurial libs are used by external applications. This patch allows Mercurial installers to store the system wide rcpath in the registry, where it can always be found. HGRCPATH is a poor option for storing the system wide rcpath, since it overrides both the system and user rcpaths.
author Steve Borho <steve@borho.org>
date Sun, 02 Dec 2007 17:15:03 +0100
parents 60d46e0bd656
children b34028d52e7e
files doc/hgrc.5.txt mercurial/util_win32.py
diffstat 2 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/doc/hgrc.5.txt	Sun Dec 02 14:06:10 2007 +0100
+++ b/doc/hgrc.5.txt	Sun Dec 02 17:15:03 2007 +0100
@@ -17,7 +17,9 @@
 
 Mercurial reads configuration data from several files, if they exist.
 The names of these files depend on the system on which Mercurial is
-installed.
+installed. Windows registry keys contain PATH-like strings, every
+part must reference a Mercurial.ini file or be a directory where *.rc
+files will be read.
 
 (Unix)    <install-root>/etc/mercurial/hgrc.d/*.rc::
 (Unix)    <install-root>/etc/mercurial/hgrc::
@@ -29,6 +31,8 @@
 
 (Unix)    /etc/mercurial/hgrc.d/*.rc::
 (Unix)    /etc/mercurial/hgrc::
+(Windows) HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial::
+  or::
 (Windows) C:\Mercurial\Mercurial.ini::
     Per-system configuration files, for the system on which Mercurial
     is running.  Options in these files apply to all Mercurial
--- a/mercurial/util_win32.py	Sun Dec 02 14:06:10 2007 +0100
+++ b/mercurial/util_win32.py	Sun Dec 02 17:15:03 2007 +0100
@@ -16,6 +16,7 @@
 from i18n import _
 import errno, os, pywintypes, win32con, win32file, win32process
 import cStringIO, winerror
+import osutil
 from win32com.shell import shell,shellcon
 
 class WinError:
@@ -179,6 +180,20 @@
 
 def system_rcpath_win32():
     '''return default os-specific hgrc search path'''
+    try:
+        value = win32api.RegQueryValue(
+                win32con.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Mercurial')
+        rcpath = []
+        for p in value.split(os.pathsep):
+            if p.lower().endswith('mercurial.ini'):
+                rcpath.append(p)
+            elif os.path.isdir(p):
+                for f, kind in osutil.listdir(p):
+                    if f.endswith('.rc'):
+                        rcpath.append(os.path.join(p, f))
+        return rcpath
+    except pywintypes.error:
+        pass
     proc = win32api.GetCurrentProcess()
     try:
         # This will fail on windows < NT