diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -100,7 +100,7 @@ class dirstate(object): files = [self._join('.hgignore')] for name, path in self._ui.configitems("ui"): if name == 'ignore' or name.startswith('ignore.'): - files.append(os.path.expanduser(path)) + files.append(util.expandpath(path)) return ignore.ignore(self._root, files, self._ui.warn) @propertycache diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -248,7 +248,7 @@ def _parse(ui, args): args = aliasargs(i[0]) + args defaults = ui.config("defaults", cmd) if defaults: - args = shlex.split(defaults) + args + args = map(util.expandpath, shlex.split(defaults)) + args c = list(i[1]) else: cmd = None @@ -477,8 +477,7 @@ def _runcommand(ui, options, cmd, cmdfun output = ui.config('profiling', 'output') if output: - path = os.path.expanduser(output) - path = ui.expandpath(path) + path = ui.expandpath(output) ostream = open(path, 'wb') else: ostream = sys.stderr diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -30,7 +30,7 @@ def find(name): def loadpath(path, module_name): module_name = module_name.replace('.', '_') - path = os.path.expanduser(path) + path = util.expandpath(path) if os.path.isdir(path): # module/__init__.py style d, f = os.path.split(path.rstrip('/')) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -198,10 +198,12 @@ class ui(object): def _path(self, loc): p = self.config('paths', loc) - if p and '%%' in p: - self.warn("(deprecated '%%' in path %s=%s from %s)\n" % - (loc, p, self.configsource('paths', loc))) - p = p.replace('%%', '%') + if p: + if '%%' in p: + self.warn("(deprecated '%%' in path %s=%s from %s)\n" % + (loc, p, self.configsource('paths', loc))) + p = p.replace('%%', '%') + p = util.expandpath(p) return p def expandpath(self, loc, default=None): diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1158,6 +1158,7 @@ def rcpath(): _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'): @@ -1250,3 +1251,6 @@ def iterlines(iterator): for chunk in iterator: for line in chunk.splitlines(): yield line + +def expandpath(path): + return os.path.expanduser(os.path.expandvars(path))