# HG changeset patch # User FUJIWARA Katsunori # Date 2017-06-25 18:44:50 # Node ID ed92a4960874a20191b2747ffcb3573bcba515c3 # Parent a15da610ea20e23c2b2852b120f8f7db0b4548a4 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. diff --git a/hgext/keyword.py b/hgext/keyword.py --- a/hgext/keyword.py +++ b/hgext/keyword.py @@ -676,25 +676,31 @@ def reposetup(ui, repo): # 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.'''