Rev 987: Split v3 mappings into a separate module. in file:///data/jelmer/bzr-svn/layout/
Jelmer Vernooij
jelmer at samba.org
Fri May 2 19:27:02 BST 2008
At file:///data/jelmer/bzr-svn/layout/
------------------------------------------------------------
revno: 987
revision-id: jelmer at samba.org-20080502182700-te13wsp7ebhsu60c
parent: jelmer at samba.org-20080502174252-mc2retxh7ehcg56o
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: layout
timestamp: Fri 2008-05-02 20:27:00 +0200
message:
Split v3 mappings into a separate module.
added:
mapping3/ mapping3-20080502174315-1pv6whtdk07lwo9q-1
mapping3/__init__.py __init__.py-20080502174630-9324zh25kka98vlw-1
modified:
mapping.py mapping.py-20080128201303-6cp01phc0dmc0kiv-1
repository.py repository.py-20060306123302-1f8c5069b3fe0265
revids.py revids.py-20070416220458-36vfa0730cchevp1-1
scheme.py scheme.py-20060516195850-95181aae6b272f9e
tests/test_blackbox.py test_blackbox.py-20070325150839-d10llf8arptpcfl6-1
tests/test_branch.py test_branch.py-20060508162215-74ffeb5d608f8e20
tests/test_fileids.py test_fileids.py-20060622131341-19gyrlgqy8yl2od5-1
tests/test_mapping.py test_mapping.py-20080201131338-0zd86eznn4bojtee-1
tests/test_upgrade.py test_upgrade.py-20070106170128-64zt3eqggg4tng1c-1
=== modified file 'mapping.py'
--- a/mapping.py 2008-04-07 14:52:57 +0000
+++ b/mapping.py 2008-05-02 18:27:00 +0000
@@ -434,99 +434,6 @@
return "".join(["%s\t%s\n" % (urllib.quote(path), fileids[path]) for path in sorted(fileids.keys())])
-class BzrSvnMappingv3(BzrSvnMapping):
- """The third version of the mappings as used in the 0.4.x series.
-
- """
- experimental = False
- upgrade_suffix = "-svn3"
- revid_prefix = "svn-v3-"
-
- def __init__(self, scheme):
- BzrSvnMapping.__init__(self)
- self.scheme = scheme
- assert not isinstance(scheme, str)
-
- def __repr__(self):
- return "%s(%r)" % (self.__class__.__name__, self.scheme)
-
- def generate_file_id(self, uuid, revnum, branch, inv_path):
- assert isinstance(uuid, str)
- assert isinstance(revnum, int)
- assert isinstance(branch, str)
- assert isinstance(inv_path, unicode)
- inv_path = inv_path.encode("utf-8")
- ret = "%d@%s:%s:%s" % (revnum, uuid, escape_svn_path(branch), escape_svn_path(inv_path))
- if len(ret) > 150:
- ret = "%d@%s:%s;%s" % (revnum, uuid,
- escape_svn_path(branch),
- sha.new(inv_path).hexdigest())
- assert isinstance(ret, str)
- return osutils.safe_file_id(ret)
-
- @staticmethod
- def supports_roundtripping():
- return True
-
- @classmethod
- def _parse_revision_id(cls, revid):
- assert isinstance(revid, str)
-
- if not revid.startswith(cls.revid_prefix):
- raise InvalidRevisionId(revid, "")
-
- try:
- (version, uuid, branch_path, srevnum) = revid.split(":")
- except ValueError:
- raise InvalidRevisionId(revid, "")
-
- scheme = version[len(cls.revid_prefix):]
-
- branch_path = unescape_svn_path(branch_path)
-
- return (uuid, branch_path, int(srevnum), scheme)
-
- @classmethod
- def parse_revision_id(cls, revid):
- (uuid, branch_path, srevnum, scheme) = cls._parse_revision_id(revid)
- # Some older versions of bzr-svn 0.4 did not always set a branching
- # scheme but set "undefined" instead.
- if scheme == "undefined":
- scheme = guess_scheme_from_branch_path(branch_path)
- else:
- scheme = BranchingScheme.find_scheme(scheme)
-
- return (uuid, branch_path, srevnum, cls(scheme))
-
- def is_branch(self, branch_path):
- return (self.scheme.is_branch(branch_path) or
- self.scheme.is_tag(branch_path))
-
- def is_tag(self, tag_path):
- return self.scheme.is_tag(tag_path)
-
- @classmethod
- def _generate_revision_id(cls, uuid, revnum, path, scheme):
- assert isinstance(revnum, int)
- assert isinstance(path, str)
- assert revnum >= 0
- assert revnum > 0 or path == "", \
- "Trying to generate revid for (%r,%r)" % (path, revnum)
- return "%s%s:%s:%s:%d" % (cls.revid_prefix, scheme, uuid, \
- escape_svn_path(path.strip("/")), revnum)
-
- def generate_revision_id(self, uuid, revnum, path):
- return self._generate_revision_id(uuid, revnum, path, self.scheme)
-
- def unprefix(self, branch_path, repos_path):
- (bp, np) = self.scheme.unprefix(repos_path)
- assert branch_path == bp
- return np
-
- def __eq__(self, other):
- return type(self) == type(other) and self.scheme == other.scheme
-
-
class BzrSvnMappingFileProps(object):
@classmethod
def supports_custom_fileprops(cls):
@@ -610,9 +517,6 @@
else:
fileprops[SVN_PROP_BZR_FILEIDS] = ""
-class BzrSvnMappingv3FileProps(BzrSvnMappingFileProps, BzrSvnMappingv3):
- pass
-
class BzrSvnMappingRevProps(object):
@classmethod
def supports_custom_revprops(cls):
@@ -679,10 +583,6 @@
raise NotImplementedError(self.get_rhs_ancestors)
-class BzrSvnMappingv3RevProps(BzrSvnMappingRevProps, BzrSvnMappingv3):
- pass
-
-
class BzrSvnMappingv4(BzrSvnMappingRevProps):
revid_prefix = "svn-v4"
experimental = True
@@ -723,47 +623,6 @@
return type(self) == type(other)
-class BzrSvnMappingv3Hybrid(BzrSvnMappingv3):
- def __init__(self, scheme):
- BzrSvnMappingv3.__init__(self, scheme)
- self.revprops = BzrSvnMappingv3RevProps(scheme)
- self.fileprops = BzrSvnMappingv3FileProps(scheme)
-
- def get_rhs_parents(self, branch_path, svn_revprops, fileprops):
- if svn_revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
- return self.revprops.get_rhs_parents(branch_path, svn_revprops, fileprops)
- else:
- return self.fileprops.get_rhs_parents(branch_path, svn_revprops, fileprops)
-
- def get_revision_id(self, branch_path, revprops, fileprops):
- if revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
- return self.revprops.get_revision_id(branch_path, revprops, fileprops)
- else:
- return self.fileprops.get_revision_id(branch_path, revprops, fileprops)
-
- def import_fileid_map(self, svn_revprops, fileprops):
- if svn_revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
- return self.revprops.import_fileid_map(svn_revprops, fileprops)
- else:
- return self.fileprops.import_fileid_map(svn_revprops, fileprops)
-
- def export_revision(self, branch_root, timestamp, timezone, committer, revprops, revision_id,
- revno, merges, fileprops):
- (_, fileprops) = self.fileprops.export_revision(branch_root, timestamp, timezone, committer,
- revprops, revision_id, revno, merges, fileprops)
- (revprops, _) = self.revprops.export_revision(branch_root, timestamp, timezone, committer,
- revprops, revision_id, revno, merges, fileprops)
- return (revprops, fileprops)
-
- def export_fileid_map(self, fileids, revprops, fileprops):
- self.fileprops.export_fileid_map(fileids, revprops, fileprops)
- self.revprops.export_fileid_map(fileids, revprops, fileprops)
-
- def import_revision(self, svn_revprops, fileprops, rev):
- self.fileprops.import_revision(svn_revprops, fileprops, rev)
- self.revprops.import_revision(svn_revprops, fileprops, rev)
-
-
class BzrSvnMappingRegistry(registry.Registry):
"""Registry for the various Bzr<->Svn mappings."""
def register(self, key, factory, help):
@@ -787,19 +646,18 @@
'Original bzr-svn mapping format')
mapping_registry.register('v2', BzrSvnMappingv2,
'Second format')
-mapping_registry.register('v3-revprops', BzrSvnMappingv3RevProps,
- 'Third format with revision properties')
-mapping_registry.register('v3-fileprops', BzrSvnMappingv3FileProps,
+mapping_registry.register('v4', BzrSvnMappingv4,
+ 'Fourth format')
+mapping_registry.register_lazy('v3-revprops', 'bzrlib.plugins.svn.mapping3',
+ 'BzrSvnMappingv3RevProps', 'Third format with revision properties')
+mapping_registry.register_lazy('v3-fileprops', 'bzrlib.plugins.svn.mapping3', 'BzrSvnMappingv3FileProps',
'Third format with file properties')
-mapping_registry.register('v3-hybrid', BzrSvnMappingv3Hybrid,
+mapping_registry.register_lazy('v3-hybrid', 'bzrlib.plugins.svn.mapping3', 'BzrSvnMappingv3Hybrid',
'Hybrid third format')
-mapping_registry.register('v3', BzrSvnMappingv3FileProps,
+mapping_registry.register_lazy('v3', 'bzrlib.plugins.svn.mapping3', 'BzrSvnMappingv3FileProps',
'Default third format')
-mapping_registry.register('v4', BzrSvnMappingv4,
- 'Fourth format')
mapping_registry.set_default('v3-fileprops')
-
def parse_revision_id(revid):
"""Try to parse a Subversion revision id.
=== added directory 'mapping3'
=== added file 'mapping3/__init__.py'
--- a/mapping3/__init__.py 1970-01-01 00:00:00 +0000
+++ b/mapping3/__init__.py 2008-05-02 18:27:00 +0000
@@ -0,0 +1,159 @@
+# 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/>.
+
+import mapping
+
+class BzrSvnMappingv3(mapping.BzrSvnMapping):
+ """The third version of the mappings as used in the 0.4.x series.
+
+ """
+ experimental = False
+ upgrade_suffix = "-svn3"
+ revid_prefix = "svn-v3-"
+
+ def __init__(self, scheme):
+ mapping.BzrSvnMapping.__init__(self)
+ self.scheme = scheme
+ assert not isinstance(scheme, str)
+
+ def __repr__(self):
+ return "%s(%r)" % (self.__class__.__name__, self.scheme)
+
+ def generate_file_id(self, uuid, revnum, branch, inv_path):
+ assert isinstance(uuid, str)
+ assert isinstance(revnum, int)
+ assert isinstance(branch, str)
+ assert isinstance(inv_path, unicode)
+ inv_path = inv_path.encode("utf-8")
+ ret = "%d@%s:%s:%s" % (revnum, uuid, escape_svn_path(branch), escape_svn_path(inv_path))
+ if len(ret) > 150:
+ ret = "%d@%s:%s;%s" % (revnum, uuid,
+ escape_svn_path(branch),
+ sha.new(inv_path).hexdigest())
+ assert isinstance(ret, str)
+ return osutils.safe_file_id(ret)
+
+ @staticmethod
+ def supports_roundtripping():
+ return True
+
+ @classmethod
+ def _parse_revision_id(cls, revid):
+ assert isinstance(revid, str)
+
+ if not revid.startswith(cls.revid_prefix):
+ raise InvalidRevisionId(revid, "")
+
+ try:
+ (version, uuid, branch_path, srevnum) = revid.split(":")
+ except ValueError:
+ raise InvalidRevisionId(revid, "")
+
+ scheme = version[len(cls.revid_prefix):]
+
+ branch_path = unescape_svn_path(branch_path)
+
+ return (uuid, branch_path, int(srevnum), scheme)
+
+ @classmethod
+ def parse_revision_id(cls, revid):
+ (uuid, branch_path, srevnum, scheme) = cls._parse_revision_id(revid)
+ # Some older versions of bzr-svn 0.4 did not always set a branching
+ # scheme but set "undefined" instead.
+ if scheme == "undefined":
+ scheme = guess_scheme_from_branch_path(branch_path)
+ else:
+ scheme = BranchingScheme.find_scheme(scheme)
+
+ return (uuid, branch_path, srevnum, cls(scheme))
+
+ def is_branch(self, branch_path):
+ return (self.scheme.is_branch(branch_path) or
+ self.scheme.is_tag(branch_path))
+
+ def is_tag(self, tag_path):
+ return self.scheme.is_tag(tag_path)
+
+ @classmethod
+ def _generate_revision_id(cls, uuid, revnum, path, scheme):
+ assert isinstance(revnum, int)
+ assert isinstance(path, str)
+ assert revnum >= 0
+ assert revnum > 0 or path == "", \
+ "Trying to generate revid for (%r,%r)" % (path, revnum)
+ return "%s%s:%s:%s:%d" % (cls.revid_prefix, scheme, uuid, \
+ escape_svn_path(path.strip("/")), revnum)
+
+ def generate_revision_id(self, uuid, revnum, path):
+ return self._generate_revision_id(uuid, revnum, path, self.scheme)
+
+ def unprefix(self, branch_path, repos_path):
+ (bp, np) = self.scheme.unprefix(repos_path)
+ assert branch_path == bp
+ return np
+
+ def __eq__(self, other):
+ return type(self) == type(other) and self.scheme == other.scheme
+
+
+class BzrSvnMappingv3FileProps(mapping.BzrSvnMappingFileProps, BzrSvnMappingv3):
+ pass
+
+
+class BzrSvnMappingv3RevProps(mapping.BzrSvnMappingRevProps, BzrSvnMappingv3):
+ pass
+
+
+class BzrSvnMappingv3Hybrid(BzrSvnMappingv3):
+ def __init__(self, scheme):
+ BzrSvnMappingv3.__init__(self, scheme)
+ self.revprops = BzrSvnMappingv3RevProps(scheme)
+ self.fileprops = BzrSvnMappingv3FileProps(scheme)
+
+ def get_rhs_parents(self, branch_path, svn_revprops, fileprops):
+ if svn_revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
+ return self.revprops.get_rhs_parents(branch_path, svn_revprops, fileprops)
+ else:
+ return self.fileprops.get_rhs_parents(branch_path, svn_revprops, fileprops)
+
+ def get_revision_id(self, branch_path, revprops, fileprops):
+ if revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
+ return self.revprops.get_revision_id(branch_path, revprops, fileprops)
+ else:
+ return self.fileprops.get_revision_id(branch_path, revprops, fileprops)
+
+ def import_fileid_map(self, svn_revprops, fileprops):
+ if svn_revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
+ return self.revprops.import_fileid_map(svn_revprops, fileprops)
+ else:
+ return self.fileprops.import_fileid_map(svn_revprops, fileprops)
+
+ def export_revision(self, branch_root, timestamp, timezone, committer, revprops, revision_id,
+ revno, merges, fileprops):
+ (_, fileprops) = self.fileprops.export_revision(branch_root, timestamp, timezone, committer,
+ revprops, revision_id, revno, merges, fileprops)
+ (revprops, _) = self.revprops.export_revision(branch_root, timestamp, timezone, committer,
+ revprops, revision_id, revno, merges, fileprops)
+ return (revprops, fileprops)
+
+ def export_fileid_map(self, fileids, revprops, fileprops):
+ self.fileprops.export_fileid_map(fileids, revprops, fileprops)
+ self.revprops.export_fileid_map(fileids, revprops, fileprops)
+
+ def import_revision(self, svn_revprops, fileprops, rev):
+ self.fileprops.import_revision(svn_revprops, fileprops, rev)
+ self.revprops.import_revision(svn_revprops, fileprops, rev)
+
+
=== modified file 'repository.py'
--- a/repository.py 2008-05-02 17:42:52 +0000
+++ b/repository.py 2008-05-02 18:27:00 +0000
@@ -42,10 +42,11 @@
import errors
import logwalker
from mapping import (SVN_PROP_BZR_REVISION_ID, SVN_REVPROP_BZR_SIGNATURE,
- SVN_PROP_BZR_BRANCHING_SCHEME, BzrSvnMappingv3FileProps,
+ SVN_PROP_BZR_BRANCHING_SCHEME,
parse_revision_metadata, parse_revid_property,
parse_merge_property, BzrSvnMapping,
get_default_mapping, parse_revision_id)
+from mapping3 import BzrSvnMappingv3FileProps
from revids import CachingRevidMap, RevidMap
from scheme import (BranchingScheme, ListBranchingScheme,
parse_list_scheme_text, guess_scheme_from_history)
=== modified file 'revids.py'
--- a/revids.py 2008-05-02 17:42:52 +0000
+++ b/revids.py 2008-05-02 18:27:00 +0000
@@ -24,8 +24,9 @@
from cache import CacheTable
from errors import InvalidPropertyValue
-from mapping import (parse_revision_id, BzrSvnMapping, BzrSvnMappingv3FileProps,
+from mapping import (parse_revision_id, BzrSvnMapping,
SVN_PROP_BZR_REVISION_ID, parse_revid_property)
+from mapping3 import BzrSvnMappingv3FileProps
from scheme import BranchingScheme
class RevidMap(object):
=== modified file 'scheme.py'
--- a/scheme.py 2008-05-02 17:42:52 +0000
+++ b/scheme.py 2008-05-02 18:27:00 +0000
@@ -23,6 +23,7 @@
from base64 import urlsafe_b64decode, urlsafe_b64encode
from layout import RepositoryLayout
+import util
import bz2
class BranchingScheme(RepositoryLayout):
@@ -336,7 +337,7 @@
path[len(self.path):].strip("/"))
def __str__(self):
- if is_valid_property_name(self.path):
+ if util.is_valid_property_name(self.path):
return "single-%s" % self.path
else:
return "single1-%s" % prop_name_quote(self.path)
=== modified file 'tests/test_blackbox.py'
--- a/tests/test_blackbox.py 2008-03-24 04:52:30 +0000
+++ b/tests/test_blackbox.py 2008-05-02 18:27:00 +0000
@@ -19,7 +19,7 @@
from bzrlib.tests.blackbox import ExternalBase
from bzrlib.trace import mutter
-from mapping import BzrSvnMappingv3FileProps
+from mapping3 import BzrSvnMappingv3FileProps
from scheme import NoBranchingScheme
from tests import TestCaseWithSubversionRepository
=== modified file 'tests/test_branch.py'
--- a/tests/test_branch.py 2008-04-28 11:19:52 +0000
+++ b/tests/test_branch.py 2008-05-02 18:27:00 +0000
@@ -28,7 +28,8 @@
from branch import FakeControlFiles, SvnBranchFormat
from convert import load_dumpfile
-from mapping import (SVN_PROP_BZR_REVISION_ID, BzrSvnMappingv3FileProps)
+from mapping import SVN_PROP_BZR_REVISION_ID
+from mapping3 import BzrSvnMappingv3FileProps
from scheme import TrunkBranchingScheme
from tests import TestCaseWithSubversionRepository
=== modified file 'tests/test_fileids.py'
--- a/tests/test_fileids.py 2008-03-29 15:36:19 +0000
+++ b/tests/test_fileids.py 2008-05-02 18:27:00 +0000
@@ -22,7 +22,7 @@
from bzrlib.tests import TestCase
from fileids import simple_apply_changes
-from mapping import BzrSvnMappingv3FileProps
+from mapping3 import BzrSvnMappingv3FileProps
from scheme import TrunkBranchingScheme, NoBranchingScheme
from tests import TestCaseWithSubversionRepository
=== modified file 'tests/test_mapping.py'
--- a/tests/test_mapping.py 2008-03-29 14:37:29 +0000
+++ b/tests/test_mapping.py 2008-05-02 18:27:00 +0000
@@ -21,8 +21,9 @@
from mapping import (generate_revision_metadata, parse_revision_metadata,
parse_revid_property, parse_merge_property,
BzrSvnMappingv1, BzrSvnMappingv2,
- BzrSvnMappingv3FileProps, BzrSvnMappingv3RevProps,
- BzrSvnMappingv4, BzrSvnMappingv3Hybrid, parse_revision_id)
+ BzrSvnMappingv4, parse_revision_id)
+from mapping3 import (BzrSvnMappingv3FileProps, BzrSvnMappingv3RevProps,
+ BzrSvnMappingv3Hybrid)
from scheme import NoBranchingScheme
from bzrlib.errors import InvalidRevisionId
=== modified file 'tests/test_upgrade.py'
--- a/tests/test_upgrade.py 2008-04-28 11:36:04 +0000
+++ b/tests/test_upgrade.py 2008-05-02 18:27:00 +0000
@@ -23,8 +23,8 @@
from errors import RebaseNotPresent
from format import get_rich_root_format
-from mapping import (BzrSvnMappingv3FileProps, BzrSvnMappingv2,
- BzrSvnMappingv1)
+from mapping import (BzrSvnMappingv2, BzrSvnMappingv1)
+from mapping3 import BzrSvnMappingv3FileProps
from scheme import TrunkBranchingScheme
from tests import TestCaseWithSubversionRepository
from upgrade import (upgrade_repository, upgrade_branch,
More information about the bazaar-commits
mailing list