[PATCH 3 of 3] move system_rcpath and user_rcpath to scmutil

Adrian Buehlmann adrian at cadifra.com
Thu Apr 21 14:46:31 CDT 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1303413414 -7200
# Node ID b9369b6ab1709e618565047ac1030e70a888e316
# Parent  c41e96d3c681a71f2044c92a3e4e3870aaa8c847
move system_rcpath and user_rcpath to scmutil

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -6,7 +6,6 @@
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import osutil
 import os, sys, errno, stat, getpass, pwd, grp, tempfile
 
 posixfile = open
@@ -29,29 +28,6 @@
     '''return number of hardlinks for the given file'''
     return os.lstat(name).st_nlink
 
-def rcfiles(path):
-    rcs = [os.path.join(path, 'hgrc')]
-    rcdir = os.path.join(path, 'hgrc.d')
-    try:
-        rcs.extend([os.path.join(rcdir, f)
-                    for f, kind in osutil.listdir(rcdir)
-                    if f.endswith(".rc")])
-    except OSError:
-        pass
-    return rcs
-
-def system_rcpath():
-    path = []
-    # old mod_python does not set sys.argv
-    if len(getattr(sys, 'argv', [])) > 0:
-        path.extend(rcfiles(os.path.dirname(sys.argv[0]) +
-                              '/../etc/mercurial'))
-    path.extend(rcfiles('/etc/mercurial'))
-    return path
-
-def user_rcpath():
-    return [os.path.expanduser('~/.hgrc')]
-
 def parse_patch_output(output_line):
     """parses the output produced by patch and returns the filename"""
     pf = output_line[14:]
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -298,8 +298,8 @@
 
 def os_rcpath():
     '''return default os-specific hgrc search path'''
-    path = util.system_rcpath()
-    path.extend(util.user_rcpath())
+    path = system_rcpath()
+    path.extend(user_rcpath())
     path = [os.path.normpath(f) for f in path]
     return path
 
@@ -328,3 +328,74 @@
         else:
             _rcpath = os_rcpath()
     return _rcpath
+
+if os.name != 'nt':
+
+    def rcfiles(path):
+        rcs = [os.path.join(path, 'hgrc')]
+        rcdir = os.path.join(path, 'hgrc.d')
+        try:
+            rcs.extend([os.path.join(rcdir, f)
+                        for f, kind in osutil.listdir(rcdir)
+                        if f.endswith(".rc")])
+        except OSError:
+            pass
+        return rcs
+
+    def system_rcpath():
+        path = []
+        # old mod_python does not set sys.argv
+        if len(getattr(sys, 'argv', [])) > 0:
+            path.extend(rcfiles(os.path.dirname(sys.argv[0]) +
+                                  '/../etc/mercurial'))
+        path.extend(rcfiles('/etc/mercurial'))
+        return path
+
+    def user_rcpath():
+        return [os.path.expanduser('~/.hgrc')]
+
+else:
+
+    _HKEY_LOCAL_MACHINE = 0x80000002L
+
+    def system_rcpath():
+        '''return default os-specific hgrc search path'''
+        rcpath = []
+        filename = util.executable_path()
+        # Use mercurial.ini found in directory with hg.exe
+        progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
+        if os.path.isfile(progrc):
+            rcpath.append(progrc)
+            return rcpath
+        # Use hgrc.d found in directory with hg.exe
+        progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
+        if os.path.isdir(progrcd):
+            for f, kind in osutil.listdir(progrcd):
+                if f.endswith('.rc'):
+                    rcpath.append(os.path.join(progrcd, f))
+            return rcpath
+        # else look for a system rcpath in the registry
+        value = util.lookup_reg('SOFTWARE\\Mercurial', None,
+                                _HKEY_LOCAL_MACHINE)
+        if not isinstance(value, str) or not value:
+            return rcpath
+        value = value.replace('/', os.sep)
+        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
+
+    def user_rcpath():
+        '''return os-specific hgrc search path to the user dir'''
+        home = os.path.expanduser('~')
+        path = [os.path.join(home, 'mercurial.ini'),
+                os.path.join(home, '.hgrc')]
+        userprofile = os.environ.get('USERPROFILE')
+        if userprofile:
+            path.append(os.path.join(userprofile, 'mercurial.ini'))
+            path.append(os.path.join(userprofile, '.hgrc'))
+        return path
diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -73,49 +73,6 @@
 def openhardlinks():
     return not _is_win_9x()
 
-_HKEY_LOCAL_MACHINE = 0x80000002L
-
-def system_rcpath():
-    '''return default os-specific hgrc search path'''
-    rcpath = []
-    filename = executable_path()
-    # Use mercurial.ini found in directory with hg.exe
-    progrc = os.path.join(os.path.dirname(filename), 'mercurial.ini')
-    if os.path.isfile(progrc):
-        rcpath.append(progrc)
-        return rcpath
-    # Use hgrc.d found in directory with hg.exe
-    progrcd = os.path.join(os.path.dirname(filename), 'hgrc.d')
-    if os.path.isdir(progrcd):
-        for f, kind in osutil.listdir(progrcd):
-            if f.endswith('.rc'):
-                rcpath.append(os.path.join(progrcd, f))
-        return rcpath
-    # else look for a system rcpath in the registry
-    value = lookup_reg('SOFTWARE\\Mercurial', None, _HKEY_LOCAL_MACHINE)
-    if not isinstance(value, str) or not value:
-        return rcpath
-    value = value.replace('/', os.sep)
-    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
-
-def user_rcpath():
-    '''return os-specific hgrc search path to the user dir'''
-    home = os.path.expanduser('~')
-    path = [os.path.join(home, 'mercurial.ini'),
-            os.path.join(home, '.hgrc')]
-    userprofile = os.environ.get('USERPROFILE')
-    if userprofile:
-        path.append(os.path.join(userprofile, 'mercurial.ini'))
-        path.append(os.path.join(userprofile, '.hgrc'))
-    return path
-
 def parse_patch_output(output_line):
     """parses the output produced by patch and returns the filename"""
     pf = output_line[14:]


More information about the Mercurial-devel mailing list