keyword: obtain kwtemplater instance via repository at runtime
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 26 Jun 2017 03:44:50 +0900
changeset 33069 ed92a4960874
parent 33068 a15da610ea20
child 33070 735218be6122
keyword: obtain kwtemplater instance via repository at runtime Wrapper functions of keyword extension are defined in reposetup(), because they refer to kwtemplater instantiated in reposetup(). This patch makes them obtain kwtemplater instance via repository at runtime. For reviewability, this patch focuses on wrapper functions, which handle generator. This is a part of preparations for defining them statically.
hgext/keyword.py
--- a/hgext/keyword.py	Mon Jun 26 03:43:47 2017 +0900
+++ b/hgext/keyword.py	Mon Jun 26 03:44:50 2017 +0900
@@ -676,25 +676,31 @@
             # shrink keywords read from working dir
             self.lines = kwt.shrinklines(self.fname, self.lines)
 
-    def kwdiff(orig, *args, **kwargs):
+    def kwdiff(orig, repo, *args, **kwargs):
         '''Monkeypatch patch.diff to avoid expansion.'''
-        restrict = kwt.restrict
-        kwt.restrict = True
+        kwt = getattr(repo, '_keywordkwt', None)
+        if kwt:
+            restrict = kwt.restrict
+            kwt.restrict = True
         try:
-            for chunk in orig(*args, **kwargs):
+            for chunk in orig(repo, *args, **kwargs):
                 yield chunk
         finally:
-            kwt.restrict = restrict
+            if kwt:
+                kwt.restrict = restrict
 
     def kwweb_skip(orig, web, req, tmpl):
         '''Wraps webcommands.x turning off keyword expansion.'''
-        origmatch = kwt.match
-        kwt.match = util.never
+        kwt = getattr(web.repo, '_keywordkwt', None)
+        if kwt:
+            origmatch = kwt.match
+            kwt.match = util.never
         try:
             for chunk in orig(web, req, tmpl):
                 yield chunk
         finally:
-            kwt.match = origmatch
+            if kwt:
+                kwt.match = origmatch
 
     def kw_amend(orig, ui, repo, commitfunc, old, extra, pats, opts):
         '''Wraps cmdutil.amend expanding keywords after amend.'''