[PATCH] keyword: pass context to kwtemplater.overwrite

Christian Ebert blacktrash at gmx.net
Mon Jun 7 18:40:36 CDT 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1275954002 -3600
# Node ID 6e94857052f709d104fe967d270376705ad9ae92
# Parent  3d0591a661189bcb0a5e8ef3393c59ecd7e42f79
keyword: pass context to kwtemplater.overwrite

Now that we have retrieved the context in every calling function
except commit, pass it as argument to kwtemplater.overwrite to
avoid looking it up twice.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -189,9 +189,8 @@
         Caveat: localrepository._link fails on Windows.'''
         return self.match(path) and not 'l' in flagfunc(path)
 
-    def overwrite(self, node, expand, candidates):
+    def overwrite(self, node, ctx, expand, candidates):
         '''Overwrites selected files expanding/shrinking keywords.'''
-        ctx = self.repo[node]
         mf = ctx.manifest()
         if self.record:
             candidates = [f for f in ctx.files() if f in mf]
@@ -286,7 +285,8 @@
 
 def _kwfwrite(ui, repo, expand, *pats, **opts):
     '''Selects files and passes them to kwtemplater.overwrite.'''
-    if len(repo[None].parents()) > 1:
+    wctx = repo[None]
+    if len(wctx.parents()) > 1:
         raise util.Abort(_('outstanding uncommitted merge'))
     kwt = kwtools['templater']
     wlock = repo.wlock()
@@ -295,7 +295,7 @@
         modified, added, removed, deleted, unknown, ignored, clean = status
         if modified or added or removed or deleted:
             raise util.Abort(_('outstanding uncommitted changes'))
-        kwt.overwrite(None, expand, clean)
+        kwt.overwrite(None, wctx, expand, clean)
     finally:
         wlock.release()
 
@@ -498,7 +498,8 @@
             n = super(kwrepo, self).commitctx(ctx, error)
             # no lock needed, only called from repo.commit() which already locks
             if not kwt.record:
-                kwt.overwrite(n, True, sorted(ctx.added() + ctx.modified()))
+                kwt.overwrite(n, self[n], True,
+                              sorted(ctx.added() + ctx.modified()))
             return n
 
     # monkeypatches
@@ -533,8 +534,9 @@
             # therefore compare nodes before and after
             ctx = repo['.']
             ret = orig(ui, repo, commitfunc, *pats, **opts)
-            if ctx != repo['.']:
-                kwt.overwrite('.',  True, None)
+            recordctx = repo['.']
+            if ctx != recordctx:
+                kwt.overwrite('.', recordctx,  True, None)
             return ret
         finally:
             wlock.release()


More information about the Mercurial-devel mailing list