Commits

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.

Comments (0)

Files changed (2)

hgext/chgsupport.py

 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 _envvarre.search(cmddef.definition)):
+            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:
             _fixdefaultencoding()
 
+        _clearenvaliases(commands.table)
+
     capabilities = commandserver.server.capabilities.copy()
     capabilities.update({'chdir': chdir,
                          'getpager': getpager,

tests/run-hgtests.py

 # 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'],
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.