Rev 2537: [MERGE] handle null revision properly for LCA in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jun 19 22:22:59 BST 2007


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

------------------------------------------------------------
revno: 2537
revision-id: pqm at pqm.ubuntu.com-20070619212256-y1148bn5gf4jg2dh
parent: pqm at pqm.ubuntu.com-20070619194321-g3qy7rh361kdvstd
parent: abentley at panoramicfeedback.com-20070619145132-xc0rgyfzebvraxb0
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2007-06-19 22:22:56 +0100
message:
  [MERGE] handle null revision properly for LCA
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/bundle/commands.py      __init__.py-20050617152058-1b6530d9ab85c11c
  bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
  bzrlib/merge_directive.py      merge_directive.py-20070228184838-ja62280spt1g7f4x-1
  bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
  bzrlib/tests/blackbox/test_bundle.py test_bundle.py-20060616222707-c21c8b7ea5ef57b1
  bzrlib/tests/blackbox/test_find_merge_base.py test_find_merge_base.py-20060131142124-f9d5c94df4505b70
  bzrlib/tests/blackbox/test_merge_directive.py test_merge_directive-20070302012039-zh7uhy39biairtn0-1
  bzrlib/tests/test_graph.py     test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
  bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
  bzrlib/tests/workingtree_implementations/test_merge_from_branch.py test_merge_from_bran-20060904034200-12jxyk2zlhpufxe1-1
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 2490.2.29
    merged: abentley at panoramicfeedback.com-20070619145132-xc0rgyfzebvraxb0
    parent: abentley at panoramicfeedback.com-20070619144906-zx160g6h377j729h
    committer: Aaron Bentley <abentley at panoramicfeedback.com>
    branch nick: graphwalker
    timestamp: Tue 2007-06-19 10:51:32 -0400
    message:
      Make parents provider private
    ------------------------------------------------------------
    revno: 2490.2.28
    merged: abentley at panoramicfeedback.com-20070619144906-zx160g6h377j729h
    parent: abentley at panoramicfeedback.com-20070618201035-6c37yx8f70lk5570
    committer: Aaron Bentley <abentley at panoramicfeedback.com>
    branch nick: graphwalker
    timestamp: Tue 2007-06-19 10:49:06 -0400
    message:
      Fix handling of null revision
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-06-18 20:04:16 +0000
+++ b/bzrlib/builtins.py	2007-06-19 14:49:06 +0000
@@ -2551,13 +2551,13 @@
     
     @display_command
     def run(self, branch, other):
-        from bzrlib.revision import MultipleRevisionSources
+        from bzrlib.revision import ensure_null, MultipleRevisionSources
         
         branch1 = Branch.open_containing(branch)[0]
         branch2 = Branch.open_containing(other)[0]
 
-        last1 = branch1.last_revision()
-        last2 = branch2.last_revision()
+        last1 = ensure_null(branch1.last_revision())
+        last2 = ensure_null(branch2.last_revision())
 
         graph = branch1.repository.get_graph(branch2.repository)
         base_rev_id = graph.find_unique_lca(last1, last2)
@@ -3538,6 +3538,7 @@
 
     def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
             sign=False, revision=None, mail_to=None, message=None):
+        from bzrlib.revision import ensure_null, NULL_REVISION
         if patch_type == 'plain':
             patch_type = None
         branch = Branch.open('.')
@@ -3568,6 +3569,9 @@
                 revision_id = revision[0].in_history(branch).rev_id
         else:
             revision_id = branch.last_revision()
+        revision_id = ensure_null(revision_id)
+        if revision_id == NULL_REVISION:
+            raise errors.BzrCommandError('No revisions to bundle.')
         directive = merge_directive.MergeDirective.from_objects(
             branch.repository, revision_id, time.time(),
             osutils.local_time_offset(), submit_branch,

=== modified file 'bzrlib/bundle/commands.py'
--- a/bzrlib/bundle/commands.py	2007-06-08 21:48:42 +0000
+++ b/bzrlib/bundle/commands.py	2007-06-19 14:49:06 +0000
@@ -27,6 +27,7 @@
 from bzrlib import (
     branch,
     errors,
+    revision as _mod_revision,
     urlutils,
     )
 """)
@@ -156,7 +157,8 @@
                                            base_branch.last_revision())
             graph = target_branch.repository.get_graph()
             base_revision = graph.find_unique_lca(
-                base_branch.last_revision(), target_revision)
+                _mod_revision.ensure_null(base_branch.last_revision()),
+                _mod_revision.ensure_null(target_revision))
 
         if output is not None:
             fileobj = file(output, 'wb')

=== modified file 'bzrlib/graph.py'
--- a/bzrlib/graph.py	2007-06-18 20:02:18 +0000
+++ b/bzrlib/graph.py	2007-06-19 14:51:32 +0000
@@ -14,6 +14,7 @@
 # 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 import errors
 from bzrlib.deprecated_graph import (node_distances, select_farthest)
 from bzrlib.revision import NULL_REVISION
 
@@ -46,6 +47,9 @@
     def __init__(self, parent_providers):
         self._parent_providers = parent_providers
 
+    def __repr__(self):
+        return "_StackedParentsProvider(%r)" % self._parent_providers
+
     def get_parents(self, revision_ids):
         """Find revision ids of the parents of a list of revisions
 
@@ -88,6 +92,10 @@
             conforming to the behavior of StackedParentsProvider.get_parents
         """
         self.get_parents = parents_provider.get_parents
+        self._parents_provider = parents_provider
+
+    def __repr__(self):
+        return 'Graph(%r)' % self._parents_provider
 
     def find_lca(self, *revisions):
         """Determine the lowest common ancestors of the provided revisions
@@ -149,6 +157,8 @@
         This allows calculation of graph difference from the results of this
         operation.
         """
+        if None in revisions:
+            raise errors.InvalidRevisionId(None, self)
         common_searcher = self._make_breadth_first_searcher([])
         common_ancestors = set()
         searchers = [self._make_breadth_first_searcher([r])

=== modified file 'bzrlib/merge_directive.py'
--- a/bzrlib/merge_directive.py	2007-06-19 19:43:21 +0000
+++ b/bzrlib/merge_directive.py	2007-06-19 21:22:56 +0000
@@ -203,7 +203,10 @@
         If the message is not supplied, the message from revision_id will be
         used for the commit.
         """
-        t = testament.StrictTestament3.from_revision(repository, revision_id)
+        t_revision_id = revision_id
+        if revision_id == 'null:':
+            t_revision_id = None
+        t = testament.StrictTestament3.from_revision(repository, t_revision_id)
         submit_branch = _mod_branch.Branch.open(target_branch)
         if submit_branch.get_public_branch() is not None:
             target_branch = submit_branch.get_public_branch()
@@ -211,6 +214,7 @@
             patch = None
         else:
             submit_revision_id = submit_branch.last_revision()
+            submit_revision_id = _mod_revision.ensure_null(submit_revision_id)
             repository.fetch(submit_branch.repository, submit_revision_id)
             graph = repository.get_graph()
             ancestor_id = graph.find_unique_lca(revision_id,

=== modified file 'bzrlib/repofmt/knitrepo.py'
--- a/bzrlib/repofmt/knitrepo.py	2007-06-08 21:48:42 +0000
+++ b/bzrlib/repofmt/knitrepo.py	2007-06-19 14:49:06 +0000
@@ -44,6 +44,9 @@
     def __init__(self, knit):
         self._knit = knit
 
+    def __repr__(self):
+        return 'KnitParentsProvider(%r)' % self._knit
+
     def get_parents(self, revision_ids):
         parents_list = []
         for revision_id in revision_ids:

=== modified file 'bzrlib/tests/blackbox/test_bundle.py'
--- a/bzrlib/tests/blackbox/test_bundle.py	2007-03-30 02:36:36 +0000
+++ b/bzrlib/tests/blackbox/test_bundle.py	2007-06-19 14:49:06 +0000
@@ -21,10 +21,10 @@
 
 from bzrlib.bundle.serializer import read_bundle
 from bzrlib.bzrdir import BzrDir
-from bzrlib.tests import TestCaseInTempDir
-
-
-class TestBundle(TestCaseInTempDir):
+from bzrlib import tests
+
+
+class TestBundle(tests.TestCaseWithTransport):
 
     def make_trees(self):
         grandparent_tree = BzrDir.create_standalone_workingtree('grandparent')
@@ -92,3 +92,9 @@
         stdout = self.run_bzr_subprocess('bundle')[0]
         br = read_bundle(StringIO(stdout))
         self.assertRevisions(br, ['revision3'])
+
+    def test_no_common_ancestor(self):
+        foo = self.make_branch_and_tree('foo')
+        bar = self.make_branch_and_tree('bar')
+        os.chdir('foo')
+        self.run_bzr('bundle', '../bar')

=== modified file 'bzrlib/tests/blackbox/test_find_merge_base.py'
--- a/bzrlib/tests/blackbox/test_find_merge_base.py	2006-10-11 23:08:27 +0000
+++ b/bzrlib/tests/blackbox/test_find_merge_base.py	2007-06-19 14:49:06 +0000
@@ -32,3 +32,9 @@
         r = self.run_bzr('find-merge-base', '.', '../a', backtick=True)
         self.assertEqual(q, r)
         
+    def test_find_null_merge_base(self):
+        tree = self.make_branch_and_tree('foo')
+        tree.commit('message')
+        tree2 = self.make_branch_and_tree('bar')
+        r = self.run_bzr('find-merge-base', 'foo', 'bar')[0]
+        self.assertEqual('merge base is revision null:\n', r)

=== modified file 'bzrlib/tests/blackbox/test_merge_directive.py'
--- a/bzrlib/tests/blackbox/test_merge_directive.py	2007-04-01 03:58:12 +0000
+++ b/bzrlib/tests/blackbox/test_merge_directive.py	2007-06-19 14:49:06 +0000
@@ -213,3 +213,17 @@
                                   '.')
         call = connect_calls[0]
         self.assertEqual(('bogushost', 0), call[1:3])
+
+    def test_no_common_ancestor(self):
+        foo = self.make_branch_and_tree('foo')
+        foo.commit('rev1')
+        bar = self.make_branch_and_tree('bar')
+        os.chdir('foo')
+        self.run_bzr('merge-directive', '../bar')
+
+    def test_no_commits(self):
+        foo = self.make_branch_and_tree('foo')
+        bar = self.make_branch_and_tree('bar')
+        os.chdir('foo')
+        self.run_bzr_error(('No revisions to bundle.', ),
+                            'merge-directive', '../bar')

=== modified file 'bzrlib/tests/test_graph.py'
--- a/bzrlib/tests/test_graph.py	2007-06-18 20:02:18 +0000
+++ b/bzrlib/tests/test_graph.py	2007-06-19 14:49:06 +0000
@@ -14,7 +14,10 @@
 # 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 import graph
+from bzrlib import (
+    errors,
+    graph,
+    )
 from bzrlib.revision import NULL_REVISION
 from bzrlib.tests import TestCaseWithMemoryTransport
 
@@ -170,6 +173,7 @@
         ancestry_1 should always have a single common ancestor
         """
         graph = self.make_graph(ancestry_1)
+        self.assertRaises(errors.InvalidRevisionId, graph.find_lca, None)
         self.assertEqual(set([NULL_REVISION]),
                          graph.find_lca(NULL_REVISION, NULL_REVISION))
         self.assertEqual(set([NULL_REVISION]),

=== modified file 'bzrlib/tests/test_merge_directive.py'
--- a/bzrlib/tests/test_merge_directive.py	2007-06-19 05:20:15 +0000
+++ b/bzrlib/tests/test_merge_directive.py	2007-06-19 21:22:56 +0000
@@ -202,6 +202,13 @@
         tree_a.commit('Commit of rev2a', rev_id='rev2a')
         return tree_a, tree_b, branch_c
 
+    def test_empty_target(self):
+        tree_a, tree_b, branch_c = self.make_trees()
+        tree_d = self.make_branch_and_tree('tree_d')
+        md2 = merge_directive.MergeDirective.from_objects(
+            tree_a.branch.repository, 'rev2a', 500, 120, tree_d.branch.base,
+            patch_type='diff', public_branch=tree_a.branch.base)
+
     def test_generate_patch(self):
         tree_a, tree_b, branch_c = self.make_trees()
         md2 = merge_directive.MergeDirective.from_objects(

=== modified file 'bzrlib/tests/workingtree_implementations/test_merge_from_branch.py'
--- a/bzrlib/tests/workingtree_implementations/test_merge_from_branch.py	2007-03-10 21:39:07 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_merge_from_branch.py	2007-06-19 14:49:06 +0000
@@ -19,6 +19,7 @@
 
 import os
 
+from bzrlib import errors
 from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
 
@@ -66,3 +67,13 @@
         tree_a.lock_read()
         self.addCleanup(tree_a.unlock)
         list(tree_a._iter_changes(tree_a.basis_tree()))
+
+    def test_merge_empty(self):
+        tree_a = self.make_branch_and_tree('tree_a')
+        self.build_tree_contents([('tree_a/file', 'text-a')])
+        tree_a.add('file')
+        tree_a.commit('added file')
+        tree_b = self.make_branch_and_tree('treeb')
+        self.assertRaises(errors.NoCommits, tree_a.merge_from_branch,
+                          tree_b.branch)
+        tree_b.merge_from_branch(tree_a.branch)

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-06-08 21:48:42 +0000
+++ b/bzrlib/workingtree.py	2007-06-19 14:49:06 +0000
@@ -813,7 +813,7 @@
                 to_revision = osutils.safe_revision_id(to_revision)
             merger.other_rev_id = to_revision
             if merger.other_rev_id is None:
-                raise error.NoCommits(branch)
+                raise errors.NoCommits(branch)
             self.branch.fetch(branch, last_revision=merger.other_rev_id)
             merger.other_basis = merger.other_rev_id
             merger.other_tree = self.branch.repository.revision_tree(




More information about the bazaar-commits mailing list