[PATCH] win32: read system rcpath from registry

Steve Borho steve at borho.org
Sat Dec 1 22:44:28 CST 2007


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1196569615 21600
# Node ID 415a66f248d90b9bcb4e242f8728efa1c06c3ee3
# Parent  feac5b0bf9bad2c125ebd5f3e133bcd46ecb8c7c
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.

diff --git a/mercurial/util_win32.py b/mercurial/util_win32.py
--- a/mercurial/util_win32.py
+++ b/mercurial/util_win32.py
@@ -16,6 +16,7 @@ from i18n import _
 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 testpid(pid):
 
 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


More information about the Mercurial-devel mailing list