# HG changeset patch # User Adrian Buehlmann # Date 1303413414 -7200 # Node ID 9c374cf76b7de03f1b590bf51ff0e865a1a58a32 # Parent 26335a817dd07dece5e299f290c9cc2ab2027402 move system_rcpath and user_rcpath to scmutil diff -r 26335a817dd0 -r 9c374cf76b7d mercurial/posix.py --- a/mercurial/posix.py Thu Apr 21 20:54:45 2011 +0200 +++ b/mercurial/posix.py Thu Apr 21 21:16:54 2011 +0200 @@ -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 -r 26335a817dd0 -r 9c374cf76b7d mercurial/scmutil.py --- a/mercurial/scmutil.py Thu Apr 21 20:54:45 2011 +0200 +++ b/mercurial/scmutil.py Thu Apr 21 21:16:54 2011 +0200 @@ -7,7 +7,7 @@ from i18n import _ import util, error, osutil -import os, errno, stat +import os, errno, stat, sys def checkfilename(f): '''Check that the filename f is an acceptable filename for a tracked file''' @@ -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 -r 26335a817dd0 -r 9c374cf76b7d mercurial/windows.py --- a/mercurial/windows.py Thu Apr 21 20:54:45 2011 +0200 +++ b/mercurial/windows.py Thu Apr 21 21:16:54 2011 +0200 @@ -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:]