Rev 1793: Move legacy mappings into their own file. in file:///data/jelmer/bzr-svn/trunk/
Jelmer Vernooij
jelmer at samba.org
Thu Sep 4 07:14:54 BST 2008
At file:///data/jelmer/bzr-svn/trunk/
------------------------------------------------------------
revno: 1793
revision-id: jelmer at samba.org-20080904061453-jz1hel4ffhmsiexm
parent: jelmer at samba.org-20080904054951-x4zadoxztxin1wtf
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Thu 2008-09-04 08:14:53 +0200
message:
Move legacy mappings into their own file.
added:
mapping2.py mapping.py-20080904055555-lw057kjuadn0r2ma-2
tests/mapping_implementations/test_base.py test_base.py-20080904055908-3t0g1y0qnmr6aeiq-1
modified:
mapping.py mapping.py-20080128201303-6cp01phc0dmc0kiv-1
mapping3/__init__.py __init__.py-20080502174630-9324zh25kka98vlw-1
tests/__init__.py __init__.py-20060508151940-e9f4d914801a2535
tests/mapping_implementations/__init__.py __init__.py-20080902013845-ity7d1ymye69sobm-1
tests/test_mapping.py test_mapping.py-20080201131338-0zd86eznn4bojtee-1
=== modified file 'mapping.py'
--- a/mapping.py 2008-09-04 05:49:51 +0000
+++ b/mapping.py 2008-09-04 06:14:53 +0000
@@ -17,7 +17,6 @@
from bzrlib import osutils, registry
from bzrlib.errors import InvalidRevisionId
-from bzrlib.inventory import ROOT_ID
from bzrlib.revision import NULL_REVISION
from bzrlib.trace import mutter
@@ -29,7 +28,6 @@
SVN_PROP_BZR_PREFIX = 'bzr:'
SVN_PROP_BZR_ANCESTRY = 'bzr:ancestry:'
SVN_PROP_BZR_FILEIDS = 'bzr:file-ids'
-SVN_PROP_BZR_MERGE = 'bzr:merge'
SVN_PROP_BZR_REVISION_INFO = 'bzr:revision-info'
SVN_PROP_BZR_REVISION_ID = 'bzr:revision-id:'
SVN_PROP_BZR_TEXT_PARENTS = 'bzr:text-parents'
@@ -434,95 +432,9 @@
def get_revision_id(self, branch_path, revprops, fileprops):
raise NotImplementedError(self.get_revision_id)
-
-class BzrSvnMappingv1(BzrSvnMapping):
- """This was the initial version of the mappings as used by bzr-svn
- 0.2.
-
- It does not support pushing revisions to Subversion as-is, but only
- as part of a merge.
- """
- name = "v1"
-
- @classmethod
- def revision_id_bzr_to_foreign(cls, revid):
- if not revid.startswith("svn-v1:"):
- raise InvalidRevisionId(revid, "")
- revid = revid[len("svn-v1:"):]
- at = revid.index("@")
- fash = revid.rindex("-")
- uuid = revid[at+1:fash]
- branch_path = unescape_svn_path(revid[fash+1:])
- revnum = int(revid[0:at])
- assert revnum >= 0
- return (uuid, branch_path, revnum, cls())
-
- def revision_id_foreign_to_bzr(self, (uuid, revnum, path)):
- return "svn-v1:%d@%s-%s" % (revnum, uuid, escape_svn_path(path))
-
- def __eq__(self, other):
- return type(self) == type(other)
-
- def is_branch(self, branch_path):
- if branch_path == "":
- return True
-
- parts = branch_path.split("/")
- return (parts[-1] == "trunk" or
- parts[-2] in ("branches", "tags", "hooks"))
-
- def is_tag(self, tag_path):
- return False
-
- def import_revision(self, svn_revprops, fileprops, uuid, branch, revnum, rev):
- parse_svn_revprops(svn_revprops, rev)
-
- @staticmethod
- def generate_file_id(uuid, revnum, branch, inv_path):
- if inv_path == "":
- return ROOT_ID
- return "%s-%s" % (self.revision_id_foreign_to_bzr((uuid, revnum, branch)), escape_svn_path(inv_path))
-
- def import_fileid_map(self, revprops, fileprops):
- return {}
-
- def import_text_parents(self, revprops, fileprops):
- return {}
-
- def get_rhs_parents(self, branch_path, revprops, fileprops):
- value = fileprops.get(SVN_PROP_BZR_MERGE, "")
- if value == "":
- return ()
- return (value.splitlines()[-1])
-
-
-
-class BzrSvnMappingv2(BzrSvnMappingv1):
- """The second version of the mappings as used in the 0.3.x series.
-
- It does not support pushing revisions to Subversion as-is, but only
- as part of a merge.
- """
- name = "v2"
-
- @classmethod
- def revision_id_bzr_to_foreign(cls, revid):
- if not revid.startswith("svn-v2:"):
- raise InvalidRevisionId(revid, "")
- revid = revid[len("svn-v2:"):]
- at = revid.index("@")
- fash = revid.rindex("-")
- uuid = revid[at+1:fash]
- branch_path = unescape_svn_path(revid[fash+1:])
- revnum = int(revid[0:at])
- assert revnum >= 0
- return (uuid, branch_path, revnum, cls())
-
- def revision_id_foreign_to_bzr(self, (uuid, revnum, path)):
- return "svn-v2:%d@%s-%s" % (revnum, uuid, escape_svn_path(path))
-
- def __eq__(self, other):
- return type(self) == type(other)
+ @classmethod
+ def get_test_instance(cls):
+ return cls()
def parse_fileid_property(text):
@@ -738,10 +650,12 @@
mapping_registry = foreign.VcsMappingRegistry()
-mapping_registry.register('v1', BzrSvnMappingv1,
- 'Original bzr-svn mapping format')
-mapping_registry.register('v2', BzrSvnMappingv2,
- 'Second format (bzr-svn 0.3.x)')
+mapping_registry.register_lazy('v1', 'bzrlib.plugins.svn.mapping2',
+ 'BzrSvnMappingv1',
+ 'Original bzr-svn mapping format (bzr-svn 0.2.x)')
+mapping_registry.register_lazy('v2', 'bzrlib.plugins.svn.mapping2',
+ 'BzrSvnMappingv2',
+ 'Second format (bzr-svn 0.3.x)')
mapping_registry.register_lazy('v3', 'bzrlib.plugins.svn.mapping3',
'BzrSvnMappingv3FileProps',
'Third format (bzr-svn 0.4.x)')
=== added file 'mapping2.py'
--- a/mapping2.py 1970-01-01 00:00:00 +0000
+++ b/mapping2.py 2008-09-04 06:14:53 +0000
@@ -0,0 +1,111 @@
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from bzrlib.errors import InvalidRevisionId
+from bzrlib.inventory import ROOT_ID
+from bzrlib.plugins.svn.mapping import BzrSvnMapping, escape_svn_path, unescape_svn_path, parse_svn_revprops
+
+SVN_PROP_BZR_MERGE = 'bzr:merge'
+
+class BzrSvnMappingv1(BzrSvnMapping):
+ """This was the initial version of the mappings as used by bzr-svn
+ 0.2.
+
+ It does not support pushing revisions to Subversion as-is, but only
+ as part of a merge.
+ """
+ name = "v1"
+
+ @classmethod
+ def revision_id_bzr_to_foreign(cls, revid):
+ if not revid.startswith("svn-v1:"):
+ raise InvalidRevisionId(revid, "")
+ revid = revid[len("svn-v1:"):]
+ at = revid.index("@")
+ fash = revid.rindex("-")
+ uuid = revid[at+1:fash]
+ branch_path = unescape_svn_path(revid[fash+1:])
+ revnum = int(revid[0:at])
+ assert revnum >= 0
+ return (uuid, branch_path, revnum, cls())
+
+ def revision_id_foreign_to_bzr(self, (uuid, revnum, path)):
+ return "svn-v1:%d@%s-%s" % (revnum, uuid, escape_svn_path(path))
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+ def is_branch(self, branch_path):
+ if branch_path == "":
+ return True
+
+ parts = branch_path.split("/")
+ return (parts[-1] == "trunk" or
+ parts[-2] in ("branches", "tags", "hooks"))
+
+ def is_tag(self, tag_path):
+ return False
+
+ def import_revision(self, svn_revprops, fileprops, uuid, branch, revnum, rev):
+ parse_svn_revprops(svn_revprops, rev)
+
+ @staticmethod
+ def generate_file_id(uuid, revnum, branch, inv_path):
+ if inv_path == "":
+ return ROOT_ID
+ return "%s-%s" % (self.revision_id_foreign_to_bzr((uuid, revnum, branch)), escape_svn_path(inv_path))
+
+ def import_fileid_map(self, revprops, fileprops):
+ return {}
+
+ def import_text_parents(self, revprops, fileprops):
+ return {}
+
+ def get_rhs_parents(self, branch_path, revprops, fileprops):
+ value = fileprops.get(SVN_PROP_BZR_MERGE, "")
+ if value == "":
+ return ()
+ return (value.splitlines()[-1])
+
+
+class BzrSvnMappingv2(BzrSvnMappingv1):
+ """The second version of the mappings as used in the 0.3.x series.
+
+ It does not support pushing revisions to Subversion as-is, but only
+ as part of a merge.
+ """
+ name = "v2"
+
+ @classmethod
+ def revision_id_bzr_to_foreign(cls, revid):
+ if not revid.startswith("svn-v2:"):
+ raise InvalidRevisionId(revid, "")
+ revid = revid[len("svn-v2:"):]
+ at = revid.index("@")
+ fash = revid.rindex("-")
+ uuid = revid[at+1:fash]
+ branch_path = unescape_svn_path(revid[fash+1:])
+ revnum = int(revid[0:at])
+ assert revnum >= 0
+ return (uuid, branch_path, revnum, cls())
+
+ def revision_id_foreign_to_bzr(self, (uuid, revnum, path)):
+ return "svn-v2:%d@%s-%s" % (revnum, uuid, escape_svn_path(path))
+
+ def __eq__(self, other):
+ return type(self) == type(other)
+
+
+
=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py 2008-09-01 13:22:31 +0000
+++ b/mapping3/__init__.py 2008-09-04 06:14:53 +0000
@@ -81,6 +81,7 @@
return "%s(%s)" % (self.__class__.__name__, repr(self.scheme))
+
def get_stored_scheme(repository):
"""Retrieve the stored branching scheme, either in the repository
or in the configuration file.
@@ -273,6 +274,10 @@
def __str__(self):
return "%s(%s)" % (self.__class__.__name__, repr(self.scheme))
+ @classmethod
+ def get_test_instance(cls):
+ return cls(NoBranchingScheme())
+
class BzrSvnMappingv3FileProps(mapping.BzrSvnMappingFileProps, BzrSvnMappingv3):
=== modified file 'tests/__init__.py'
--- a/tests/__init__.py 2008-09-03 00:24:56 +0000
+++ b/tests/__init__.py 2008-09-04 06:14:53 +0000
@@ -345,7 +345,8 @@
'test_workingtree',
'test_blackbox',
'mapping_implementations',
- 'mapping3']
+ 'mapping3',
+ 'mapping3.test_scheme']
suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i) for i in testmod_names]))
suite.addTest(loader.loadTestsFromModuleNames(["bzrlib.plugins.svn.foreign.test_versionedfiles"]))
=== modified file 'tests/mapping_implementations/__init__.py'
--- a/tests/mapping_implementations/__init__.py 2008-09-04 05:49:51 +0000
+++ b/tests/mapping_implementations/__init__.py 2008-09-04 06:14:53 +0000
@@ -13,110 +13,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from bzrlib.tests import (multiply_tests_from_modules, TestCase,
- TestNotApplicable)
-
+from bzrlib.tests import multiply_tests_from_modules
from bzrlib.plugins.svn.mapping import mapping_registry
-class RoundtripMappingTests(TestCase):
-
- def setUp(self):
- super(RoundtripMappingTests, self).setUp()
- self._old_mapping = mapping_registry._get_default_key()
- mapping_registry.set_default(self.mapping_name)
-
- def tearDown(self):
- super(RoundtripMappingTests, self).tearDown()
- mapping_registry.set_default(self._old_mapping)
-
- def test_roundtrip_revision(self):
- revid = self.mapping.revision_id_foreign_to_bzr(("myuuid", 42, "path"))
- (uuid, path, revnum, mapping) = self.mapping.revision_id_bzr_to_foreign(revid)
- self.assertEquals(uuid, "myuuid")
- self.assertEquals(revnum, 42)
- self.assertEquals(path, "path")
- self.assertEquals(mapping, self.mapping)
-
- def test_fileid_map(self):
- if not self.mapping.supports_roundtripping():
- raise TestNotApplicable
- fileids = {"": "some-id", "bla/blie": "other-id"}
- revprops = {}
- fileprops = {}
- self.mapping.export_revision("branchp", 432432432.0, 0, "somebody", {}, "arevid", 4, ["merge1"], revprops, fileprops)
- self.mapping.export_fileid_map(fileids, revprops, fileprops)
- revprops["svn:date"] = "2008-11-03T09:33:00.716938Z"
- self.assertEquals(fileids,
- self.mapping.import_fileid_map(revprops, fileprops))
-
- def test_text_parents(self):
- if not self.mapping.supports_roundtripping():
- raise TestNotApplicable
- revprops = {}
- fileprops = {}
- text_parents = {"bla": "bloe", "ll": "12"}
- self.mapping.export_text_parents(text_parents, revprops, fileprops)
- self.assertEquals(text_parents,
- self.mapping.import_text_parents(revprops, fileprops))
-
- def test_message(self):
- if not self.mapping.supports_roundtripping():
- raise TestNotApplicable
- revprops = {}
- fileprops = {}
- self.mapping.export_revision("branchp", 432432432.0, 0, "somebody",
- {"arevprop": "val"}, "arevid", 4, ["merge1"], revprops, fileprops)
- revprops["svn:date"] = "2008-11-03T09:33:00.716938Z"
- try:
- self.mapping.export_message("My Commit message", revprops, fileprops)
- except NotImplementedError:
- raise TestNotApplicable
- targetrev = Revision(None)
- self.mapping.import_revision(revprops, fileprops, "someuuid", "somebp", 4, targetrev)
- self.assertEquals("My Commit message", targetrev.message)
-
- def test_revision(self):
- if not self.mapping.supports_roundtripping():
- raise TestNotApplicable
- revprops = {}
- fileprops = {}
- self.mapping.export_revision("branchp", 432432432.0, 0, "somebody",
- {"arevprop": "val" }, "arevid", 4, ["parent", "merge1"], revprops, fileprops)
- targetrev = Revision(None)
- revprops["svn:date"] = "2008-11-03T09:33:00.716938Z"
- self.mapping.import_revision(revprops, fileprops, "someuuid", "somebp", 4, targetrev)
- self.assertEquals(targetrev.committer, "somebody")
- self.assertEquals(targetrev.properties, {"arevprop": "val"})
- self.assertEquals(targetrev.timestamp, 432432432.0)
- self.assertEquals(targetrev.timezone, 0)
-
- def test_revision_id(self):
- if not self.mapping.supports_roundtripping():
- raise TestNotApplicable
- revprops = {}
- fileprops = {}
- self.mapping.export_revision("branchp", 432432432.0, 0, "somebody", {}, "arevid", 4, ["parent", "merge1"], revprops, fileprops)
- self.assertEquals((4, "arevid"), self.mapping.get_revision_id("branchp", revprops, fileprops))
-
- def test_revision_id_none(self):
- if not self.mapping.supports_roundtripping():
- raise TestNotApplicable
- self.assertEquals((None, None), self.mapping.get_revision_id("bp", {}, dict()))
-
- def test_parse_revision_id_unknown(self):
- self.assertRaises(InvalidRevisionId,
- lambda: self.mapping.revision_id_bzr_to_foreign("bla"))
-
- def test_parse_revision_id(self):
- self.assertEquals(("myuuid", "bla", 5, self.mapping),
- self.mapping.revision_id_bzr_to_foreign(
- self.mapping.revision_id_foreign_to_bzr(("myuuid", 5, "bla"))))
-
-
def load_tests(basic_tests, module, loader):
result = loader.suiteClass()
prefix = "bzrlib.plugins.svn.tests.mapping_implementations"
- modules = ['test_repository']
+ modules = ['test_base', 'test_repository']
module_name_list = ["%s.%s" % (prefix, m) for m in modules]
format_scenarios = []
for name in mapping_registry.keys():
=== added file 'tests/mapping_implementations/test_base.py'
--- a/tests/mapping_implementations/test_base.py 1970-01-01 00:00:00 +0000
+++ b/tests/mapping_implementations/test_base.py 2008-09-04 06:14:53 +0000
@@ -0,0 +1,122 @@
+# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from bzrlib.errors import InvalidRevisionId
+from bzrlib.revision import Revision
+from bzrlib.tests import TestCase, TestNotApplicable
+
+from bzrlib.plugins.svn.mapping import mapping_registry
+
+class RoundtripMappingTests(TestCase):
+
+ def setUp(self):
+ super(RoundtripMappingTests, self).setUp()
+ self.mapping = mapping_registry.get(self.mapping_name).get_test_instance()
+
+ def test_roundtrip_revision(self):
+ revid = self.mapping.revision_id_foreign_to_bzr(("myuuid", 42, "path"))
+ (uuid, path, revnum, mapping) = self.mapping.revision_id_bzr_to_foreign(revid)
+ self.assertEquals(uuid, "myuuid")
+ self.assertEquals(revnum, 42)
+ self.assertEquals(path, "path")
+ self.assertEquals(mapping, self.mapping)
+
+ def test_fileid_map(self):
+ if not self.mapping.supports_roundtripping():
+ raise TestNotApplicable
+ fileids = {"": "some-id", "bla/blie": "other-id"}
+ revprops = {}
+ fileprops = {}
+ self.mapping.export_revision("branchp", 432432432.0, 0, "somebody", {}, "arevid", 4, ["merge1"], revprops, fileprops)
+ self.mapping.export_fileid_map(fileids, revprops, fileprops)
+ revprops["svn:date"] = "2008-11-03T09:33:00.716938Z"
+ self.assertEquals(fileids,
+ self.mapping.import_fileid_map(revprops, fileprops))
+
+ def test_text_parents(self):
+ if not self.mapping.supports_roundtripping():
+ raise TestNotApplicable
+ revprops = {}
+ fileprops = {}
+ text_parents = {"bla": "bloe", "ll": "12"}
+ self.mapping.export_text_parents(text_parents, revprops, fileprops)
+ self.assertEquals(text_parents,
+ self.mapping.import_text_parents(revprops, fileprops))
+
+ def test_message(self):
+ if not self.mapping.supports_roundtripping():
+ raise TestNotApplicable
+ revprops = {}
+ fileprops = {}
+ self.mapping.export_revision("branchp", 432432432.0, 0, "somebody",
+ {"arevprop": "val"}, "arevid", 4, ["merge1"], revprops, fileprops)
+ revprops["svn:date"] = "2008-11-03T09:33:00.716938Z"
+ try:
+ self.mapping.export_message("My Commit message", revprops, fileprops)
+ except NotImplementedError:
+ raise TestNotApplicable
+ targetrev = Revision(None)
+ self.mapping.import_revision(revprops, fileprops, "someuuid", "somebp", 4, targetrev)
+ self.assertEquals("My Commit message", targetrev.message)
+
+ def test_revision(self):
+ if not self.mapping.supports_roundtripping():
+ raise TestNotApplicable
+ revprops = {}
+ fileprops = {}
+ self.mapping.export_revision("branchp", 432432432.0, 0, "somebody",
+ {"arevprop": "val" }, "arevid", 4, ["parent", "merge1"], revprops, fileprops)
+ targetrev = Revision(None)
+ revprops["svn:date"] = "2008-11-03T09:33:00.716938Z"
+ self.mapping.import_revision(revprops, fileprops, "someuuid", "somebp", 4, targetrev)
+ self.assertEquals(targetrev.committer, "somebody")
+ self.assertEquals(targetrev.properties, {"arevprop": "val"})
+ self.assertEquals(targetrev.timestamp, 432432432.0)
+ self.assertEquals(targetrev.timezone, 0)
+
+ def test_revision_id(self):
+ if not self.mapping.supports_roundtripping():
+ raise TestNotApplicable
+ revprops = {}
+ fileprops = {}
+ self.mapping.export_revision("branchp", 432432432.0, 0, "somebody", {}, "arevid", 4, ["parent", "merge1"], revprops, fileprops)
+ self.assertEquals((4, "arevid"), self.mapping.get_revision_id("branchp", revprops, fileprops))
+
+ def test_revision_id_none(self):
+ if not self.mapping.supports_roundtripping():
+ raise TestNotApplicable
+ self.assertEquals((None, None), self.mapping.get_revision_id("bp", {}, dict()))
+
+ def test_parse_revision_id_unknown(self):
+ self.assertRaises(InvalidRevisionId,
+ lambda: self.mapping.revision_id_bzr_to_foreign("bla"))
+
+ def test_parse_revision_id(self):
+ self.assertEquals(("myuuid", "bla", 5, self.mapping),
+ self.mapping.revision_id_bzr_to_foreign(
+ self.mapping.revision_id_foreign_to_bzr(("myuuid", 5, "bla"))))
+
+
+ def test_import_revision_svnprops(self):
+ rev = Revision(None)
+ self.mapping.import_revision({"svn:log": "A log msg",
+ "svn:author": "Somebody",
+ "svn:date": "2008-11-03T09:33:00.716938Z"}, {}, "someuuid", "trunk", 23, rev)
+ self.assertEquals("Somebody", rev.committer)
+ self.assertEquals("A log msg", rev.message)
+ self.assertEquals({}, rev.properties)
+ self.assertEquals(1225704780.716938, rev.timestamp)
+ self.assertEquals(0.0, rev.timezone)
+
=== modified file 'tests/test_mapping.py'
--- a/tests/test_mapping.py 2008-09-04 05:49:51 +0000
+++ b/tests/test_mapping.py 2008-09-04 06:14:53 +0000
@@ -24,8 +24,9 @@
from bzrlib.plugins.svn.errors import InvalidPropertyValue
from bzrlib.plugins.svn.mapping import (generate_revision_metadata, parse_revision_metadata,
parse_revid_property, parse_merge_property, parse_text_parents_property,
- generate_text_parents_property, BzrSvnMappingv1, BzrSvnMappingv2,
+ generate_text_parents_property,
parse_revision_id, escape_svn_path, unescape_svn_path)
+from bzrlib.plugins.svn.mapping2 import BzrSvnMappingv1, BzrSvnMappingv2
from bzrlib.plugins.svn.mapping3 import BzrSvnMappingv3FileProps
from bzrlib.plugins.svn.mapping4 import BzrSvnMappingv4
More information about the bazaar-commits
mailing list