Rev 507: Depend on the rebase plugin for svn-upgrade. in file:///data/jelmer/bzr-svn/0.4/

Jelmer Vernooij jelmer at samba.org
Thu Jul 12 09:28:33 BST 2007


At file:///data/jelmer/bzr-svn/0.4/

------------------------------------------------------------
revno: 507
revision-id: jelmer at samba.org-20070704142127-06cs6cj5i9osjc16
parent: jelmer at samba.org-20070703164254-bpp3awscz1jr52fa
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Wed 2007-07-04 16:21:27 +0200
message:
  Depend on the rebase plugin for svn-upgrade.
modified:
  README                         README-20051120210643-bd274a2fef9aed6a
  errors.py                      errors.py-20061226172623-w1sbj8ynpo0eojqp-1
  tests/test_upgrade.py          test_upgrade.py-20070106170128-64zt3eqggg4tng1c-1
  upgrade.py                     upgrade.py-20070106192108-0rakplee2lzah4gs-1
=== modified file 'README'
--- a/README	2007-06-24 18:14:04 +0000
+++ b/README	2007-07-04 14:21:27 +0000
@@ -24,6 +24,10 @@
 If you are running an older version of Python (under 2.5), you will also 
 need to have the pysqlite package installed.
 
+In order to be able to use the ``svn-upgrade`` command (for those 
+who used earlier versions of bzr-svn), you will need the bzr-rebase 
+plugin (http://people.samba.org/bzr/jelmer/bzr-rebase/trunk).
+
 ========
 Features
 ========

=== modified file 'errors.py'
--- a/errors.py	2007-06-17 16:10:27 +0000
+++ b/errors.py	2007-07-04 14:21:27 +0000
@@ -15,7 +15,8 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Subversion-specific errors and conversion of Subversion-specific errors."""
 
-from bzrlib.errors import BzrError, ConnectionReset, LockError, PermissionDenied
+from bzrlib.errors import (BzrError, ConnectionReset, LockError, 
+                           PermissionDenied, DependencyNotPresent)
 
 import svn.core
 
@@ -74,3 +75,9 @@
         BzrError.__init__(self)
         self.property = property
         self.msg = msg
+
+class RebaseNotPresent(DependencyNotPresent):
+    _fmt = "Unable to import bzr-rebase (required for svn-upgrade support): %(error)s"
+
+    def __init__(self, error):
+        DependencyNotPresent.__init__(self, 'bzr-rebase', error)

=== modified file 'tests/test_upgrade.py'
--- a/tests/test_upgrade.py	2007-06-24 14:08:49 +0000
+++ b/tests/test_upgrade.py	2007-07-04 14:21:27 +0000
@@ -19,13 +19,14 @@
 from bzrlib.bzrdir import BzrDir
 from bzrlib.errors import InvalidRevisionId
 from bzrlib.repository import Repository
-from bzrlib.tests import TestCase, TestCaseWithTransport
+from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
+from errors import RebaseNotPresent
 from fileids import generate_svn_file_id
 from format import get_rich_root_format
 from repository import MAPPING_VERSION
 from tests import TestCaseWithSubversionRepository
-from upgrade import (change_revision_parent, upgrade_repository, upgrade_branch,
+from upgrade import (upgrade_repository, upgrade_branch,
                      UpgradeChangesContent, parse_legacy_revision_id,
                      create_upgraded_revid)
 
@@ -65,28 +66,19 @@
                          create_upgraded_revid("bla-svn1-upgrade"))
 
 
-class ConversionTests(TestCaseWithTransport):
-    def test_simple(self):
-        wt = self.make_branch_and_tree('.')
-        b = wt.branch
-        file('hello', 'w').write('hello world')
-        wt.add('hello')
-        wt.commit(message='add hello', rev_id="bla")
-        file('hello', 'w').write('world')
-        wt.commit(message='change hello', rev_id="bloe")
-        wt.set_last_revision("bla")
-        b.set_revision_history(["bla"])
-        file('hello', 'w').write('world')
-        wt.commit(message='change hello', rev_id="bla2")
-        
-        newrev = change_revision_parent(wt.branch.repository, "bla2", "bla4", 
-                                        ["bloe"])
-        self.assertEqual("bla4", newrev)
-        self.assertTrue(wt.branch.repository.has_revision(newrev))
-        self.assertEqual(["bloe"], wt.branch.repository.revision_parents(newrev))
+def skip_no_rebase(unbound):
+    def check_error(self, *args, **kwargs):
+        try:
+            return unbound(self, *args, **kwargs)
+        except RebaseNotPresent, e:
+            raise TestSkipped(e)
+    check_error.__doc__ = unbound.__doc__
+    check_error.__name__ = unbound.__name__
+    return check_error
 
 
 class UpgradeTests(TestCaseWithSubversionRepository):
+    @skip_no_rebase
     def test_no_custom(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/a': 'b'})
@@ -109,6 +101,7 @@
 
         self.assertTrue(newrepos.has_revision(oldrepos.generate_revision_id(1, "", "none")))
 
+    @skip_no_rebase
     def test_single_custom(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/a': 'b'})
@@ -134,6 +127,7 @@
         self.assertTrue([oldrepos.generate_revision_id(1, "", "none")],
                         newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION))
 
+    @skip_no_rebase
     def test_single_keep_parent_fileid(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/a': 'b'})
@@ -161,7 +155,7 @@
         self.assertEqual(generate_svn_file_id(oldrepos.uuid, 1, "", "a"), 
                          tree.inventory.path2id("b"))
 
-
+    @skip_no_rebase
     def test_single_custom_continue(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/a': 'b', 'dc/b': 'c'})
@@ -197,6 +191,7 @@
         self.assertTrue([oldrepos.generate_revision_id(1, "", "none")],
                         newrepos.revision_parents("customrev-svn%d-upgrade" % MAPPING_VERSION))
 
+    @skip_no_rebase
     def test_more_custom(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/a': 'b'})
@@ -231,6 +226,7 @@
         self.assertTrue(["customrev-svn%d-upgrade" % MAPPING_VERSION],
                         newrepos.revision_parents("anotherrev-svn%d-upgrade" % MAPPING_VERSION))
 
+    @skip_no_rebase
     def test_more_custom_branch(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/a': 'b'})
@@ -257,6 +253,7 @@
                           "anotherrev-svn%d-upgrade" % MAPPING_VERSION
                           ], b.revision_history())
 
+    @skip_no_rebase
     def test_branch_none(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/a': 'b'})
@@ -280,6 +277,7 @@
         self.assertEqual(["blarev", "customrev", "anotherrev"],
                 b.revision_history())
 
+    @skip_no_rebase
     def test_raise_incompat(self):
         repos_url = self.make_client("a", "dc")
         self.build_tree({'dc/d': 'e'})

=== modified file 'upgrade.py'
--- a/upgrade.py	2007-06-24 14:08:49 +0000
+++ b/upgrade.py	2007-07-04 14:21:27 +0000
@@ -15,11 +15,11 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Upgrading revisions made with older versions of the mapping."""
 
-from bzrlib.config import Config
 from bzrlib.errors import BzrError, InvalidRevisionId
 from bzrlib.trace import mutter
 import bzrlib.ui as ui
 
+from errors import RebaseNotPresent
 from revids import (generate_svn_revision_id, parse_svn_revision_id, 
                     MAPPING_VERSION,  unescape_svn_path)
 from scheme import BranchingScheme
@@ -32,91 +32,6 @@
         self.revid = revid
 
 
-# Change the parent of a revision
-def change_revision_parent(repository, oldrevid, newrevid, new_parents):
-    """Create a copy of a revision with different parents.
-
-    :param repository: Repository in which the revision is present.
-    :param oldrevid: Revision id of the revision to copy.
-    :param newrevid: Revision id of the revision to create.
-    :param new_parents: Revision ids of the new parent revisions.
-    """
-    assert isinstance(new_parents, list)
-    mutter('creating copy %r of %r with new parents %r' % (newrevid, oldrevid, new_parents))
-    oldrev = repository.get_revision(oldrevid)
-
-    builder = repository.get_commit_builder(branch=None, parents=new_parents, 
-                                  config=Config(),
-                                  committer=oldrev.committer,
-                                  timestamp=oldrev.timestamp,
-                                  timezone=oldrev.timezone,
-                                  revprops=oldrev.properties,
-                                  revision_id=newrevid)
-
-    # Check what new_ie.file_id should be
-    # use old and new parent inventories to generate new_id map
-    old_parents = oldrev.parent_ids
-    new_id = {}
-    for (oldp, newp) in zip(old_parents, new_parents):
-        oldinv = repository.get_revision_inventory(oldp)
-        newinv = repository.get_revision_inventory(newp)
-        for path, ie in oldinv.iter_entries():
-            if newinv.has_filename(path):
-                new_id[ie.file_id] = newinv.path2id(path)
-
-    i = 0
-    class MapTree:
-        def __init__(self, oldtree, map):
-            self.oldtree = oldtree
-            self.map = map
-
-        def old_id(self, file_id):
-            for x in self.map:
-                if self.map[x] == file_id:
-                    return x
-            return file_id
-
-        def get_file_sha1(self, file_id, path=None):
-            return self.oldtree.get_file_sha1(file_id=self.old_id(file_id), 
-                                              path=path)
-
-        def get_file(self, file_id):
-            return self.oldtree.get_file(self.old_id(file_id=file_id))
-
-        def is_executable(self, file_id, path=None):
-            return self.oldtree.is_executable(self.old_id(file_id=file_id), 
-                                              path=path)
-
-    oldtree = MapTree(repository.revision_tree(oldrevid), new_id)
-    oldinv = repository.get_revision_inventory(oldrevid)
-    total = len(oldinv)
-    pb = ui.ui_factory.nested_progress_bar()
-    transact = repository.get_transaction()
-    try:
-        for path, ie in oldinv.iter_entries():
-            pb.update('upgrading file', i, total)
-            i += 1
-            new_ie = ie.copy()
-            if new_ie.revision == oldrevid:
-                new_ie.revision = None
-            def lookup(file_id):
-                try:
-                    return new_id[file_id]
-                except KeyError:
-                    return file_id
-
-            new_ie.file_id = lookup(new_ie.file_id)
-            new_ie.parent_id = lookup(new_ie.parent_id)
-            builder.record_entry_contents(new_ie, 
-                   map(repository.get_revision_inventory, new_parents), 
-                   path, oldtree)
-    finally:
-        pb.finished()
-
-    builder.finish_inventory()
-    return builder.commit(oldrev.message)
-
-
 def parse_legacy_revision_id(revid):
     """Try to parse a legacy Subversion revision id.
     
@@ -201,6 +116,10 @@
                         all revisions.
     :param allow_change: Allow changes to mappings.
     """
+    try:
+        from bzrlib.plugins.rebase.rebase import change_revision_parent
+    except ImportError, e:
+        raise RebaseNotPresent(e)
     needed_revs = []
     needs_upgrading = []
     new_parents = {}




More information about the bazaar-commits mailing list