1 # Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 from bzrlib import errors
18 from bzrlib.plugins.svn import mapping
20 supported_features = set()
23 class BzrSvnMappingv4(mapping.BzrSvnMapping):
24 """Mapping between Subversion and Bazaar, introduced in bzr-svn 0.5.
26 Tries to use revision properties when possible.
28 TODO: Add variable with required features.
30 revid_prefix = "svn-v4"
31 upgrade_suffix = "-svn4"
36 self.revprops = mapping.BzrSvnMappingRevProps()
37 self.fileprops = mapping.BzrSvnMappingFileProps(self.name)
40 def supports_roundtripping():
44 def revision_id_bzr_to_foreign(cls, revid):
45 assert isinstance(revid, str)
47 if not revid.startswith(cls.revid_prefix):
48 raise errors.InvalidRevisionId(revid, "")
51 (version, uuid, branch_path, srevnum) = revid.split(":")
53 raise errors.InvalidRevisionId(revid, "")
55 branch_path = mapping.unescape_svn_path(branch_path)
57 return (uuid, branch_path, int(srevnum), cls())
59 def revision_id_foreign_to_bzr(self, (uuid, revnum, path)):
60 return "svn-v4:%s:%s:%d" % (uuid, path, revnum)
62 def generate_file_id(self, uuid, revnum, branch, inv_path):
63 return "%d@%s:%s/%s" % (revnum, uuid, branch, inv_path.encode("utf-8"))
65 def is_branch(self, branch_path):
68 def is_tag(self, tag_path):
71 def __eq__(self, other):
72 return type(self) == type(other)
74 def get_rhs_parents(self, branch_path, svn_revprops, fileprops):
75 if svn_revprops.has_key(mapping.SVN_REVPROP_BZR_MAPPING_VERSION):
76 return self.revprops.get_rhs_parents(branch_path, svn_revprops, fileprops)
78 return self.fileprops.get_rhs_parents(branch_path, svn_revprops, fileprops)
80 def get_revision_id(self, branch_path, revprops, fileprops):
81 if revprops.has_key(mapping.SVN_REVPROP_BZR_MAPPING_VERSION):
82 return self.revprops.get_revision_id(branch_path, revprops, fileprops)
84 return self.fileprops.get_revision_id(branch_path, revprops, fileprops)
86 def import_text_parents(self, svn_revprops, fileprops):
87 if svn_revprops.has_key(mapping.SVN_REVPROP_BZR_TEXT_PARENTS):
88 return self.revprops.import_text_parents(svn_revprops, fileprops)
90 return self.fileprops.import_text_parents(svn_revprops, fileprops)
92 def import_fileid_map(self, svn_revprops, fileprops):
93 if svn_revprops.has_key(mapping.SVN_REVPROP_BZR_MAPPING_VERSION):
94 return self.revprops.import_fileid_map(svn_revprops, fileprops)
96 return self.fileprops.import_fileid_map(svn_revprops, fileprops)
98 def export_revision(self, can_use_custom_revprops, branch_root, timestamp, timezone, committer, revprops, revision_id,
99 revno, merges, fileprops):
100 if can_use_custom_revprops:
101 (svn_revprops, fileprops) = self.revprops.export_revision(can_use_custom_revprops, branch_root, timestamp, timezone, committer,
102 revprops, revision_id, revno, merges, fileprops)
103 svn_revprops[mapping.SVN_REVPROP_BZR_MAPPING_VERSION] = "4"
104 return (svn_revprops, fileprops)
106 return self.fileprops.export_revision(can_use_custom_revprops, branch_root, timestamp, timezone, committer,
107 revprops, revision_id, revno, merges, fileprops)
109 def export_fileid_map(self, can_use_custom_revprops, fileids, revprops, fileprops):
110 if can_use_custom_revprops:
111 self.revprops.export_fileid_map(can_use_custom_revprops, fileids, revprops, fileprops)
113 self.fileprops.export_fileid_map(can_use_custom_revprops, fileids, revprops, fileprops)
115 def export_text_parents(self, can_use_custom_revprops, text_parents, revprops, fileprops):
116 if can_use_custom_revprops:
117 self.revprops.export_text_parents(can_use_custom_revprops, text_parents, revprops, fileprops)
119 self.fileprops.export_text_parents(can_use_custom_revprops, text_parents, revprops, fileprops)
121 def import_revision(self, svn_revprops, fileprops, uuid, branch, revnum, rev):
122 if svn_revprops.has_key(mapping.SVN_REVPROP_BZR_REQUIRED_FEATURES):
123 features = set(svn_revprops[mapping.SVN_REVPROP_BZR_REQUIRED_FEATURES].split(","))
124 assert features.issubset(supported_features), "missing feature: %r" % features.difference(supported_features)
125 if svn_revprops.has_key(mapping.SVN_REVPROP_BZR_MAPPING_VERSION):
126 self.revprops.import_revision(svn_revprops, fileprops, uuid, branch, revnum, rev)
128 self.fileprops.import_revision(svn_revprops, fileprops, uuid, branch, revnum, rev)