Rev 2521: (John Arbash Meinel, Aaron Bentley) Fix bug #115343 allowing 'bzr branch' to sprout any revision in the repository. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jun 12 01:09:26 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2521
revision-id: pqm at pqm.ubuntu.com-20070612000924-if8v5wnnp3nwmghg
parent: pqm at pqm.ubuntu.com-20070608134340-flu6dlpzyo7izrrs
parent: john at arbash-meinel.com-20070611232340-paq4xaycao04vkcd
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-06-12 01:09:24 +0100
message:
  (John Arbash Meinel, Aaron Bentley) Fix bug #115343 allowing 'bzr branch' to sprout any revision in the repository.
added:
  bzrlib/tests/branch_implementations/test_sprout.py test_sprout.py-20070521151739-b8t8p7axw1h966ws-1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/tests/branch_implementations/__init__.py __init__.py-20060123013057-b12a52c3f361daf4
  bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
    ------------------------------------------------------------
    revno: 2487.2.7
    merged: john at arbash-meinel.com-20070611232340-paq4xaycao04vkcd
    parent: aaron.bentley at utoronto.ca-20070611010812-u55krk2l4pnv86fs
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Mon 2007-06-11 18:23:40 -0500
    message:
      Fix NEWS to put _iter_changes fixes in right location.
    ------------------------------------------------------------
    revno: 2487.2.6
    merged: aaron.bentley at utoronto.ca-20070611010812-u55krk2l4pnv86fs
    parent: aaron.bentley at utoronto.ca-20070611010616-23ypxhz3zekrck7y
    parent: pqm at pqm.ubuntu.com-20070608134340-flu6dlpzyo7izrrs
    committer: Aaron Bentley <aaron.bentley at utoronto.ca>
    branch nick: fix-115343
    timestamp: Sun 2007-06-10 21:08:12 -0400
    message:
      Merge bzr.dev
    ------------------------------------------------------------
    revno: 2487.2.5
    merged: aaron.bentley at utoronto.ca-20070611010616-23ypxhz3zekrck7y
    parent: aaron.bentley at utoronto.ca-20070611010119-8aayeoi2l6d0si36
    committer: Aaron Bentley <aaron.bentley at utoronto.ca>
    branch nick: fix-115343
    timestamp: Sun 2007-06-10 21:06:16 -0400
    message:
      Tweak NEWS
    ------------------------------------------------------------
    revno: 2487.2.4
    merged: aaron.bentley at utoronto.ca-20070611010119-8aayeoi2l6d0si36
    parent: john at arbash-meinel.com-20070521170258-206ck4nmijfode31
    committer: Aaron Bentley <aaron.bentley at utoronto.ca>
    branch nick: fix-115343
    timestamp: Sun 2007-06-10 21:01:19 -0400
    message:
      Add test to ensure we can branch from repository revisions
    ------------------------------------------------------------
    revno: 2487.2.3
    merged: john at arbash-meinel.com-20070521170258-206ck4nmijfode31
    parent: john at arbash-meinel.com-20070521164413-tp0zcdi51i5dxkv2
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: branch_from_merged_115343
    timestamp: Mon 2007-05-21 19:02:58 +0200
    message:
      Fix bug #115343, Add a test that we can branch any revision in our ancestry.
      And update Branch6 to support this properly.
    ------------------------------------------------------------
    revno: 2487.2.2
    merged: john at arbash-meinel.com-20070521164413-tp0zcdi51i5dxkv2
    parent: john at arbash-meinel.com-20070521151804-dgnr0rfe2j9brq1m
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: branch_from_merged_115343
    timestamp: Mon 2007-05-21 18:44:13 +0200
    message:
      Adding a simple sprout test to make sure it creates the target branch with the right format
    ------------------------------------------------------------
    revno: 2487.2.1
    merged: john at arbash-meinel.com-20070521151804-dgnr0rfe2j9brq1m
    parent: pqm at pqm.ubuntu.com-20070517174205-qwgn733pkui2xqr4
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: branch_from_merged_115343
    timestamp: Mon 2007-05-21 17:18:04 +0200
    message:
      Move the Branch.sprout tests into their own folder.
=== added file 'bzrlib/tests/branch_implementations/test_sprout.py'
--- a/bzrlib/tests/branch_implementations/test_sprout.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/branch_implementations/test_sprout.py	2007-06-11 01:01:19 +0000
@@ -0,0 +1,99 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# 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
+
+"""Tests for Branch.sprout()"""
+
+from bzrlib import (
+    remote,
+    revision as _mod_revision,
+    tests,
+    )
+from bzrlib.tests.branch_implementations import TestCaseWithBranch
+
+
+class TestSprout(TestCaseWithBranch):
+
+    def test_sprout_branch_nickname(self):
+        # test the nick name is reset always
+        raise tests.TestSkipped('XXX branch sprouting is not yet tested..')
+
+    def test_sprout_branch_parent(self):
+        source = self.make_branch('source')
+        target = source.bzrdir.sprout(self.get_url('target')).open_branch()
+        self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
+
+    def test_sprout_preserves_kind(self):
+        branch1 = self.make_branch('branch1')
+        target_repo = self.make_repository('branch2')
+        target_repo.fetch(branch1.repository)
+        branch2 = branch1.sprout(target_repo.bzrdir)
+        if isinstance(branch1, remote.RemoteBranch):
+            branch1._ensure_real()
+            target_class = branch1._real_branch.__class__
+        else:
+            target_class = branch1.__class__
+        self.assertIsInstance(branch2, target_class)
+
+    def test_sprout_partial(self):
+        # test sprouting with a prefix of the revision-history.
+        # also needs not-on-revision-history behaviour defined.
+        wt_a = self.make_branch_and_tree('a')
+        self.build_tree(['a/one'])
+        wt_a.add(['one'])
+        wt_a.commit('commit one', rev_id='1')
+        self.build_tree(['a/two'])
+        wt_a.add(['two'])
+        wt_a.commit('commit two', rev_id='2')
+        repo_b = self.make_repository('b')
+        repo_a = wt_a.branch.repository
+        repo_a.copy_content_into(repo_b)
+        br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1')
+        self.assertEqual('1', br_b.last_revision())
+
+    def test_sprout_partial_not_in_revision_history(self):
+        """We should be able to sprout from any revision in ancestry."""
+        wt = self.make_branch_and_tree('source')
+        self.build_tree(['source/a'])
+        wt.add('a')
+        wt.commit('rev1', rev_id='rev1')
+        wt.commit('rev2-alt', rev_id='rev2-alt')
+        wt.set_parent_ids(['rev1'])
+        wt.branch.set_last_revision_info(1, 'rev1')
+        wt.commit('rev2', rev_id='rev2')
+        wt.set_parent_ids(['rev2', 'rev2-alt'])
+        wt.commit('rev3', rev_id='rev3')
+
+        repo = self.make_repository('target')
+        repo.fetch(wt.branch.repository)
+        branch2 = wt.branch.sprout(repo.bzrdir, revision_id='rev2-alt')
+        self.assertEqual((2, 'rev2-alt'), branch2.last_revision_info())
+        self.assertEqual(['rev1', 'rev2-alt'], branch2.revision_history())
+
+    def test_sprout_from_any_repo_revision(self):
+        """We should be able to sprout from any revision."""
+        wt = self.make_branch_and_tree('source')
+        self.build_tree(['source/a'])
+        wt.add('a')
+        wt.commit('rev1a', rev_id='rev1a')
+        # simulated uncommit
+        wt.branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
+        wt.set_last_revision(None)
+        wt.revert([])
+        wt.commit('rev1b', rev_id='rev1b')
+        wt2 = wt.bzrdir.sprout('target',
+            revision_id='rev1a').open_workingtree()
+        self.assertEqual('rev1a', wt2.last_revision())
+        self.failUnlessExists('target/a')

=== modified file 'NEWS'
--- a/NEWS	2007-06-07 22:31:44 +0000
+++ b/NEWS	2007-06-12 00:09:24 +0000
@@ -88,6 +88,10 @@
     * Tests no longer fail when BZR_REMOTE_PATH is set in the environment.
       (Daniel Watkins, #111958)
 
+    * ``bzr branch -r revid:foo`` can be used to branch any revision in
+      your repository. (Previously Branch6 only supported revisions in your
+      mainline). (John Arbash Meinel, #115343)
+
 bzr 0.16  2007-05-07
   
   BUGFIXES:

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2007-05-08 20:00:50 +0000
+++ b/bzrlib/branch.py	2007-05-21 17:02:58 +0000
@@ -2077,7 +2077,14 @@
         if revision_id is None:
             revno, revision_id = self.last_revision_info()
         else:
-            revno = self.revision_id_to_revno(revision_id)
+            # To figure out the revno for a random revision, we need to build
+            # the revision history, and count its length.
+            # We don't care about the order, just how long it is.
+            # Alternatively, we could start at the current location, and count
+            # backwards. But there is no guarantee that we will find it since
+            # it may be a merged revision.
+            revno = len(list(self.repository.iter_reverse_revision_history(
+                                                                revision_id)))
         destination.set_last_revision_info(revno, revision_id)
 
     def _make_tags(self):

=== modified file 'bzrlib/tests/branch_implementations/__init__.py'
--- a/bzrlib/tests/branch_implementations/__init__.py	2007-04-24 19:45:05 +0000
+++ b/bzrlib/tests/branch_implementations/__init__.py	2007-05-21 15:18:04 +0000
@@ -119,6 +119,7 @@
         'bzrlib.tests.branch_implementations.test_push',
         'bzrlib.tests.branch_implementations.test_revision_history',
         'bzrlib.tests.branch_implementations.test_revision_id_to_revno',
+        'bzrlib.tests.branch_implementations.test_sprout',
         'bzrlib.tests.branch_implementations.test_tags',
         'bzrlib.tests.branch_implementations.test_uncommit',
         'bzrlib.tests.branch_implementations.test_update',

=== modified file 'bzrlib/tests/branch_implementations/test_branch.py'
--- a/bzrlib/tests/branch_implementations/test_branch.py	2007-04-24 03:23:27 +0000
+++ b/bzrlib/tests/branch_implementations/test_branch.py	2007-05-21 15:18:04 +0000
@@ -167,22 +167,6 @@
         br_b = branch.clone(repo_b.bzrdir, revision_id='1')
         self.assertEqual('1', br_b.last_revision())
 
-    def test_sprout_partial(self):
-        # test sprouting with a prefix of the revision-history.
-        # also needs not-on-revision-history behaviour defined.
-        wt_a = self.make_branch_and_tree('a')
-        self.build_tree(['a/one'])
-        wt_a.add(['one'])
-        wt_a.commit('commit one', rev_id='1')
-        self.build_tree(['a/two'])
-        wt_a.add(['two'])
-        wt_a.commit('commit two', rev_id='2')
-        repo_b = self.make_repository('b')
-        repo_a = wt_a.branch.repository
-        repo_a.copy_content_into(repo_b)
-        br_b = wt_a.branch.sprout(repo_b.bzrdir, revision_id='1')
-        self.assertEqual('1', br_b.last_revision())
-
     def get_parented_branch(self):
         wt_a = self.make_branch_and_tree('a')
         self.build_tree(['a/one'])
@@ -214,15 +198,6 @@
         branch_d = branch_b.clone(repo_d.bzrdir)
         self.assertEqual(random_parent, branch_d.get_parent())
 
-    def test_sprout_branch_nickname(self):
-        # test the nick name is reset always
-        raise TestSkipped('XXX branch sprouting is not yet tested..')
-
-    def test_sprout_branch_parent(self):
-        source = self.make_branch('source')
-        target = source.bzrdir.sprout(self.get_url('target')).open_branch()
-        self.assertEqual(source.bzrdir.root_transport.base, target.get_parent())
-
     def test_submit_branch(self):
         """Submit location can be queried and set"""
         branch = self.make_branch('branch')




More information about the bazaar-commits mailing list