# HG changeset patch
# User FUJIWARA Katsunori <fo...@lares.dti.ne.jp>
# Date 1498416006 -32400
#      Mon Jun 26 03:40:06 2017 +0900
# Node ID 0d030855f6427dcb13e0deefe84de6181b692a29
# Parent  d03c6351573ad632e4f54aa269c7487e8f185b8a
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.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -675,8 +675,13 @@ def reposetup(ui, repo):
 
     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.'''
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -1019,6 +1019,7 @@ kwexpand nonexistent
 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 @@ hg serve
   
   
   
+
+(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 <u...@example.com>: firstline $
+
   $ cat errors.log
 #endif
 
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to