Standalone compatibility fixes: demandload, changeset_templater kwmap-templates
authorChristian Ebert <blacktrash@gmx.net>
Fri, 09 Feb 2007 16:13:51 +0100
branchkwmap-templates
changeset 135 a4c748fc7e00
parent 134 f869c65156f7
child 136 5e9d6c57d679
Standalone compatibility fixes: demandload, changeset_templater If demandload is present, use it, and import gettext. changeset_templater may have extra arg for branches.
hgkw/keyword.py
--- a/hgkw/keyword.py	Fri Feb 09 14:43:01 2007 +0100
+++ b/hgkw/keyword.py	Fri Feb 09 16:13:51 2007 +0100
@@ -71,11 +71,17 @@
 hgrc files.
 '''
 
-from mercurial.i18n import gettext as _
-# above line for backwards compatibility of standalone version
-from mercurial import cmdutil, templater, util
-from mercurial import context, filelog, revlog
-import os.path, re, time
+try:
+    from mercurial.demandload import * # stable
+    from mercurial.i18n import gettext as _
+    demandload(globals(), 'mercurial:cmdutil,templater,util')
+    demandload(globals(), 'mercurial:context,filelog,revlog')
+    demandload(globals(), 'os.path re time')
+except ImportError: # demandimport
+    from mercurial.i18n import _
+    from mercurial import cmdutil, templater, util
+    from mercurial import context, filelog, revlog
+    import os.path, re, time
 
 deftemplates = {
         'Revision': '{node|short}',
@@ -103,7 +109,13 @@
         self.re_kw = re.compile(r'\$(%s)[^$]*?\$' %
                 '|'.join(re.escape(k) for k in self.templates.keys()))
         templater.common_filters['utcdate'] = utcdate
-        self.t = cmdutil.changeset_templater(ui, repo, False, '', False)
+        try:
+            self.t = cmdutil.changeset_templater(ui, repo,
+                    False, '', False)
+        except TypeError:
+            # depending on hg rev changeset_templater has extra "brinfo" arg
+            self.t = cmdutil.changeset_templater(ui, repo,
+                    False, None, '', False)
 
     def kwsub(self, mobj, path, node):
         '''Substitutes keyword using corresponding template.'''