hgkw/keyword.py
branchkwmap-templates
changeset 138 bf8622c50309
parent 137 bfea48fbcb88
child 139 0ea07bb56ff6
--- a/hgkw/keyword.py	Fri Feb 09 18:43:15 2007 +0100
+++ b/hgkw/keyword.py	Sun Feb 11 19:51:22 2007 +0100
@@ -138,18 +138,27 @@
             return data
         return self.re_kw.sub(lambda m: self.kwsub(m, path, node), data)
 
-    def expandn(self, path, node, data):
-        '''Returns data with expanded keywords and number of expansions.'''
-        if util.binary(data):
-            return data, None
-        return self.re_kw.subn(lambda m: self.kwsub(m, path, node), data)
-
     def shrink(self, text):
         '''Returns text with all keyword substitutions removed.'''
         if util.binary(text):
             return text
         return self.re_kw.sub(r'$\1$', text)
 
+    def overwrite(self, candidates, node):
+        '''Overwrites candidates in working dir expanding keywords.'''
+        files = []
+        for f in candidates:
+            data = self.repo.wfile(f).read()
+            if not util.binary(data):
+                data, kwct = self.re_kw.subn(lambda m:
+                        self.kwsub(m, f, node), data)
+                if kwct:
+                    self.ui.debug(_('overwriting %s expanding keywords\n') % f)
+                    self.repo.wfile(f, 'w').write(data)
+                    files.append(f)
+        if files:
+            self.repo.dirstate.update(files, 'n')
+
 
 def reposetup(ui, repo):
     '''Sets up repo, and filelog especially, as kwrepo and kwfilelog
@@ -185,7 +194,6 @@
                     text=text, user=user, date=date,
                     match=match, force=force, lock=lock, wlock=wlock,
                     force_editor=force_editor, p1=p1, p2=p2, extra=extra)
-
             if node is None:
                 return node
 
@@ -196,16 +204,7 @@
                 return node
 
             kwt = kwtemplater(self.ui, self)
-            overwrite = []
-            for f in candidates:
-                data = self.wfile(f).read()
-                data, kwct = kwt.expandn(f, node, data)
-                if kwct:
-                    ui.debug(_('overwriting %s expanding keywords\n' % f))
-                    self.wfile(f, 'w').write(data)
-                    overwrite.append(f)
-            if overwrite:
-                self.dirstate.update(overwrite, 'n')
+            kwt.overwrite(candidates, node)
             return node
 
     class kwfilelog(filelog.filelog):