keyword: restore kwtemplater.match at the end of wrapped webcommands
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 26 Jun 2017 03:40:06 +0900
changeset 33064 9062458febca
parent 33063 7f569ce30216
child 33065 0afdc1a4f925
keyword: restore kwtemplater.match at the end of wrapped webcommands Before this patch, kwweb_skip doesn't restore kwtemplater.match after wrapped webcommands. This suppresses keyword expansion at wrapped webcommands. Typical usecase of this issue is "file" webcommand after annotate, changeset, filediff or so on. To ensure kwtemplater.match=util.never while original webcommand running, this patch makes kwweb_skip yield values returned by it, because it returns generator object.
hgext/keyword.py
tests/test-keyword.t
--- a/hgext/keyword.py	Mon Jun 26 03:38:12 2017 +0900
+++ b/hgext/keyword.py	Mon Jun 26 03:40:06 2017 +0900
@@ -675,8 +675,13 @@
 
     def kwweb_skip(orig, web, req, tmpl):
         '''Wraps webcommands.x turning off keyword expansion.'''
+        origmatch = kwt.match
         kwt.match = util.never
-        return orig(web, req, tmpl)
+        try:
+            for chunk in orig(web, req, tmpl):
+                yield chunk
+        finally:
+            kwt.match = origmatch
 
     def kw_amend(orig, ui, repo, commitfunc, old, extra, pats, opts):
         '''Wraps cmdutil.amend expanding keywords after amend.'''
--- a/tests/test-keyword.t	Mon Jun 26 03:38:12 2017 +0900
+++ b/tests/test-keyword.t	Mon Jun 26 03:40:06 2017 +0900
@@ -1019,6 +1019,7 @@
 hg serve
  - expand with hgweb file
  - no expansion with hgweb annotate/changeset/filediff
+ - expand with hgweb file, again
  - check errors
 
   $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
@@ -1078,6 +1079,18 @@
   
   
   
+
+(check "kwweb_skip"-ed webcommand doesn't suppress expanding keywords
+at subsequent webcommands)
+
+  $ get-with-headers.py localhost:$HGPORT 'file/tip/a/?style=raw'
+  200 Script output follows
+  
+  expand $Id: a bb948857c743 Thu, 01 Jan 1970 00:00:02 +0000 user $
+  do not process $Id:
+  xxx $
+  $Xinfo: User Name <user@example.com>: firstline $
+
   $ cat errors.log
 #endif