Rev 1703: Implement svn-set-revprops. in file:///data/jelmer/bzr-svn/trunk/
Jelmer Vernooij
jelmer at samba.org
Fri Aug 29 20:02:28 BST 2008
At file:///data/jelmer/bzr-svn/trunk/
------------------------------------------------------------
revno: 1703
revision-id: jelmer at samba.org-20080829190227-wml9s50qb4hmfbvp
parent: jelmer at samba.org-20080829172452-jtz399rc7swc7eye
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Fri 2008-08-29 21:02:27 +0200
message:
Implement svn-set-revprops.
modified:
TODO todo-20060729211917-2kpobww0zyvvo0j2-1
__init__.py __init__.py-20051008155114-eae558e6cf149e1d
branch.py svnbranch.py-20051017135706-11c749eb0dab04a7
mapping.py mapping.py-20080128201303-6cp01phc0dmc0kiv-1
mapping3/__init__.py __init__.py-20080502174630-9324zh25kka98vlw-1
upgrade.py upgrade.py-20070106192108-0rakplee2lzah4gs-1
=== modified file 'TODO'
--- a/TODO 2008-08-29 11:43:07 +0000
+++ b/TODO 2008-08-29 19:02:27 +0000
@@ -2,6 +2,9 @@
- refuse to set fileprops on repository on which revprops have been set
- skip looking for fileprops if revprops have been found in earlier revisions
- implement set-svn-revprops command
+ - iterate over all revisions in history and:
+ - check if a revision is a bzr revision
+ - if it is, upgrade it
- implement layout functions, including command
todo:
=== modified file '__init__.py'
--- a/__init__.py 2008-08-29 15:18:10 +0000
+++ b/__init__.py 2008-08-29 19:02:27 +0000
@@ -34,8 +34,9 @@
from bzrlib import log
from bzrlib.bzrdir import BzrDirFormat, format_registry
from bzrlib.errors import BzrError
-from bzrlib.commands import Command, register_command, display_command, Option
+from bzrlib.commands import Command, register_command, display_command
from bzrlib.help_topics import topic_registry
+from bzrlib.option import Option, RegistryOption
from bzrlib.revisionspec import SPEC_TYPES
from bzrlib.trace import warning, mutter
from bzrlib.transport import register_lazy_transport, register_transport_proto
@@ -235,7 +236,7 @@
incremental=False):
from bzrlib.bzrdir import BzrDir
from bzrlib.errors import BzrCommandError, NoRepositoryPresent
- from bzrlib import urlutils
+ from bzrlib import osutils, urlutils
from bzrlib.plugins.svn.convert import convert_repository
from bzrlib.plugins.svn.mapping3 import repository_guess_scheme
from bzrlib.plugins.svn.repository import SvnRepository
@@ -299,7 +300,6 @@
keep=keep, incremental=incremental)
if tmp_repos is not None:
- from bzrlib import osutils
osutils.rmtree(tmp_repos)
finally:
from_repos.unlock()
@@ -313,11 +313,16 @@
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
takes_args = ['from_repository?']
- takes_options = ['verbose']
+ takes_options = ['verbose', RegistryOption('mapping',
+ help="New mapping to upgrade to.",
+ registry=mapping_registry,
+ title="Subversion mapping",
+ value_switches=True)]
@display_command
- def run(self, from_repository=None, verbose=False):
+ def run(self, from_repository=None, verbose=False, mapping=None):
from bzrlib.plugins.svn.upgrade import (upgrade_branch,
upgrade_workingtree)
from bzrlib.branch import Branch
@@ -346,11 +351,18 @@
else:
from_repository = Repository.open(from_repository)
+ if mapping is None:
+ mapping = get_default_mapping()
+
+ new_mapping = mapping.from_repository(from_repository)
+
if wt_to is not None:
renames = upgrade_workingtree(wt_to, from_repository,
+ new_mapping=new_mapping,
allow_changes=True, verbose=verbose)
else:
renames = upgrade_branch(branch_to, from_repository,
+ new_mapping=new_mapping,
allow_changes=True, verbose=verbose)
if renames == {}:
@@ -489,10 +501,23 @@
To change these permissions, edit the hooks/pre-revprop-change
file in the Subversion repository.
"""
- takes_args = ['location']
+ takes_args = ['location?']
+ from bzrlib.plugins.svn.mapping import mapping_registry
+ takes_options = [RegistryOption('mapping',
+ help="New mapping to upgrade to.",
+ registry=mapping_registry,
+ title="Subversion mapping",
+ value_switches=True)]
- def run(self, location="."):
- raise NotImplementedError(self.run)
+ def run(self, location=".", mapping=None):
+ from bzrlib.repository import Repository
+ from bzrlib.plugins.svn.upgrade import set_revprops
+ from bzrlib.plugins.svn.mapping import get_default_mapping
+ repos = Repository.open(location)
+ if mapping is None:
+ mapping = get_default_mapping()
+ new_mapping = mapping.from_repository(repos)
+ set_revprops(repos, new_mapping)
register_command(cmd_svn_set_revprops)
=== modified file 'branch.py'
--- a/branch.py 2008-08-29 16:20:10 +0000
+++ b/branch.py 2008-08-29 19:02:27 +0000
@@ -505,7 +505,7 @@
def __get_matchingbzrdir(self):
"""See BranchFormat.__get_matchingbzrdir()."""
- from remote import SvnRemoteFormat
+ from bzrlib.plugins.svn.remote import SvnRemoteFormat
return SvnRemoteFormat()
_matchingbzrdir = property(__get_matchingbzrdir)
=== modified file 'mapping.py'
--- a/mapping.py 2008-08-29 16:00:52 +0000
+++ b/mapping.py 2008-08-29 19:02:27 +0000
@@ -266,6 +266,10 @@
return cls()
@classmethod
+ def from_revprops(cls, revprops):
+ return cls()
+
+ @classmethod
def supports_roundtripping(cls):
"""Whether this mapping supports roundtripping.
"""
@@ -670,13 +674,13 @@
mapping_registry.register('v1', BzrSvnMappingv1,
'Original bzr-svn mapping format')
mapping_registry.register('v2', BzrSvnMappingv2,
- 'Second format')
+ 'Second format (bzr-svn 0.3.x)')
mapping_registry.register_lazy('v3', 'bzrlib.plugins.svn.mapping3',
'BzrSvnMappingv3FileProps',
- 'Default third format')
+ 'Default third format (bzr-svn 0.4.x)')
mapping_registry.register_lazy('v4', 'bzrlib.plugins.svn.mapping4',
'BzrSvnMappingv4',
- 'Fourth format')
+ 'Fourth format (bzr-svn 0.5.x)')
mapping_registry.set_default('v3')
def parse_mapping_name(name):
@@ -700,7 +704,18 @@
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:
+ ret = BzrSvnMapping.from_revprops(revprops)
+ if ret is not None:
+ 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 None
+
=== modified file 'mapping3/__init__.py'
--- a/mapping3/__init__.py 2008-08-29 16:00:52 +0000
+++ b/mapping3/__init__.py 2008-08-29 19:02:27 +0000
@@ -233,6 +233,10 @@
self.scheme = scheme
self.guessed_scheme = guessed_scheme
+ @classmethod
+ def from_revprops(cls, revprops):
+ return None
+
def get_mandated_layout(self, repository):
return SchemeDerivedLayout(repository, self.scheme)
=== modified file 'upgrade.py'
--- a/upgrade.py 2008-08-29 16:00:52 +0000
+++ b/upgrade.py 2008-08-29 19:02:27 +0000
@@ -15,11 +15,15 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Upgrading revisions made with older versions of the mapping."""
+from bzrlib import ui
from bzrlib.errors import BzrError, InvalidRevisionId
+from bzrlib.revision import Revision
from bzrlib.trace import info
import itertools
+from bzrlib.plugins.svn import changes, logwalker, mapping
from bzrlib.plugins.svn.mapping import parse_revision_id
+from bzrlib.plugins.svn.repository import RevisionMetadata
class UpgradeChangesContent(BzrError):
"""Inconsistency was found upgrading the mapping of a revision."""
@@ -44,19 +48,22 @@
return revid + mapping_suffix + upgrade_suffix
-def upgrade_workingtree(wt, svn_repository, allow_changes=False, verbose=False):
+def upgrade_workingtree(wt, svn_repository, new_mapping=None,
+ allow_changes=False, verbose=False):
"""Upgrade a working tree.
:param svn_repository: Subversion repository object
"""
- renames = upgrade_branch(wt.branch, svn_repository, allow_changes=allow_changes, verbose=verbose)
+ renames = upgrade_branch(wt.branch, svn_repository, new_mapping=new_mapping,
+ allow_changes=allow_changes, verbose=verbose)
last_revid = wt.branch.last_revision()
wt.set_parent_trees([(last_revid, wt.branch.repository.revision_tree(last_revid))])
# TODO: Should also adjust file ids in working tree if necessary
return renames
-def upgrade_branch(branch, svn_repository, allow_changes=False, verbose=False):
+def upgrade_branch(branch, svn_repository, new_mapping=None,
+ allow_changes=False, verbose=False):
"""Upgrade a branch to the current mapping version.
:param branch: Branch to upgrade.
@@ -66,7 +73,8 @@
"""
revid = branch.last_revision()
renames = upgrade_repository(branch.repository, svn_repository,
- revision_id=revid, allow_changes=allow_changes, verbose=verbose)
+ revision_id=revid, new_mapping=new_mapping,
+ allow_changes=allow_changes, verbose=verbose)
if len(renames) > 0:
branch.generate_revision_history(renames[revid])
return renames
@@ -208,3 +216,42 @@
finally:
repository.unlock()
svn_repository.unlock()
+
+
+def set_revprops(repository, new_mapping, from_revnum=0, to_revnum=None):
+ """Set bzr-svn revision properties for existing bzr-svn revisions.
+
+ :param repository: Subversion Repository object.
+ :param new_mapping: Mapping to upgrade to
+ """
+ if to_revnum is None:
+ to_revnum = repository.get_latest_revnum()
+ graph = repository.get_graph()
+ assert from_revnum <= to_revnum
+ pb = ui.ui_factory.nested_progress_bar()
+ try:
+ for (paths, revnum, revprops) in repository._log.iter_changes(None, to_revnum, from_revnum, pb=pb):
+ # Find the root path of the change
+ bp = changes.changes_root(paths.keys())
+ # FIXME: Check revprops for branch root
+ if bp is None:
+ fileprops = {}
+ else:
+ fileprops = logwalker.lazy_dict({}, repository.branchprop_list.get_properties, bp, revnum)
+ old_mapping = mapping.find_mapping(revprops, fileprops)
+ if old_mapping is None:
+ continue
+ rev = Revision(old_mapping.get_revision_id(bp, revprops, fileprops)[1])
+ old_mapping.import_revision(revprops, fileprops, repository.uuid, bp, revnum, rev)
+ revno = graph.find_distance_to_null(rev.revision_id, [])
+ (new_revprops, new_fileprops) = new_mapping.export_revision(True, bp, rev.timestamp, rev.timezone, rev.committer, rev.properties, rev.revision_id, revno, old_mapping.get_rhs_parents(bp, revprops, fileprops), fileprops)
+ new_mapping.export_fileid_map(True, old_mapping.import_fileid_map(revprops, fileprops),
+ new_revprops, new_fileprops)
+ new_mapping.export_text_parents(True, old_mapping.import_text_parents(revprops, fileprops),
+ new_revprops, new_fileprops)
+ # new_mapping.export_message
+ assert new_fileprops == fileprops, "expected %r got %r" % (new_fileprops, fileprops)
+ for k, v in new_revprops.items():
+ repository.transport.change_rev_prop(revnum, k, v)
+ finally:
+ pb.finished()
More information about the bazaar-commits
mailing list