# HG changeset patch # User Adrian Buehlmann # Date 2011-04-21 18:14:29 # Node ID af60153b5e3b8b3af35b845b7922b405c5635b42 # Parent 144d64cf456e497d3110662420f5ea983c774f23 move rcpath from util to scmutil diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1199,7 +1199,7 @@ def showconfig(ui, repo, *values, **opts Returns 0 on success. """ - for f in util.rcpath(): + for f in scmutil.rcpath(): ui.debug(_('read config from: %s\n') % f) untrusted = bool(opts.get('untrusted')) if values: diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -6,7 +6,7 @@ # GNU General Public License version 2 or any later version. from i18n import _ -import util, error +import util, error, osutil import os, errno, stat def checkfilename(f): @@ -295,3 +295,29 @@ def walkrepos(path, followsym=False, see else: newdirs.append(d) dirs[:] = newdirs + +_rcpath = None + +def rcpath(): + '''return hgrc search path. if env var HGRCPATH is set, use it. + for each item in path, if directory, use files ending in .rc, + else use item. + make HGRCPATH empty to only look in .hg/hgrc of current repo. + if no HGRCPATH, use default os-specific path.''' + global _rcpath + if _rcpath is None: + if 'HGRCPATH' in os.environ: + _rcpath = [] + for p in os.environ['HGRCPATH'].split(os.pathsep): + if not p: + continue + p = util.expandpath(p) + if os.path.isdir(p): + for f, kind in osutil.listdir(p): + if f.endswith('.rc'): + _rcpath.append(os.path.join(p, f)) + else: + _rcpath.append(p) + else: + _rcpath = util.os_rcpath() + return _rcpath diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -7,7 +7,7 @@ from i18n import _ import errno, getpass, os, socket, sys, tempfile, traceback -import config, util, error, url +import config, scmutil, util, error, url class ui(object): def __init__(self, src=None): @@ -32,7 +32,7 @@ class ui(object): # shared read-only environment self.environ = os.environ # we always trust global config files - for f in util.rcpath(): + for f in scmutil.rcpath(): self.readconfig(f, trust=True) def copy(self): diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1083,8 +1083,6 @@ def ellipsis(text, maxlength=400): except (UnicodeDecodeError, UnicodeEncodeError): return _ellipsis(text, maxlength)[0] -_rcpath = None - def os_rcpath(): '''return default os-specific hgrc search path''' path = system_rcpath() @@ -1092,30 +1090,6 @@ def os_rcpath(): path = [os.path.normpath(f) for f in path] return path -def rcpath(): - '''return hgrc search path. if env var HGRCPATH is set, use it. - for each item in path, if directory, use files ending in .rc, - else use item. - make HGRCPATH empty to only look in .hg/hgrc of current repo. - if no HGRCPATH, use default os-specific path.''' - global _rcpath - if _rcpath is None: - if 'HGRCPATH' in os.environ: - _rcpath = [] - for p in os.environ['HGRCPATH'].split(os.pathsep): - if not p: - continue - p = expandpath(p) - if os.path.isdir(p): - for f, kind in osutil.listdir(p): - if f.endswith('.rc'): - _rcpath.append(os.path.join(p, f)) - else: - _rcpath.append(p) - else: - _rcpath = os_rcpath() - return _rcpath - def bytecount(nbytes): '''return byte count formatted as readable string, with units'''