Rev 1798: Move parse_mapping_name and parse_revision_id onto SubversionMappingRegistry. in file:///data/jelmer/bzr-svn/trunk/
Jelmer Vernooij
jelmer at samba.org
Thu Sep 4 09:11:09 BST 2008
At file:///data/jelmer/bzr-svn/trunk/
------------------------------------------------------------
revno: 1798
revision-id: jelmer at samba.org-20080904081108-mhnj83ywmro0vbj3
parent: jelmer at samba.org-20080904075837-djng68pxhr1zd163
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Thu 2008-09-04 10:11:08 +0200
message:
Move parse_mapping_name and parse_revision_id onto SubversionMappingRegistry.
modified:
__init__.py __init__.py-20051008155114-eae558e6cf149e1d
commit.py commit.py-20060607190346-qvq128wgfubhhgm2-1
mapping.py mapping.py-20080128201303-6cp01phc0dmc0kiv-1
repository.py repository.py-20060306123302-1f8c5069b3fe0265
revids.py revids.py-20070416220458-36vfa0730cchevp1-1
tests/test_mapping.py test_mapping.py-20080201131338-0zd86eznn4bojtee-1
upgrade.py upgrade.py-20070106192108-0rakplee2lzah4gs-1
=== modified file '__init__.py'
--- a/__init__.py 2008-09-02 01:00:35 +0000
+++ b/__init__.py 2008-09-04 08:11:08 +0000
@@ -313,7 +313,7 @@
This will change the revision ids of revisions whose parents
were mapped from svn revisions.
"""
- from bzrlib.plugins.svn.mapping import mapping_registry, get_default_mapping
+ from bzrlib.plugins.svn.mapping import mapping_registry
takes_args = ['from_repository?']
takes_options = ['verbose', RegistryOption('mapping',
help="New mapping to upgrade to.",
@@ -352,7 +352,7 @@
from_repository = Repository.open(from_repository)
if mapping is None:
- mapping = get_default_mapping()
+ mapping = mapping_registry.get_default()
new_mapping = mapping.from_repository(from_repository)
@@ -513,12 +513,12 @@
from bzrlib.errors import BzrCommandError
from bzrlib.repository import Repository
from bzrlib.plugins.svn.upgrade import set_revprops
- from bzrlib.plugins.svn.mapping import get_default_mapping
+ from bzrlib.plugins.svn.mapping import mapping_registry
repos = Repository.open(location)
if not repos.transport.has_capability("commit-revprops"):
raise BzrCommandError("Please upgrade the Subversion server to 1.5 or higher.")
if mapping is None:
- mapping = get_default_mapping()
+ mapping = mapping_registry.get_default()
new_mapping = mapping.from_repository(repos)
if not new_mapping.supports_custom_revprops():
raise BzrCommandError("Please specify a different mapping, %s doesn't support revision properties." % new_mapping.name)
=== modified file 'commit.py'
--- a/commit.py 2008-09-01 01:30:13 +0000
+++ b/commit.py 2008-09-04 08:11:08 +0000
@@ -35,7 +35,7 @@
generate_svk_feature, serialize_svk_features,
parse_svk_features, SVN_PROP_SVK_MERGE)
from bzrlib.plugins.svn.logwalker import lazy_dict
-from bzrlib.plugins.svn.mapping import parse_revision_id
+from bzrlib.plugins.svn.mapping import mapping_registry
from bzrlib.plugins.svn.repository import SvnRepositoryFormat, SvnRepository
@@ -46,7 +46,7 @@
:return: Matching SVK feature identifier.
"""
assert isinstance(revid, str)
- (uuid, branch, revnum, _) = parse_revision_id(revid)
+ (uuid, branch, revnum, _) = mapping_registry.parse_revision_id(revid)
# TODO: What about renamed revisions? Should use
# repository.lookup_revision_id here.
return generate_svk_feature(uuid, branch, revnum)
=== modified file 'mapping.py'
--- a/mapping.py 2008-09-04 07:58:37 +0000
+++ b/mapping.py 2008-09-04 08:11:08 +0000
@@ -649,7 +649,31 @@
raise NotImplementedError(self.get_rhs_ancestors)
-mapping_registry = foreign.VcsMappingRegistry()
+class SubversionMappingRegistry(foreign.VcsMappingRegistry):
+
+ def parse_mapping_name(self, name):
+ assert isinstance(name, str)
+ if "-" in name:
+ name, rest = name.split("-", 1)
+ assert isinstance(rest, str)
+ return self.get(name)(rest)
+ return self.get(name)()
+
+
+ def parse_revision_id(self, revid):
+ """Try to parse a Subversion revision id.
+
+ :param revid: Revision id to parse
+ :return: tuple with (uuid, branch_path, revno, mapping)
+ """
+ if not revid.startswith("svn-"):
+ raise InvalidRevisionId(revid, None)
+ mapping_version = revid[len("svn-"):len("svn-vx")]
+ mapping = self.get(mapping_version)
+ return mapping.revision_id_bzr_to_foreign(revid)
+
+
+mapping_registry = SubversionMappingRegistry()
mapping_registry.register_lazy('v1', 'bzrlib.plugins.svn.mapping2',
'BzrSvnMappingv1',
'Original bzr-svn mapping format (bzr-svn 0.2.x)')
@@ -664,32 +688,6 @@
'Fourth format (bzr-svn 0.5.x)')
mapping_registry.set_default('v3')
-def parse_mapping_name(name):
- assert isinstance(name, str)
- if "-" in name:
- name, rest = name.split("-", 1)
- assert isinstance(rest, str)
- return mapping_registry.get(name)(rest)
- return mapping_registry.get(name)()
-
-
-def parse_revision_id(revid):
- """Try to parse a Subversion revision id.
-
- :param revid: Revision id to parse
- :return: tuple with (uuid, branch_path, revno, mapping)
- """
- if not revid.startswith("svn-"):
- raise InvalidRevisionId(revid, None)
- mapping_version = revid[len("svn-"):len("svn-vx")]
- mapping = mapping_registry.get(mapping_version)
- return mapping.revision_id_bzr_to_foreign(revid)
-
-
-def get_default_mapping():
- return mapping_registry.get_default()
-
-
def find_mapping(revprops, fileprops):
if SVN_REVPROP_BZR_MAPPING_VERSION in revprops:
try:
@@ -704,7 +702,7 @@
return ret
for k, v in fileprops.items():
if k.startswith(SVN_PROP_BZR_REVISION_ID):
- return parse_mapping_name(k[len(SVN_PROP_BZR_REVISION_ID):])
+ return mapping_registry.parse_mapping_name(k[len(SVN_PROP_BZR_REVISION_ID):])
return None
=== modified file 'repository.py'
--- a/repository.py 2008-09-04 07:01:24 +0000
+++ b/repository.py 2008-09-04 08:11:08 +0000
@@ -43,7 +43,6 @@
SVN_REVPROP_BZR_SKIP,
parse_tags_property,
BzrSvnMapping,
- get_default_mapping,
mapping_registry,
is_bzr_revision_revprops, is_bzr_revision_fileprops,
parse_svn_dateprop)
@@ -256,7 +255,7 @@
config_mapping_name = self.get_config().get_default_mapping()
if config_mapping_name is not None:
return mapping_registry.get(config_mapping_name)
- return get_default_mapping()
+ return mapping_registry.get_default()
def get_mapping(self):
if self._default_mapping is None:
=== modified file 'revids.py'
--- a/revids.py 2008-09-02 18:05:00 +0000
+++ b/revids.py 2008-09-04 08:11:08 +0000
@@ -22,9 +22,9 @@
from bzrlib.plugins.svn.cache import CacheTable
from bzrlib.plugins.svn.core import SubversionException
from bzrlib.plugins.svn.errors import InvalidPropertyValue, ERR_FS_NO_SUCH_REVISION, InvalidBzrSvnRevision
-from bzrlib.plugins.svn.mapping import (parse_revision_id, BzrSvnMapping,
+from bzrlib.plugins.svn.mapping import (BzrSvnMapping,
SVN_PROP_BZR_REVISION_ID, parse_revid_property,
- find_mapping, parse_mapping_name, is_bzr_revision_revprops)
+ find_mapping, mapping_registry, is_bzr_revision_revprops)
class RevidMap(object):
def __init__(self, repos):
@@ -34,7 +34,7 @@
"""Find the (branch, revnum) tuple for a revision id."""
# Try a simple parse
try:
- (uuid, branch_path, revnum, mapping) = parse_revision_id(revid)
+ (uuid, branch_path, revnum, mapping) = mapping_registry.parse_revision_id(revid)
assert isinstance(branch_path, str)
assert isinstance(mapping, BzrSvnMapping)
if uuid == self.repos.uuid:
@@ -98,7 +98,7 @@
# If there are any new entries that are not yet in the cache,
# add them
for ((entry_revno, entry_revid), mapping_name) in revids:
- yield (entry_revid, branch, revno, parse_mapping_name(mapping_name))
+ yield (entry_revid, branch, revno, mapping_registry.parse_mapping_name(mapping_name))
def bisect_revid_revnum(self, revid, branch_path, min_revnum, max_revnum):
"""Find out what the actual revnum was that corresponds to a revid.
@@ -125,7 +125,7 @@
continue
if entry_revid == revid:
mapping_name = propname[len(SVN_PROP_BZR_REVISION_ID):]
- mapping = parse_mapping_name(mapping_name)
+ mapping = mapping_registry.parse_mapping_name(mapping_name)
assert (mapping.is_tag(revmeta.branch_path) or
mapping.is_branch(revmeta.branch_path))
return (revmeta.branch_path, revmeta.revnum, mapping)
@@ -142,7 +142,7 @@
def get_branch_revnum(self, revid, layout, project=None):
# Try a simple parse
try:
- (uuid, branch_path, revnum, mapping) = parse_revision_id(revid)
+ (uuid, branch_path, revnum, mapping) = mapping_registry.parse_revision_id(revid)
assert isinstance(branch_path, str)
assert isinstance(mapping, BzrSvnMapping)
if uuid == self.actual.repos.uuid:
@@ -162,7 +162,7 @@
# Entry already complete?
assert min_revnum <= max_revnum
if min_revnum == max_revnum:
- return (branch_path, min_revnum, parse_mapping_name(mapping))
+ return (branch_path, min_revnum, mapping_registry.parse_mapping_name(mapping))
except NoSuchRevision, e:
last_revnum = self.actual.repos.get_latest_revnum()
last_checked = self.cache.last_revnum_checked(repr((layout, project)))
=== modified file 'tests/test_mapping.py'
--- a/tests/test_mapping.py 2008-09-04 06:14:53 +0000
+++ b/tests/test_mapping.py 2008-09-04 08:11:08 +0000
@@ -25,7 +25,7 @@
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,
- parse_revision_id, escape_svn_path, unescape_svn_path)
+ 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
@@ -149,31 +149,31 @@
def test_v4(self):
self.assertEqual(("uuid", "trunk", 1, BzrSvnMappingv4()),
- parse_revision_id("svn-v3:uuid:trunk:1"))
+ mapping_registry.parse_revision_id("svn-v3:uuid:trunk:1"))
def test_v3(self):
self.assertEqual(("uuid", "trunk", 1, BzrSvnMappingv3FileProps(TrunkBranchingScheme())),
- parse_revision_id("svn-v3-trunk0:uuid:trunk:1"))
+ mapping_registry.parse_revision_id("svn-v3-trunk0:uuid:trunk:1"))
def test_v3_undefined(self):
self.assertEqual(("uuid", "trunk", 1, BzrSvnMappingv3FileProps(TrunkBranchingScheme())),
- parse_revision_id("svn-v3-undefined:uuid:trunk:1"))
+ mapping_registry.parse_revision_id("svn-v3-undefined:uuid:trunk:1"))
def test_v2(self):
self.assertEqual(("uuid", "trunk", 1, BzrSvnMappingv2()),
- parse_revision_id("svn-v2:1 at uuid-trunk"))
+ mapping_registry.parse_revision_id("svn-v2:1 at uuid-trunk"))
def test_v1(self):
self.assertEqual(("uuid", "trunk", 1, BzrSvnMappingv1()),
- parse_revision_id("svn-v1:1 at uuid-trunk"))
+ mapping_registry.parse_revision_id("svn-v1:1 at uuid-trunk"))
def test_except(self):
self.assertRaises(InvalidRevisionId,
- parse_revision_id, "svn-v0:1 at uuid-trunk")
+ mapping_registry.parse_revision_id, "svn-v0:1 at uuid-trunk")
def test_except_nonsvn(self):
self.assertRaises(InvalidRevisionId,
- parse_revision_id, "blah")
+ mapping_registry.parse_revision_id, "blah")
class EscapeTest(TestCase):
=== modified file 'upgrade.py'
--- a/upgrade.py 2008-09-04 07:32:57 +0000
+++ b/upgrade.py 2008-09-04 08:11:08 +0000
@@ -22,7 +22,7 @@
import itertools
from bzrlib.plugins.svn import changes, logwalker, mapping, properties
-from bzrlib.plugins.svn.mapping import parse_revision_id
+from bzrlib.plugins.svn.mapping import mapping_registry
class UpgradeChangesContent(BzrError):
"""Inconsistency was found upgrading the mapping of a revision."""
@@ -118,7 +118,7 @@
for revid in revs:
assert isinstance(revid, str)
try:
- (uuid, bp, rev, mapping) = parse_revision_id(revid)
+ (uuid, bp, rev, mapping) = mapping_registry.parse_revision_id(revid)
except InvalidRevisionId:
# Not a bzr-svn revision, nothing to do
continue
@@ -217,7 +217,7 @@
info("%s -> %s" % (revid, plan[revid][0]))
def fix_revid(revid):
try:
- (uuid, bp, rev, mapping) = parse_revision_id(revid)
+ (uuid, bp, rev, mapping) = mapping_registry.parse_revision_id(revid)
except InvalidRevisionId:
return revid
return new_mapping.revision_id_foreign_to_bzr((uuid, rev, bp))
More information about the bazaar-commits
mailing list