Yuya Nishihara committed 2ca9e1a

hgext: recreate stale command aliases referencing env vars on each request

Sadly variable expansion of cmdalias is done at initial boot.

  • Participants
  • Parent commits 60c91cf

Comments (0)

Files changed (2)

File hgext/

 causes unexpected behavior.
-import errno, gc, itertools, os, signal, socket, struct, tempfile
+import errno, gc, itertools, os, re, signal, socket, struct, tempfile
 from mercurial import cmdutil, commands, commandserver, dispatch, encoding, \
                       error, extensions, i18n, scmutil, util
 from mercurial.i18n import _
         if newdef is not None:
             commands.globalopts[i] = opt[:2] + (newdef,) + opt[3:]
+_envvarre = re.compile(r'\$[a-zA-Z_]+')
+def _clearenvaliases(cmdtable):
+    """Remove stale command aliases referencing env vars; variable expansion
+    is done at dispatch.addaliases()"""
+    for name, tab in cmdtable.items():
+        cmddef = tab[0]
+        if (isinstance(cmddef, dispatch.cmdalias)
+            and not cmddef.definition.startswith('!')  # shell alias
+            and
+            del cmdtable[name]
 class chgcmdserver(commandserver.server):
     def __init__(self, sui, ui, repo, fin, fout, masterpid):
         super(chgcmdserver, self).__init__(ui, repo, mode='pipe')
         if encoding in modstoreload:
+        _clearenvaliases(commands.table)
     capabilities = commandserver.server.capabilities.copy()
     capabilities.update({'chdir': chdir,
                          'getpager': getpager,

File tests/

 # switch background server by environment variables (SHOULD BE FIXED LATER)
 _defaultenvsuminclude = []
 _envsuminclude = {
-    'test-alias.t': _defaultenvsuminclude + ['FOO'],
     'test-convert-svn-branches.t': _defaultenvsuminclude + ['HG'],
     'test-hook.t': _defaultenvsuminclude + ['PYTHONPATH'],