hgkw/keyword.py
changeset 347 c912b8c3f3ff
parent 346 2c2b49def9d8
child 349 c78c74451bac
child 363 263b3b10c55f
--- a/hgkw/keyword.py	Wed Jan 23 09:53:40 2008 +0100
+++ b/hgkw/keyword.py	Wed Jan 23 11:36:37 2008 +0100
@@ -88,17 +88,15 @@
 
 commands.optionalrepo += ' kwdemo'
 
+# hg commands that trigger expansion only when writing to working dir,
+# not when reading filelog, and unexpand when reading from working dir
+restricted = ('diff1', 'record',
+              'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
+
 def utcdate(date):
     '''Returns hgdate in cvs-like UTC format.'''
     return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
 
-def _kwrestrict(cmd):
-    '''Returns True if cmd should trigger restricted expansion.
-    Keywords will only expanded when writing to working dir.
-    Crucial for mq as expanded keywords should not make it into patches.'''
-    return cmd in ('diff1', 'record',
-                   'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
-
 
 _kwtemplater = None
 
@@ -159,7 +157,7 @@
 
     def expand(self, node, data):
         '''Returns data with keywords expanded.'''
-        if util.binary(data) or _kwrestrict(self.hgcmd):
+        if util.binary(data) or self.hgcmd in restricted:
             return data
         return self.substitute(node, data, self.re_kw.sub)
 
@@ -453,7 +451,7 @@
 
         def wread(self, filename):
             data = super(kwrepo, self).wread(filename)
-            if _kwrestrict(hgcmd) and _kwtemplater.matcher(filename):
+            if hgcmd in restricted and _kwtemplater.matcher(filename):
                 return _kwtemplater.shrink(data)
             return data