# HG changeset patch # User Augie Fackler # Date 1283810891 18000 # Node ID d424bd1ac647f3cf0fa1e37ad6182837ad2fde7c # Parent 0c67d97f54beecc18deec5d1d25ec885d9d6bd49 templatekw: restore compatibility with hg < 1.5 The templatekw module was new in 1.5 - it looks nontrivial to extend the templater in 1.4.x and earlier, so just disable this feature on those versions. diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -23,7 +23,6 @@ from mercurial import commands from mercurial import extensions from mercurial import help from mercurial import hg -from mercurial import templatekw from mercurial import util as hgutil from mercurial import demandimport demandimport.ignore.extend([ @@ -34,6 +33,13 @@ demandimport.ignore.extend([ 'svn.ra', ]) +try: + from mercurial import templatekw + # force demandimport to load templatekw + templatekw.keywords +except ImportError: + templatekw = None + import svncommands import util import svnrepo @@ -152,11 +158,12 @@ def _show_tpl_kw(ctx, kw): return convinfo.get(kw, '') -templatekw.keywords.update({ - 'svnrev': lambda repo, ctx, templ, **a: _show_tpl_kw(ctx, 'svnrev'), - 'svnpath': lambda repo, ctx, templ, **a: _show_tpl_kw(ctx, 'svnpath'), - 'svnuuid': lambda repo, ctx, templ, **a: _show_tpl_kw(ctx, 'svnuuid'), - }) +if templatekw: + templatekw.keywords.update({ + 'svnrev': lambda repo, ctx, templ, **a: _show_tpl_kw(ctx, 'svnrev'), + 'svnpath': lambda repo, ctx, templ, **a: _show_tpl_kw(ctx, 'svnpath'), + 'svnuuid': lambda repo, ctx, templ, **a: _show_tpl_kw(ctx, 'svnuuid'), + }) def reposetup(ui, repo): diff --git a/tests/test_template_keywords.py b/tests/test_template_keywords.py --- a/tests/test_template_keywords.py +++ b/tests/test_template_keywords.py @@ -4,6 +4,11 @@ import unittest from mercurial import commands from mercurial import ui +try: + from mercurial import templatekw + templatekw.keywords +except ImportError: + templatekw = None class CapturingUI(ui.ui): @@ -15,25 +20,28 @@ class CapturingUI(ui.ui): def write(self, msg, *args, **kwds): self._output += msg - -class TestLogKeywords(test_util.TestBase): - - def test_svn_keywords(self): - defaults = {'date': None, 'rev': None, 'user': None} - repo = self._load_fixture_and_fetch('two_revs.svndump') - ui = CapturingUI() - commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults) - self.assertEqual(ui._output, '0:2 1:3 ') - ui = CapturingUI() - commands.log(ui, repo, template='{rev}:{svnpath} ', **defaults) - self.assertEqual(ui._output, '0:/trunk 1:/trunk ') - ui = CapturingUI() - commands.log(ui, repo, template='{rev}:{svnuuid} ', **defaults) - self.assertEqual(ui._output, - ('0:df2126f7-00ab-4d49-b42c-7e981dde0bcf ' - '1:df2126f7-00ab-4d49-b42c-7e981dde0bcf ')) - - -def suite(): - all = [unittest.TestLoader().loadTestsFromTestCase(TestLogKeywords),] - return unittest.TestSuite(all) +if templatekw: + class TestLogKeywords(test_util.TestBase): + + def test_svn_keywords(self): + defaults = {'date': None, 'rev': None, 'user': None} + repo = self._load_fixture_and_fetch('two_revs.svndump') + ui = CapturingUI() + commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults) + self.assertEqual(ui._output, '0:2 1:3 ') + ui = CapturingUI() + commands.log(ui, repo, template='{rev}:{svnpath} ', **defaults) + self.assertEqual(ui._output, '0:/trunk 1:/trunk ') + ui = CapturingUI() + commands.log(ui, repo, template='{rev}:{svnuuid} ', **defaults) + self.assertEqual(ui._output, + ('0:df2126f7-00ab-4d49-b42c-7e981dde0bcf ' + '1:df2126f7-00ab-4d49-b42c-7e981dde0bcf ')) + + + def suite(): + all = [unittest.TestLoader().loadTestsFromTestCase(TestLogKeywords),] + return unittest.TestSuite(all) +else: + def suite(): + return unittest.TestSuite([])