hgkw/keyword.py
branch0.9.2compat
changeset 348 63ebc698d06b
parent 343 f5927e5574e6
child 350 83aa851f0d84
child 379 290d023e8306
--- a/hgkw/keyword.py	Sat Jan 19 18:26:17 2008 +0100
+++ b/hgkw/keyword.py	Wed Jan 23 11:38:22 2008 +0100
@@ -189,17 +189,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', 
-                   'qimport', 'qnew', 'qpush', 'qrefresh', 'record', 'qrecord')
-
 
 _kwtemplater = None
 
@@ -269,7 +267,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)
 
@@ -340,7 +338,7 @@
     mf = ctx.manifest()
     if node is not None:   # commit
         _kwtemplater.commitnode = node
-        files = [f for f in ctx.files() if mf.has_key(f)]
+        files = [f for f in ctx.files() if f in mf]
         notify = ui.debug
     else:                  # kwexpand/kwshrink
         notify = ui.note
@@ -409,7 +407,7 @@
         kwmaps = kwtemplater.templates
         if ui.configitems('keywordmaps'):
             # override maps from optional rcfile
-            for k, v in kwmaps.items():
+            for k, v in kwmaps.iteritems():
                 ui.setconfig('keywordmaps', k, v)
     elif args:
         # simulate hgrc parsing
@@ -428,7 +426,7 @@
     demostatus('config using %s keyword template maps' % kwstatus)
     ui.write('[extensions]\n%s\n' % extension)
     demoitems('keyword', ui.configitems('keyword'))
-    demoitems('keywordmaps', kwmaps.items())
+    demoitems('keywordmaps', kwmaps.iteritems())
     keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n'
     repo.wopener(fn, 'w').write(keywords)
     repo.add([fn])
@@ -552,7 +550,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
 
@@ -589,10 +587,10 @@
                 if not _lock:
                     _lock = self.lock()
                 # store and postpone commit hooks
-                commithooks = []
+                commithooks = {}
                 for name, cmd in ui.configitems('hooks'):
                     if name.split('.', 1)[0] == 'commit':
-                        commithooks.append((name, cmd))
+                        commithooks[name] = cmd
                         ui.setconfig('hooks', name, '')
                 if commithooks:
                     # store parents for commit hook environment
@@ -610,7 +608,7 @@
                                     _lock, _wlock, force_editor, p1, p2, extra)
 
                 # restore commit hooks
-                for name, cmd in commithooks:
+                for name, cmd in commithooks.iteritems():
                     ui.setconfig('hooks', name, cmd)
                 if node is not None:
                     _overwrite(ui, self, node=node)