changeset 33063:7f569ce30216

keyword: restore kwtemplater.restrict at the end of wrapped patch.diff Before this patch, kwdiff doesn't restore kwtemplater.restrict after invocation of wrapped patch.diff(). This suppresses keyword expansion at subsequent filelog.read(). Typical usecase of this issue is "hg cat" after "hg diff" with command server. In this case, kwtemplater.restrict=True is kept in command server process even after "hg diff". To ensure kwtemplater.restrict=True while original patch.diff() running, this patch makes kwdiff() yield values returned by it, because it returns generator object. Strictly speaking, if filelog.read() is invoked before completely evaluating the result of previous patch.diff(), keyword expansion is still suppressed, because kwtemplater.restrict isn't restored yet. But this fixing should be reasonable enough, because patch.diff() is consumed immediately, AFAIK.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 26 Jun 2017 03:38:12 +0900
parents e21b750c9b9e
children 9062458febca
files hgext/keyword.py tests/test-keyword.t
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/keyword.py	Mon Jun 26 22:27:34 2017 +0900
+++ b/hgext/keyword.py	Mon Jun 26 03:38:12 2017 +0900
@@ -665,8 +665,13 @@
 
     def kwdiff(orig, *args, **kwargs):
         '''Monkeypatch patch.diff to avoid expansion.'''
+        restrict = kwt.restrict
         kwt.restrict = True
-        return orig(*args, **kwargs)
+        try:
+            for chunk in orig(*args, **kwargs):
+                yield chunk
+        finally:
+            kwt.restrict = restrict
 
     def kwweb_skip(orig, web, req, tmpl):
         '''Wraps webcommands.x turning off keyword expansion.'''
--- a/tests/test-keyword.t	Mon Jun 26 22:27:34 2017 +0900
+++ b/tests/test-keyword.t	Mon Jun 26 03:38:12 2017 +0900
@@ -1378,4 +1378,35 @@
    $Xinfo$
   +xxxx
 
+Test that patch.diff(), which is implied by "hg diff" or so, doesn't
+suppress expanding keywords at subsequent commands
+
+#if windows
+  $ PYTHONPATH="$TESTDIR/../contrib;$PYTHONPATH"
+#else
+  $ PYTHONPATH="$TESTDIR/../contrib:$PYTHONPATH"
+#endif
+  $ export PYTHONPATH
+
+  $ grep -v '^promptecho ' < $HGRCPATH >> $HGRCPATH.new
+  $ mv $HGRCPATH.new $HGRCPATH
+
+  >>> from __future__ import print_function
+  >>> from hgclient import readchannel, runcommand, check
+  >>> @check
+  ... def check(server):
+  ...     # hello block
+  ...     readchannel(server)
+  ... 
+  ...     runcommand(server, ['cat', 'm'])
+  ...     runcommand(server, ['diff', '-c', '.', 'm'])
+  ...     runcommand(server, ['cat', 'm'])
+  *** runcommand cat m
+  $Id: m 800511b3a22d Thu, 01 Jan 1970 00:00:00 +0000 test $
+  bar
+  *** runcommand diff -c . m
+  *** runcommand cat m
+  $Id: m 800511b3a22d Thu, 01 Jan 1970 00:00:00 +0000 test $
+  bar
+
   $ cd ..