Rev 4376: (Jelmer) Return BranchPushResult from InterBranch.lossy_push(). in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu May 21 15:57:48 BST 2009


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

------------------------------------------------------------
revno: 4376
revision-id: pqm at pqm.ubuntu.com-20090521145743-3ttnkw77ofepprzq
parent: pqm at pqm.ubuntu.com-20090521140643-e0igtobdd3k832wb
parent: jelmer at samba.org-20090514210916-c5lcjp4b1rmxbjvm
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-05-21 15:57:43 +0100
message:
  (Jelmer) Return BranchPushResult from InterBranch.lossy_push().
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
  bzrlib/tests/blackbox/test_dpush.py test_dpush.py-20090108125928-st1td6le59g0vyv2-1
  bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
  bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
    ------------------------------------------------------------
    revno: 4347.3.2
    revision-id: jelmer at samba.org-20090514210916-c5lcjp4b1rmxbjvm
    parent: jelmer at samba.org-20090514034156-v4uflz8c789talme
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: interbranch-dpush-result
    timestamp: Thu 2009-05-14 23:09:16 +0200
    message:
      Add some basic tests for lossy_push.
    modified:
      bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
      bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
    ------------------------------------------------------------
    revno: 4347.3.1
    revision-id: jelmer at samba.org-20090514034156-v4uflz8c789talme
    parent: jelmer at samba.org-20090510012654-jp9ufxquekaokbeo
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: interbranch-dpush-result
    timestamp: Thu 2009-05-14 05:41:56 +0200
    message:
      Return BranchPushResult instance from lossy_push() and make dpush print 
      "Pushed up to revision X." messages.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/foreign.py              foreign.py-20081112170002-olsxmandkk8qyfuq-1
      bzrlib/tests/blackbox/test_dpush.py test_dpush.py-20090108125928-st1td6le59g0vyv2-1
      bzrlib/tests/test_foreign.py   test_foreign.py-20081125004048-ywb901edgp9lluxo-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-05-16 08:21:11 +0000
+++ b/bzrlib/branch.py	2009-05-21 14:57:43 +0000
@@ -877,7 +877,8 @@
 
         :param target: Target branch
         :param stop_revision: Revision to push, defaults to last revision.
-        :return: Dictionary mapping revision ids from the target branch 
+        :return: BranchPushResult with an extra member revidmap: 
+            A dictionary mapping revision ids from the target branch 
             to new revision ids in the target branch, for each 
             revision that was pushed.
         """

=== modified file 'bzrlib/foreign.py'
--- a/bzrlib/foreign.py	2009-05-17 16:10:26 +0000
+++ b/bzrlib/foreign.py	2009-05-21 14:57:43 +0000
@@ -329,7 +329,7 @@
         target_branch.lock_write()
         try:
             try:
-                revid_map = source_branch.lossy_push(target_branch)
+                push_result = source_branch.lossy_push(target_branch)
             except errors.LossyPushToSameVCS:
                 raise BzrCommandError("%r and %r are in the same VCS, lossy "
                     "push not necessary. Please use regular push." %
@@ -349,6 +349,7 @@
                         update_workingtree_fileids(source_wt, target)
                     finally:
                         source_wt.unlock()
+            push_result.report(self.outf)
         finally:
             target_branch.unlock()
 
@@ -365,7 +366,8 @@
 
         :param target: Target branch
         :param stop_revision: Revision to push, defaults to last revision.
-        :return: Dictionary mapping revision ids from the target branch 
+        :return: BranchPushResult with an extra member revidmap: 
+            A dictionary mapping revision ids from the target branch 
             to new revision ids in the target branch, for each 
             revision that was pushed.
         """

=== modified file 'bzrlib/tests/blackbox/test_dpush.py'
--- a/bzrlib/tests/blackbox/test_dpush.py	2009-05-17 16:10:26 +0000
+++ b/bzrlib/tests/blackbox/test_dpush.py	2009-05-21 14:57:43 +0000
@@ -80,7 +80,8 @@
         self.build_tree(("dc/foo", "blaaaa"))
         dc.open_workingtree().commit('msg')
 
-        self.check_output("", "dpush -d dc d")
+        output, error = self.run_bzr("dpush -d dc d")
+        self.assertEquals(error, "Pushed up to revision 2.\n")
         self.check_output("", "status dc")
 
     def test_dpush_new(self):

=== modified file 'bzrlib/tests/branch_implementations/test_push.py'
--- a/bzrlib/tests/branch_implementations/test_push.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/branch_implementations/test_push.py	2009-05-14 21:09:16 +0000
@@ -436,3 +436,13 @@
         self.assertTrue(len(self.hpss_calls) <= 9, self.hpss_calls)
 
 
+class TestLossyPush(TestCaseWithBranch):
+
+    def setUp(self):
+        self.hook_calls = []
+        TestCaseWithBranch.setUp(self)
+
+    def test_lossy_push_raises_same_vcs(self):
+        target = self.make_branch('target')
+        source = self.make_branch('source')
+        self.assertRaises(errors.LossyPushToSameVCS, source.lossy_push, target)

=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py	2009-05-16 08:21:11 +0000
+++ b/bzrlib/tests/test_foreign.py	2009-05-21 14:57:43 +0000
@@ -34,7 +34,10 @@
     format_registry,
     )
 from bzrlib.inventory import Inventory
-from bzrlib.revision import Revision
+from bzrlib.revision import (
+    NULL_REVISION,
+    Revision,
+    )
 from bzrlib.tests import (
     TestCase,
     TestCaseWithTransport,
@@ -110,6 +113,10 @@
         return isinstance(target, DummyForeignVcsBranch)
 
     def lossy_push(self, stop_revision=None):
+        result = branch.BranchPushResult()
+        result.source_branch = self.source
+        result.target_branch = self.target
+        result.old_revno, result.old_revid = self.target.last_revision_info()
         self.source.lock_read()
         try:
             # This just handles simple cases, but that's good enough for tests
@@ -129,7 +136,11 @@
                     (str(rev.timestamp), str(rev.timezone), 
                         str(self.target.revno())))
                 parent_revno, parent_revid= self.target.last_revision_info()
-                builder = self.target.get_commit_builder([parent_revid], 
+                if parent_revid == NULL_REVISION:
+                    parent_revids = []
+                else:
+                    parent_revids = [parent_revid]
+                builder = self.target.get_commit_builder(parent_revids, 
                         self.target.get_config(), rev.timestamp,
                         rev.timezone, rev.committer, rev.properties,
                         new_revid)
@@ -138,7 +149,7 @@
                         new_ie = ie.copy()
                         new_ie.revision = None
                         builder.record_entry_contents(new_ie, 
-                            [self.target.repository.get_inventory(parent_revid)],
+                            [self.target.repository.revision_tree(parent_revid).inventory],
                             path, tree, 
                             (ie.kind, ie.text_size, ie.executable, ie.text_sha1))
                     builder.finish_inventory()
@@ -152,7 +163,9 @@
                     revid, revidmap[revid])
         finally:
             self.source.unlock()
-        return revidmap
+        result.new_revno, result.new_revid = self.target.last_revision_info()
+        result.revidmap = revidmap
+        return result
 
 
 class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6):
@@ -372,3 +385,29 @@
         dir = BzrDir.open("d")
         newdir = dir.sprout("e")
         self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string())
+
+    def test_lossy_push_empty(self):
+        source_tree = self.make_branch_and_tree("source")
+        target_tree = self.make_branch_and_tree("target", 
+            format=DummyForeignVcsDirFormat())
+        pushresult = source_tree.branch.lossy_push(target_tree.branch)
+        self.assertEquals(NULL_REVISION, pushresult.old_revid)
+        self.assertEquals(NULL_REVISION, pushresult.new_revid)
+        self.assertEquals({}, pushresult.revidmap)
+
+    def test_lossy_push_simple(self):
+        source_tree = self.make_branch_and_tree("source")
+        self.build_tree(['source/a', 'source/b'])
+        source_tree.add(['a', 'b'])
+        revid1 = source_tree.commit("msg")
+        target_tree = self.make_branch_and_tree("target", 
+            format=DummyForeignVcsDirFormat())
+        target_tree.branch.lock_write()
+        try:
+            pushresult = source_tree.branch.lossy_push(target_tree.branch)
+        finally:
+            target_tree.branch.unlock()
+        self.assertEquals(NULL_REVISION, pushresult.old_revid)
+        self.assertEquals({revid1:target_tree.branch.last_revision()}, 
+                           pushresult.revidmap)
+        self.assertEquals(pushresult.revidmap[revid1], pushresult.new_revid)




More information about the bazaar-commits mailing list