# HG changeset patch # User FUJIWARA Katsunori # Date 2017-06-25 18:38:12 # Node ID 7f569ce3021659eb66428978c1892c974f5c9789 # Parent e21b750c9b9efa96517e74c7fc045350c02dc466 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. diff --git a/hgext/keyword.py b/hgext/keyword.py --- a/hgext/keyword.py +++ b/hgext/keyword.py @@ -665,8 +665,13 @@ def reposetup(ui, repo): 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.''' diff --git a/tests/test-keyword.t b/tests/test-keyword.t --- a/tests/test-keyword.t +++ b/tests/test-keyword.t @@ -1378,4 +1378,35 @@ Test restricted mode with fetch (with me $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 ..