from copy import deepcopy
from cStringIO import StringIO
from errors import ChangesRootLHSHistory, MissingPrefix, RevpropChangeFailed
-from mapping import (SVN_PROP_BZR_FILEIDS, SVN_REVPROP_BZR_FILEIDS)
+from mapping import default_mapping
from repository import (SvnRepositoryFormat, SvnRepository)
import urllib
(self.base_path, self.base_revnum, self.base_scheme) = \
repository.lookup_revision_id(self.base_revid)
- # Determine revisions merged in this one
- merges = filter(lambda x: x != self.base_revid, parents)
-
- if len(merges) > 0:
- self._record_merges(merges)
-
- # Set appropriate property if revision id was specified by
- # caller
- if revision_id is not None:
- self._record_revision_id(revision_id)
-
if old_inv is None:
if self.base_revid is None:
self.old_inv = Inventory(root_id=None)
# so allow None as well.
assert self.old_inv.revision_id in (None, self.base_revid)
+ # Determine revisions merged in this one
+ merges = filter(lambda x: x != self.base_revid, parents)
+
self.modified_files = {}
self.modified_dirs = set()
- (self._svn_revprops, self._svnprops) = default_mapping.generate_svn_revision(timestamp, timezone, committer, revprops, revision_id)
- self._svnprops[SVN_PROP_BZR_FILEIDS] = ""
+ (self._svn_revprops, self._svnprops) = default_mapping.export_revision(timestamp, timezone, committer, revprops, revision_id, merges)
def mutter(self, text):
if 'commit' in debug.debug_flags:
child_ie.file_id in self.modified_dirs):
_dir_process_file_id(old_inv, new_inv, new_child_path, child_ie.file_id)
- fileids = []
+ fileids = {}
if (self.old_inv.root is None or
self.new_inventory.root.file_id != self.old_inv.root.file_id):
- fileids.append((self.new_inventory.root.file_id, ""))
+ fileids[""] = self.new_inventory.root.file_id
- fileids += list(_dir_process_file_id(self.old_inv, self.new_inventory, "", self.new_inventory.root.file_id))
+ for id, path in _dir_process_file_id(self.old_inv, self.new_inventory, "", self.new_inventory.root.file_id):
+ fileids[path] = id
- if fileids != []:
- file_id_text = "".join(["%s\t%s\n" % (urllib.quote(path), file_id) for (file_id, path) in fileids])
- self._svn_revprops[SVN_REVPROP_BZR_FILEIDS] = file_id_text
- self._svnprops[SVN_PROP_BZR_FILEIDS] = file_id_text
+ export_fileid_map(fileids, self._svn_revprops, self._svnprops)
try:
existing_bp_parts = _check_dirs_exist(self.repository.transport,
raise NotImplementedError(self.generate_file_id)
@staticmethod
- def parse_svn_revision(revprops, get_branch_file_property, rev):
+ def import_revision(revprops, get_branch_file_property, rev):
"""Update a Revision object from Subversion revision and branch
properties.
path.
:param rev: Revision object to import data into.
"""
- raise NotImplementedError(self.parse_svn_revision)
+ raise NotImplementedError(self.import_revision)
@staticmethod
def get_rhs_parents(revprops, get_branch_file_property, scheme):
raise NotImplementedError(self.get_rhs_ancestors)
@staticmethod
- def get_fileid_map(revprops, get_branch_file_property):
- raise NotImplementedError(self.get_fileid_map)
+ def import_fileid_map(revprops, get_branch_file_property):
+ """Obtain the file id map for a revision from the properties.
+
+ """
+ raise NotImplementedError(self.import_fileid_map)
@staticmethod
- def generate_svn_revision(rev):
+ def export_fileid_map(fileids, revprops, fileprops):
+ """Adjust the properties for a file id map.
+
+ :param fileids: Dictionary
+ :param revprops: Subversion revision properties
+ :param fileprops: File properties
+ """
+ if fileids != {}:
+ file_id_text = generate_fileid_property(fileids)
+ revprops[SVN_REVPROP_BZR_FILEIDS] = file_id_text
+ fileprops[SVN_PROP_BZR_FILEIDS] = file_id_text
+ else:
+ fileprops[SVN_PROP_BZR_FILEIDS] = ""
+
+ @staticmethod
+ def export_revision(rev):
"""Determines the revision properties and branch root file
properties.
"""
- raise NotImplementedError(self.generate_svn_revision)
+ raise NotImplementedError(self.export_revision)
+
+ @staticmethod
+ def get_revision_id(revprops, get_branch_file_property, scheme):
+ raise NotImplementedError(self.get_revision_id)
class BzrSvnMappingv1(BzrSvnMapping):
ret[urllib.unquote(path)] = osutils.safe_file_id(key)
return ret
+def generate_fileid_property(fileids):
+ return "".join(["%s\t%s\n" % (urllib.quote(path), file_id) for (path, file_id) in fileids.items()])
class BzrSvnMappingv3(BzrSvnMapping):
"""The third version of the mappings as used in the 0.4.x series.
return osutils.safe_file_id(ret)
@staticmethod
- def parse_svn_revision(svn_revprops, get_branch_file_property, rev):
+ def import_revision(svn_revprops, get_branch_file_property, rev):
parse_svn_revprops(svn_revprops, rev)
parse_revision_metadata(
get_branch_file_property(SVN_PROP_BZR_REVISION_INFO, ""), rev)
return ancestry
@classmethod
- def get_fileid_map(cls, svn_revprops, get_branch_file_property):
+ def import_fileid_map(cls, svn_revprops, get_branch_file_property):
fileids = get_branch_file_property(SVN_PROP_BZR_FILEIDS, None)
if fileids is None:
return {}
self._svn_revprops[SVN_REVPROP_BZR_MERGE] = "".join(map(lambda x: x + "\n", merges))
@staticmethod
- def generate_svn_revision(timestamp, timezone, committer, message, revprops):
+ def export_revision(timestamp, timezone, committer, message, revprops, revision_id, merges):
# Keep track of what Subversion properties to set later on
fileprops = {}
fileprops[SVN_PROP_BZR_REVISION_INFO] = generate_revision_metadata(
svn_revprops[SVN_REVPROP_BZR_ROOT] = self.branch.get_branch_path()
svn_revprops[svn.core.SVN_PROP_REVISION_LOG] = message.encode("utf-8")
+ if len(merges) > 0:
+ self._record_merges(merges)
+
+ # Set appropriate property if revision id was specified by
+ # caller
+ if revision_id is not None:
+ self._record_revision_id(revision_id)
+
return (svn_revprops, fileprops)
+ @staticmethod
+ def get_revision_id(revprops, get_branch_file_property, scheme):
+ # Lookup the revision from the bzr:revision-id-vX property
+ lines = get_branch_file_property(SVN_PROP_BZR_REVISION_ID+str(scheme), None)
+ if lines is None:
+ return (None, None)
+
+ try:
+ return parse_revid_property(lines.splitlines()[-1])
+ except errors.InvalidPropertyValue, e:
+ mutter(str(e))
+ return (None, None)
+
class BzrSvnMappingv4(BzrSvnMappingv3):
@staticmethod
- def parse_svn_revision(svn_revprops, get_branch_file_property, rev):
+ def import_revision(svn_revprops, get_branch_file_property, rev):
parse_svn_revprops(svn_revprops, rev)
if svn_revprops.get(SVN_REVPROP_BZR_MAPPING_VERSION) == str(MAPPING_VERSION):
parse_bzr_svn_revprops(svn_revprops, rev)
parse_revision_metadata(get_branch_file_property(SVN_PROP_BZR_REVISION_INFO, ""), rev)
@classmethod
- def get_fileid_map(cls, svn_revprops, get_branch_file_property):
+ def import_fileid_map(cls, svn_revprops, get_branch_file_property):
if svn_revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
if not svn_revprops.has_key(SVN_REVPROP_BZR_FILEIDS):
return {}
return parse_fileid_property(svn_revprops[SVN_REVPROP_BZR_FILEIDS])
else:
- return BzrSvnMappingv3.get_fileid_map(svn_revprops, get_branch_file_property)
+ return BzrSvnMappingv3.import_fileid_map(svn_revprops, get_branch_file_property)
@classmethod
def get_rhs_parents(cls, svn_revprops, get_branch_file_property, scheme):
else:
return BzrSvnMappingv3.get_rhs_parents(svn_revprops, get_branch_file_property, scheme)
+ @staticmethod
+ def get_revision_id(revprops, get_branch_file_property, scheme):
+ if revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
+ if revprops[SVN_REVPROP_BZR_ROOT] == path:
+ revid = revprops[SVN_REVPROP_BZR_REVISION_ID]
+ return (FIXME, revid)
+ return BzrSvnMappingv3.get_revision_id(revprops, get_branch_file_property, scheme)
+
class BzrSvnMappingRegistry(registry.Registry):
def register(self, key, factory, help):
(path, revnum, _) = self.lookup_revision_id(revid)
svn_revprops = self.transport.revprop_list(revnum)
- return default_mapping.get_fileid_map(svn_revprops,
+ return default_mapping.import_fileid_map(svn_revprops,
lambda name, default: self.branchprop_list.get_changed_property(path, revnum, name, default)
)
rev = LazySvnRevision(revision_id=revision_id, parent_ids=parent_ids)
svn_revprops = self.transport.revprop_list(revnum)
- default_mapping.parse_svn_revision(svn_revprops,
+ default_mapping.import_revision(svn_revprops,
lambda name, default: self.branchprop_list.get_changed_property(path, revnum, name, default), rev)
return rev
# See if there is a bzr:revision-id revprop set
revprops = self._log._get_transport().revprop_list(revnum)
- if revprops.has_key(SVN_REVPROP_BZR_MAPPING_VERSION):
- if revprops[SVN_REVPROP_BZR_ROOT] == path:
- revid = revprops[SVN_REVPROP_BZR_REVISION_ID]
- else:
- revid = generate_svn_revision_id(self.uuid, revnum, path,
- scheme)
- else:
- # Lookup the revision from the bzr:revision-id-vX property
- line = self.branchprop_list.get_property_diff(path, revnum,
- SVN_PROP_BZR_REVISION_ID+str(scheme)).strip("\n")
- # Or generate it
- if line == "":
- revid = default_mapping.generate_revision_id(
- self.uuid, revnum, path, scheme)
- else:
- try:
- (bzr_revno, revid) = parse_revid_property(line)
- self.revmap.insert_revid(revid, path, revnum, revnum,
- scheme, bzr_revno)
- except errors.InvalidPropertyValue, e:
- mutter(str(e))
- revid = default_mapping.generate_revision_id(self.uuid,
- revnum, path, scheme)
- self.revmap.insert_revid(revid, path, revnum, revnum,
- scheme)
-
+ (bzr_revno, revid) = default_mapping.get_revision_id(revprops,
+ lambda name, default: self.branchprop_list.get_changed_property(path, revnum, name, default),
+ scheme)
+ # Or generate it
+ if revid is None:
+ revid = default_mapping.generate_revision_id(
+ self.uuid, revnum, path, scheme)
+ self.revmap.insert_revid(revid, path, revnum, revnum,
+ scheme, bzr_revno)
return revid
def lookup_revision_id(self, revid, scheme=None):