# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1285776266 -7200 # Node ID cb32d90f915e700cfbf035dff3e322e03154071d # Parent 1f1a3a6730c193e7c23dda6d7c58a6d621138ecd templatekw: clean up implementation & test; add help. The core logic is cleaned up and moved to the wrappers module. The test made to test that it works with original Mercurial changesets, is cleaned up so that it can be more easily extended in the future. Finally, documentation is added for the feature. diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -139,32 +139,8 @@ def uisetup(ui): else: help.helptable = help.helptable + entries - -def _get_svnmeta(ctx): - """Returns a dictionary with parsed convert_revision or None.""" - unparsed = ctx.extra().get('convert_revision', '') - if unparsed.startswith('svn:'): - unparsed = unparsed[4:] # remove "svn:" - return {'svnuuid': unparsed[:36], - 'svnpath': unparsed[36:].rsplit('@', 1)[0], - 'svnrev': unparsed[36:].rsplit('@', 1)[-1]} - return None - - -def _show_tpl_kw(ctx, kw): - convinfo = _get_svnmeta(ctx) - if convinfo is None: - return '' - return convinfo.get(kw, '') - - -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'), - }) - + if templatekw: + templatekw.keywords.update(util.templatekeywords) def reposetup(ui, repo): if repo.local(): diff --git a/hgsubversion/help/subversion.rst b/hgsubversion/help/subversion.rst --- a/hgsubversion/help/subversion.rst +++ b/hgsubversion/help/subversion.rst @@ -56,6 +56,18 @@ option with the HEAD argument causes the latest revision; later pulls will convert all revisions following the first. Please note that this only works for single-directory clones. +Displaying Subversion revisions +------------------------------------------- + +For revealing the relationship between Mercurial changesets and Subversion +revisions, hgsubversion provides three keywords, available when using Mercurial +1.5 or later. The "svnrev" keyword is expanded to the original Subversion +revision number. "svnpath" is the path within the repository that the changeset +represents, and "svnuuid" is the Universally Unique Identifier of the Subversion +repository. An example:: + + $ hg log --template='{rev}:{node|short} {author|user}\nsvn: {svnrev}\n' + Support for externals ----------------------------- diff --git a/hgsubversion/util.py b/hgsubversion/util.py --- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -174,3 +174,27 @@ def issamefile(parentctx, childctx, f): return False # parentctx is not an ancestor of childctx, files are unrelated return False + +def _templatehelper(ctx, kw): + ''' + Helper function for displaying information about converted changesets. + ''' + convertinfo = ctx.extra().get('convert_revision', '') + + if not convertinfo or not convertinfo.startswith('svn:'): + return '' + + if kw == 'svnuuid': + return convertinfo[4:40] + elif kw == 'svnpath': + return convertinfo[40:].rsplit('@', 1)[0] + elif kw == 'svnrev': + return convertinfo[40:].rsplit('@', 1)[-1] + else: + raise hgutil.Abort('unrecognized hgsubversion keyword %s' % kw) + +templatekeywords = { + 'svnrev': (lambda repo, ctx, templ, **a: _templatehelper(ctx, 'svnrev')), + 'svnpath': (lambda repo, ctx, templ, **a: _templatehelper(ctx, 'svnpath')), + 'svnuuid': (lambda repo, ctx, templ, **a: _templatehelper(ctx, 'svnuuid')), +} 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 @@ -20,28 +20,29 @@ class CapturingUI(ui.ui): def write(self, msg, *args, **kwds): self._output += msg -if templatekw: - class TestLogKeywords(test_util.TestBase): - +class TestLogKeywords(test_util.TestBase): + if templatekw: def test_svn_keywords(self): defaults = {'date': None, 'rev': None, 'user': None} repo = self._load_fixture_and_fetch('two_revs.svndump') + + # we want one commit that isn't from Subversion + self.commitchanges([('foo', 'foo', 'frobnicate\n')]) + ui = CapturingUI() commands.log(ui, repo, template='{rev}:{svnrev} ', **defaults) - self.assertEqual(ui._output, '0:2 1:3 ') + self.assertEqual(ui._output, '0:2 1:3 2: ') ui = CapturingUI() commands.log(ui, repo, template='{rev}:{svnpath} ', **defaults) - self.assertEqual(ui._output, '0:/trunk 1:/trunk ') + self.assertEqual(ui._output, '0:/trunk 1:/trunk 2: ') 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 ')) + '1:df2126f7-00ab-4d49-b42c-7e981dde0bcf ' + '2: ')) - def suite(): - all = [unittest.TestLoader().loadTestsFromTestCase(TestLogKeywords),] - return unittest.TestSuite(all) -else: - def suite(): - return unittest.TestSuite([]) +def suite(): + all = [unittest.TestLoader().loadTestsFromTestCase(TestLogKeywords),] + return unittest.TestSuite(all)