Patchwork [2,of,2] chgserver: remove _clearenvaliases

login
register
mail settings
Submitter Jun Wu
Date May 6, 2016, 11:22 p.m.
Message ID <83928625fb4d89dd067b.1462576969@x1c>
Download mbox | patch
Permalink /patch/14957/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - May 6, 2016, 11:22 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1462575476 -3600
#      Fri May 06 23:57:56 2016 +0100
# Node ID 83928625fb4d89dd067b1b0ca5b39113f17ea4ba
# Parent  24dc9e5deec415bfa635fb80c7767ef5146c2775
chgserver: remove _clearenvaliases

Since we expand environment variables in alias lazily, the _clearenvaliases
hack is no longer necessary.

This resolves an issue that a non-shell alias which has environment variables
in its arguments and is set to use pager will not use pager running with chg.
Sean Farley - May 7, 2016, 12:51 a.m.
Jun Wu <quark@fb.com> writes:

> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1462575476 -3600
> #      Fri May 06 23:57:56 2016 +0100
> # Node ID 83928625fb4d89dd067b1b0ca5b39113f17ea4ba
> # Parent  24dc9e5deec415bfa635fb80c7767ef5146c2775
> chgserver: remove _clearenvaliases
>
> Since we expand environment variables in alias lazily, the _clearenvaliases
> hack is no longer necessary.
>
> This resolves an issue that a non-shell alias which has environment variables
> in its arguments and is set to use pager will not use pager running with chg.

These look good to me but I'd like Yuya to take a look as well.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -213,18 +213,6 @@ 
         ui.setconfig('ui', 'interactive', False, 'pager')
         return p
 
-_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('!') and  # shell alias
-            _envvarre.search(cmddef.definition)):
-            del cmdtable[name]
-
 def _newchgui(srcui, csystem):
     class chgui(srcui.__class__):
         def __init__(self, src=None):
@@ -525,7 +513,6 @@ 
         _log('setenv: %r\n' % sorted(newenv.keys()))
         os.environ.clear()
         os.environ.update(newenv)
-        _clearenvaliases(commands.table)
 
     capabilities = commandserver.server.capabilities.copy()
     capabilities.update({'attachio': attachio,
diff --git a/tests/test-chg.t b/tests/test-chg.t
--- a/tests/test-chg.t
+++ b/tests/test-chg.t
@@ -10,3 +10,23 @@ 
   $ hg status
   hg: parse error at * (glob)
   [255]
+
+alias having an environment variable and set to use pager
+
+  $ rm $HGRCPATH
+  $ cat >> $HGRCPATH <<'EOF'
+  > [ui]
+  > formatted = yes
+  > [extensions]
+  > pager =
+  > [pager]
+  > pager = sed -e 's/^/P/'
+  > attend = printa
+  > [alias]
+  > printa = log -T "$A\n" -r 0
+  > EOF
+
+  $ A=1 hg printa
+  P1
+  $ A=2 hg printa
+  P2