comparison hgext/keyword.py @ 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 69d1c3ea0d6f
children 9062458febca
comparison
equal deleted inserted replaced
33062:e21b750c9b9e 33063:7f569ce30216
663 # shrink keywords read from working dir 663 # shrink keywords read from working dir
664 self.lines = kwt.shrinklines(self.fname, self.lines) 664 self.lines = kwt.shrinklines(self.fname, self.lines)
665 665
666 def kwdiff(orig, *args, **kwargs): 666 def kwdiff(orig, *args, **kwargs):
667 '''Monkeypatch patch.diff to avoid expansion.''' 667 '''Monkeypatch patch.diff to avoid expansion.'''
668 restrict = kwt.restrict
668 kwt.restrict = True 669 kwt.restrict = True
669 return orig(*args, **kwargs) 670 try:
671 for chunk in orig(*args, **kwargs):
672 yield chunk
673 finally:
674 kwt.restrict = restrict
670 675
671 def kwweb_skip(orig, web, req, tmpl): 676 def kwweb_skip(orig, web, req, tmpl):
672 '''Wraps webcommands.x turning off keyword expansion.''' 677 '''Wraps webcommands.x turning off keyword expansion.'''
673 kwt.match = util.never 678 kwt.match = util.never
674 return orig(web, req, tmpl) 679 return orig(web, req, tmpl)