Rev 376: Initial work on an upgrade command that can replace old mapped SVN revisions in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev

Jelmer Vernooij jelmer at samba.org
Sat Jan 6 19:32:11 GMT 2007


------------------------------------------------------------
revno: 376
revision-id: jelmer at samba.org-20070106193150-ubn5wjhot0mqo9et
parent: jelmer at samba.org-20070106165818-4mt4qbtnyn6340h0
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Sat 2007-01-06 20:31:50 +0100
message:
  Initial work on an upgrade command that can replace old mapped SVN revisions 
  with more recent ones. 
  
  This is useful, for example, you have a couple of custom bzr revisions on 
  top of a Subversion branch and need to merge new revisions after upgrading 
  bzr-svn.
  
  This commit adds a simple utility function that can copy a revision but 
  changes its parent ids.
  
  -------------- This line and the following will be ignored --------------
  
  added:
    tests/test_upgrade.py
    upgrade.py
  modified:
    tests/__init__.py
  unknown:
    .coverage
    __init__.py,cover
    _trial_temp
    branch.py,cover
    branchprops.py,cover
    bzr_svn.egg-info
    checkout.py,cover
    checkouts
    commit.py,cover
    convert-all.diff
    convert.py,cover
    coverage.py
    coverage.py,cover
    errors.py,cover
    fetch.py,cover
    fileids.py,cover
    format.py,cover
    idmap
    jelmer.diff
    logwalker.py,cover
    p1.diff
    properfix.diff
    repository.py,cover
    scheme.py,cover
    setup.py,cover
    transport.py,cover
    tree.py,cover
    upgrade.py,cover
    x
    xu
    xx
    yp
    tests/apache2.conf
    tests/ra_backends.py
    tests/test_branchprops1.py
    tests/test_fileids.py.orig
    tests/test_fileids.py.rej
    tests/test_logwalker.py.rej
    tests/tmpapache
added:
  tests/test_upgrade.py          test_upgrade.py-20070106170128-64zt3eqggg4tng1c-1
  upgrade.py                     upgrade.py-20070106192108-0rakplee2lzah4gs-1
modified:
  tests/__init__.py              __init__.py-20060508151940-e9f4d914801a2535
=== added file 'tests/test_upgrade.py'
--- a/tests/test_upgrade.py	1970-01-01 00:00:00 +0000
+++ b/tests/test_upgrade.py	2007-01-06 19:31:50 +0000
@@ -0,0 +1,54 @@
+# Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from bzrlib.bzrdir import BzrDir
+from bzrlib.errors import NoRepositoryPresent
+from bzrlib.tests import TestCase, TestCaseWithTransport
+
+from repository import SvnRepository
+from tests import TestCaseWithSubversionRepository
+from upgrade import (change_revision_parent, upgrade_branch, 
+                     UpgradeChangesContent)
+
+class TestUpgradeChangesContent(TestCase):
+    def test_init(self):
+        x = UpgradeChangesContent("revisionx")
+        self.assertEqual("revisionx", x.revid)
+
+
+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", ["bloe"])
+        self.assertNotEqual(None, newrev)
+        self.assertNotEqual(newrev, "bla2")
+        self.assertTrue(wt.branch.repository.has_revision(newrev))
+        self.assertEqual(["bloe"], wt.branch.repository.revision_parents(newrev))
+
+
+class UpgradeTests(TestCase):
+    pass

=== added file 'upgrade.py'
--- a/upgrade.py	1970-01-01 00:00:00 +0000
+++ b/upgrade.py	2007-01-06 19:31:50 +0000
@@ -0,0 +1,96 @@
+#!/usr/bin/env python2.4
+#
+# Copyright (C) 2006 by Jelmer Vernooij
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+
+from bzrlib.config import Config
+from bzrlib.errors import BzrError
+from bzrlib.ui import ui_factory
+
+from repository import MAPPING_VERSION
+
+# Takes an existing Bazaar branch and replaces all old-version mapped revisions 
+# with new-style revisions mappings. 
+# 
+# It checks the sha1s of the contents to make sure that the revision hasn't 
+# changed. This behaviour can be turned off by specifying --allow-change.
+#
+# Usage: svn-upgrade [--allow-change] PATH REPOSITORY
+
+class UpgradeChangesContent(BzrError):
+    _fmt = """Upgrade will change contents in revision %(revid)s."""
+
+    def __init__(self, revid):
+        super(UpgradeChangesContent, self).__init__()
+        self.revid = revid
+
+
+# Change the parent of a revision
+def change_revision_parent(repository, oldrevid, new_parents):
+    assert isinstance(new_parents, list)
+    suffix = "-svn%d-upgrade" % MAPPING_VERSION
+    if oldrevid.endswith("-upgrade"):
+        # FIXME: 
+        newrevid = oldrevid
+    else:
+        newrevid = oldrevid + suffix
+
+    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)
+
+    # FIXME: Populate the inventory
+    for path, ie in repository.get_revision_inventory(oldrevid).iter_entries():
+        new_ie = ie.copy()
+        if new_ie.revision == oldrevid:
+            new_ie.revision = None
+        builder.record_entry_contents(new_ie, 
+               map(repository.get_revision_inventory, new_parents), 
+               path, repository.revision_tree(oldrevid))
+
+    builder.finish_inventory()
+    return builder.commit(oldrev.message)
+
+
+def upgrade_branch(branch, svn_repository, allow_change=False):
+    needed_revs = []
+    needs_upgrading = {}
+    # FIXME: Find revisions that need to be upgraded, create
+    # dictionary with revision ids in key, new parents in value
+
+    # Make sure all the required current version revisions are present
+    pb = ui_factory.nested_progress_bar()
+    i = 0
+    for revid in needed_revs:
+        pb.update('fetching new revisions', i, len(needed_revs))
+        branch.repository.fetch(svn_repository, revid)
+        i+=1
+    pb.finished()
+
+    pb = ui_factory.nested_progress_bar()
+    i = 0
+    for revid in needs_upgrading:
+        pb.update('upgrading revisions', i, len(needed_revs))
+        change_revision_parent(branch, revid, needs_upgrading[revid])
+        i+=1
+    pb.finished()

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-01-03 22:24:00 +0000
+++ b/tests/__init__.py	2007-01-06 19:31:50 +0000
@@ -241,6 +241,7 @@
             'test_scheme', 
             'test_transport',
             'test_tree',
+            'test_upgrade',
             'test_workingtree']
     suite.addTest(loader.loadTestsFromModuleNames(["%s.%s" % (__name__, i) for i in testmod_names]))
 




More information about the bazaar-commits mailing list