Rev 624: Saner names for various mapping functions. in file:///data/jelmer/bzr-svn/revprops/
Jelmer Vernooij
jelmer at samba.org
Fri Feb 1 20:18:50 GMT 2008
At file:///data/jelmer/bzr-svn/revprops/
------------------------------------------------------------
revno: 624
revision-id:jelmer at samba.org-20080201201849-wydiruou79o3vcrc
parent: jelmer at samba.org-20080201193133-zrbbnqo4puizgg0d
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: revprops
timestamp: Fri 2008-02-01 21:18:49 +0100
message:
Saner names for various mapping functions.
modified:
commit.py commit.py-20060607190346-qvq128wgfubhhgm2-1
fetch.py fetch.py-20060625004942-x2lfaib8ra707a8p-1
mapping.py mapping.py-20080128201303-6cp01phc0dmc0kiv-1
repository.py repository.py-20060306123302-1f8c5069b3fe0265
=== modified file 'commit.py'
--- a/commit.py 2008-02-01 19:31:33 +0000
+++ b/commit.py 2008-02-01 20:18:49 +0000
@@ -30,7 +30,7 @@
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
@@ -107,17 +107,6 @@
(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)
@@ -129,10 +118,12 @@
# 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:
@@ -404,18 +395,16 @@
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 += list(_dir_process_file_id(self.old_inv, self.new_inventory, "", self.new_inventory.root.file_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
+ fileids[""] = 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
+
+ export_fileid_map(fileids, self._svn_revprops, self._svnprops)
try:
existing_bp_parts = _check_dirs_exist(self.repository.transport,
=== modified file 'fetch.py'
--- a/fetch.py 2008-02-01 18:52:36 +0000
+++ b/fetch.py 2008-02-01 20:18:49 +0000
@@ -121,9 +121,7 @@
rev = Revision(revision_id=revid, parent_ids=self._get_parent_ids())
svn_revprops = self.source._log._get_transport().revprop_list(self.revnum)
- default_mapping.parse_svn_revision(svn_revprops,
- self._branch_fileprops.get,
- rev)
+ default_mapping.import_revision(svn_revprops, self._branch_fileprops.get, rev)
return rev
=== modified file 'mapping.py'
--- a/mapping.py 2008-02-01 19:31:33 +0000
+++ b/mapping.py 2008-02-01 20:18:49 +0000
@@ -281,7 +281,7 @@
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.
@@ -291,7 +291,7 @@
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):
@@ -308,15 +308,37 @@
raise NotImplementedError(self.get_rhs_ancestors)
@staticmethod
- def get_fileid_map(revprops, get_branch_file_property):
- raise NotImplementedError(self.get_fileid_map)
-
- @staticmethod
- def generate_svn_revision(rev):
+ 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 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):
@@ -363,6 +385,8 @@
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.
@@ -418,7 +442,7 @@
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)
@@ -444,7 +468,7 @@
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 {}
@@ -500,7 +524,7 @@
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(
@@ -521,12 +545,33 @@
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)
@@ -534,13 +579,13 @@
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):
@@ -553,6 +598,14 @@
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):
=== modified file 'repository.py'
--- a/repository.py 2008-02-01 19:07:48 +0000
+++ b/repository.py 2008-02-01 20:18:49 +0000
@@ -345,7 +345,7 @@
(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)
)
@@ -465,7 +465,7 @@
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
@@ -497,32 +497,15 @@
# 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):
More information about the bazaar-commits
mailing list