[PATCH] keyword: simplify record switch in kwtemplater.overwrite

Christian Ebert blacktrash at gmx.net
Sat May 1 17:00:45 CDT 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1272751179 -7200
# Node ID 02b5d29cf48f7236a28bfc265e3ea6af497a56eb
# Parent  4263d8998daa8dc73b8f1f53d605b80cf34bba8c
keyword: simplify record switch in kwtemplater.overwrite

1) use kwtemplater.record attribute for clarity
2) drop optional context argument; consider the speed loss by
   duplicating the dictionary lookup repo['.'] as negligible

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -160,12 +160,9 @@
         Caveat: localrepository._link fails on Windows.'''
         return self.match(path) and not 'l' in flagfunc(path)
 
-    def overwrite(self, node, expand, candidates, recctx=None):
+    def overwrite(self, node, expand, candidates):
         '''Overwrites selected files expanding/shrinking keywords.'''
-        if recctx is None:
-            ctx = self.repo[node]
-        else:
-            ctx = recctx
+        ctx = self.repo[node]
         mf = ctx.manifest()
         if node is not None:     # commit, record
             candidates = [f for f in ctx.files() if f in mf]
@@ -175,7 +172,7 @@
             msg = (expand and _('overwriting %s expanding keywords\n')
                    or _('overwriting %s shrinking keywords\n'))
             for f in candidates:
-                if recctx is None:
+                if not self.record:
                     data = self.repo.file(f).read(mf[f])
                 else:
                     data = self.repo.wread(f)
@@ -507,7 +504,7 @@
             ret = orig(ui, repo, commitfunc, *pats, **opts)
             recctx = repo['.']
             if ctx != recctx:
-                kwt.overwrite('.',  True, None, recctx)
+                kwt.overwrite('.',  True, None)
             return ret
         finally:
             wlock.release()


More information about the Mercurial-devel mailing list