Rev 3503: Fix the tree.branch returned by make_branch_and_tree. (Andrew in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Jun 18 06:14:38 BST 2008


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

------------------------------------------------------------
revno: 3503
revision-id:pqm at pqm.ubuntu.com-20080618051428-txnglk8ls5jd93fc
parent: pqm at pqm.ubuntu.com-20080618032827-fq9wj33m0wfpurzv
parent: andrew.bennetts at canonical.com-20080618045053-4zgvoz9xu1h1zcri
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-06-18 06:14:28 +0100
message:
  Fix the tree.branch returned by make_branch_and_tree. (Andrew
  	Bennetts)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
  bzrlib/tests/branch_implementations/test_check.py test_check.py-20080429151303-1sbfclxhddpz0tnj-1
  bzrlib/tests/branch_implementations/test_reconcile.py test_reconcile.py-20080429161555-qlmccuyeyt6pvho7-1
    ------------------------------------------------------------
    revno: 3489.2.9
    revision-id:andrew.bennetts at canonical.com-20080618045053-4zgvoz9xu1h1zcri
    parent: andrew.bennetts at canonical.com-20080618005845-3y0ae9qp05d48que
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Wed 2008-06-18 14:50:53 +1000
    message:
      Add NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3489.2.8
    revision-id:andrew.bennetts at canonical.com-20080618005845-3y0ae9qp05d48que
    parent: andrew.bennetts at canonical.com-20080612000017-rj3iicm3ftpv1fin
    parent: andrew.bennetts at canonical.com-20080617043218-gm8jc3cdk0lgjcfv
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Wed 2008-06-18 10:58:45 +1000
    message:
      Merge from remote-is-at-least.
    modified:
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/xml_serializer.py       xml.py-20050309040759-57d51586fdec365d
    ------------------------------------------------------------
    revno: 3489.2.7
    revision-id:andrew.bennetts at canonical.com-20080612000017-rj3iicm3ftpv1fin
    parent: andrew.bennetts at canonical.com-20080611235934-dtn3wahp7xf2cdq0
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Thu 2008-06-12 10:00:17 +1000
    message:
      Update comments and docstrings, add NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
    ------------------------------------------------------------
    revno: 3489.2.6
    revision-id:andrew.bennetts at canonical.com-20080611235934-dtn3wahp7xf2cdq0
    parent: andrew.bennetts at canonical.com-20080611075454-evxru0ssycsdywgd
    parent: andrew.bennetts at canonical.com-20080611235921-5j77i6gne7sh8x3s
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Thu 2008-06-12 09:59:34 +1000
    message:
      Merge from bzr.dev.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/__init__.py             __init__.py-20050309040759-33e65acf91bbcd5d
      bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
      bzrlib/export/tar_exporter.py  tar_exporter.py-20051114235828-1f6349a2f090a5d0
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/smart/protocol.py       protocol.py-20061108035435-ot0lstk2590yqhzr-1
      bzrlib/tests/blackbox/test_export.py test_export.py-20051229024010-e6c26658e460fb1c
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
      bzrlib/tests/test_osutils.py   test_osutils.py-20051201224856-e48ee24c12182989
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/developers/releasing.txt   releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
      doc/index.txt                  index.txt-20070813101924-07gd9i9d2jt124bf-1
    ------------------------------------------------------------
    revno: 3489.2.5
    revision-id:andrew.bennetts at canonical.com-20080611075454-evxru0ssycsdywgd
    parent: andrew.bennetts at canonical.com-20080611075225-vqv5d1p5wydryz49
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Wed 2008-06-11 17:54:54 +1000
    message:
      Tweak suggested by John's review.
    modified:
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
    ------------------------------------------------------------
    revno: 3489.2.4
    revision-id:andrew.bennetts at canonical.com-20080611075225-vqv5d1p5wydryz49
    parent: andrew.bennetts at canonical.com-20080610074115-e4isop261jrba6ip
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Wed 2008-06-11 17:52:25 +1000
    message:
      Fix all tests broken by fixing make_branch_and_tree.
    modified:
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
      bzrlib/tests/branch_implementations/test_check.py test_check.py-20080429151303-1sbfclxhddpz0tnj-1
      bzrlib/tests/branch_implementations/test_reconcile.py test_reconcile.py-20080429161555-qlmccuyeyt6pvho7-1
    ------------------------------------------------------------
    revno: 3489.2.3
    revision-id:andrew.bennetts at canonical.com-20080610074115-e4isop261jrba6ip
    parent: andrew.bennetts at canonical.com-20080610050540-926drw1nk5ctqwbo
    parent: andrew.bennetts at canonical.com-20080610073759-ewmdzkasnyz6gagl
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Tue 2008-06-10 17:41:15 +1000
    message:
      Merge remote-is-at-least.
    modified:
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
    ------------------------------------------------------------
    revno: 3489.2.2
    revision-id:andrew.bennetts at canonical.com-20080610050540-926drw1nk5ctqwbo
    parent: andrew.bennetts at canonical.com-20080610050510-kx0fkha390ois9pq
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Tue 2008-06-10 15:05:40 +1000
    message:
      Fix RemoteToOtherFetcher to update count_copied.
    modified:
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
    ------------------------------------------------------------
    revno: 3489.2.1
    revision-id:andrew.bennetts at canonical.com-20080610050510-kx0fkha390ois9pq
    parent: pqm at pqm.ubuntu.com-20080609211646-amc2rr2zi50omr8m
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: make-branch-and-tree-fix
    timestamp: Tue 2008-06-10 15:05:10 +1000
    message:
      Fix make_branch_and_tree to return a tree whose .branch is always the right format.
    modified:
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
=== modified file 'NEWS'
--- a/NEWS	2008-06-18 02:15:53 +0000
+++ b/NEWS	2008-06-18 05:14:28 +0000
@@ -51,8 +51,17 @@
 
   TESTING:
 
+   * ``TestCaseWithTransport.make_branch_and_tree`` tries harder to return
+     a tree with a ``branch`` attribute of the right format.  This was
+     preventing some ``RemoteBranch`` tests from actually running with
+     ``RemoteBranch`` instances.  (Andrew Bennetts)
+
   API CHANGES:
 
+    * ``Branch.pull`` now accepts an ``_override_hook_target`` optional
+      parameter.  If you have a subclass of ``Branch`` that overrides
+      ``pull`` then you should add this parameter.  (Andrew Bennetts)
+
   INTERNALS:
 
 

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2008-06-16 16:55:05 +0000
+++ b/bzrlib/branch.py	2008-06-18 05:14:28 +0000
@@ -528,7 +528,7 @@
         return history[revno - 1]
 
     def pull(self, source, overwrite=False, stop_revision=None,
-             possible_transports=None):
+             possible_transports=None, _override_hook_target=None):
         """Mirror source into this branch.
 
         This branch is considered to be 'local', having low latency.
@@ -1557,18 +1557,24 @@
 
     @needs_write_lock
     def pull(self, source, overwrite=False, stop_revision=None,
-             _hook_master=None, run_hooks=True, possible_transports=None):
+             _hook_master=None, run_hooks=True, possible_transports=None,
+             _override_hook_target=None):
         """See Branch.pull.
 
         :param _hook_master: Private parameter - set the branch to 
-            be supplied as the master to push hooks.
+            be supplied as the master to pull hooks.
         :param run_hooks: Private parameter - if false, this branch
             is being called because it's the master of the primary branch,
             so it should not run its hooks.
+        :param _override_hook_target: Private parameter - set the branch to be
+            supplied as the target_branch to pull hooks.
         """
         result = PullResult()
         result.source_branch = source
-        result.target_branch = self
+        if _override_hook_target is None:
+            result.target_branch = self
+        else:
+            result.target_branch = _override_hook_target
         source.lock_read()
         try:
             # We assume that during 'pull' the local repository is closer than
@@ -1581,9 +1587,9 @@
             result.new_revno, result.new_revid = self.last_revision_info()
             if _hook_master:
                 result.master_branch = _hook_master
-                result.local_branch = self
+                result.local_branch = result.target_branch
             else:
-                result.master_branch = self
+                result.master_branch = result.target_branch
                 result.local_branch = None
             if run_hooks:
                 for hook in Branch.hooks['post_pull']:
@@ -1753,7 +1759,8 @@
         
     @needs_write_lock
     def pull(self, source, overwrite=False, stop_revision=None,
-             run_hooks=True, possible_transports=None):
+             run_hooks=True, possible_transports=None,
+             _override_hook_target=None):
         """Pull from source into self, updating my master if any.
         
         :param run_hooks: Private parameter - if false, this branch
@@ -1773,7 +1780,8 @@
                     run_hooks=False)
             return super(BzrBranch5, self).pull(source, overwrite,
                 stop_revision, _hook_master=master_branch,
-                run_hooks=run_hooks)
+                run_hooks=run_hooks,
+                _override_hook_target=_override_hook_target)
         finally:
             if master_branch:
                 master_branch.unlock()

=== modified file 'bzrlib/fetch.py'
--- a/bzrlib/fetch.py	2008-05-12 01:23:41 +0000
+++ b/bzrlib/fetch.py	2008-06-10 05:05:40 +0000
@@ -458,6 +458,6 @@
 
     def _fetch_everything_for_search(self, search, pp):
         data_stream = self.from_repository.get_data_stream_for_search(search)
-        self.to_repository.insert_data_stream(data_stream)
+        self.count_copied += self.to_repository.insert_data_stream(data_stream)
 
 

=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2008-06-17 04:32:18 +0000
+++ b/bzrlib/remote.py	2008-06-18 00:58:45 +0000
@@ -1510,15 +1510,10 @@
     @needs_write_lock
     def pull(self, source, overwrite=False, stop_revision=None,
              **kwargs):
-        # FIXME: This asks the real branch to run the hooks, which means
-        # they're called with the wrong target branch parameter. 
-        # The test suite specifically allows this at present but it should be
-        # fixed.  It should get a _override_hook_target branch,
-        # as push does.  -- mbp 20070405
         self._ensure_real()
         return self._real_branch.pull(
             source, overwrite=overwrite, stop_revision=stop_revision,
-            **kwargs)
+            _override_hook_target=self, **kwargs)
 
     @needs_read_lock
     def push(self, target, overwrite=False, stop_revision=None):

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-06-04 07:29:35 +0000
+++ b/bzrlib/repository.py	2008-06-10 05:05:40 +0000
@@ -834,6 +834,7 @@
         Is it a substitute for fetch? 
         Should it manage its own write group ?
         """
+        revisions_inserted = 0
         for item_key, bytes in stream:
             if item_key[0] == 'file':
                 (file_id,) = item_key[1:]
@@ -844,6 +845,7 @@
             elif item_key == ('revisions',):
                 knit = self._revision_store.get_revision_file(
                     self.get_transaction())
+                revisions_inserted += 1
             elif item_key == ('signatures',):
                 knit = self._revision_store.get_signature_file(
                     self.get_transaction())
@@ -865,6 +867,7 @@
                     return buffer.read(count)
             knit.insert_data_stream(
                 (format, data_list, reader_func))
+        return revisions_inserted
 
     @needs_read_lock
     def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2008-06-06 13:56:24 +0000
+++ b/bzrlib/tests/__init__.py	2008-06-11 07:54:54 +0000
@@ -2186,7 +2186,14 @@
                 # the branch is colocated on disk, we cannot create a checkout.
                 # hopefully callers will expect this.
                 local_controldir= bzrdir.BzrDir.open(self.get_vfs_only_url(relpath))
-                return local_controldir.create_workingtree()
+                wt = local_controldir.create_workingtree()
+                if wt.branch._format != b._format:
+                    wt._branch = b
+                    # Make sure that assigning to wt._branch fixes wt.branch,
+                    # in case the implementation details of workingtree objects
+                    # change.
+                    self.assertIs(b, wt.branch)
+                return wt
             else:
                 return b.create_checkout(relpath, lightweight=True)
 

=== modified file 'bzrlib/tests/branch_implementations/test_branch.py'
--- a/bzrlib/tests/branch_implementations/test_branch.py	2008-05-28 22:30:48 +0000
+++ b/bzrlib/tests/branch_implementations/test_branch.py	2008-06-11 07:52:25 +0000
@@ -165,7 +165,7 @@
         wt_a.add(['one'])
         wt_a.commit('commit one', rev_id='1')
 
-        branch_b = wt_a.bzrdir.sprout('b', revision_id='1').open_branch()
+        branch_b = wt_a.branch.bzrdir.sprout('b', revision_id='1').open_branch()
         self.assertEqual(wt_a.branch.base, branch_b.get_parent())
         return branch_b
 

=== modified file 'bzrlib/tests/branch_implementations/test_check.py'
--- a/bzrlib/tests/branch_implementations/test_check.py	2008-04-29 17:01:24 +0000
+++ b/bzrlib/tests/branch_implementations/test_check.py	2008-06-11 07:52:25 +0000
@@ -43,6 +43,11 @@
         # Now, try to set an invalid history
         try:
             tree.branch.set_revision_history([r1, r2b, r5])
+            if tree.branch.last_revision_info() != (3, r5):
+                # RemoteBranch silently corrects an impossible revision
+                # history given to set_revision_history.  It can be tricked
+                # with set_last_revision_info though.
+                tree.branch.set_last_revision_info(3, r5)
         except errors.NotLefthandHistory:
             # Branch5 allows set_revision_history to be wrong
             # Branch6 raises NotLefthandHistory, but we can force bogus stuff

=== modified file 'bzrlib/tests/branch_implementations/test_reconcile.py'
--- a/bzrlib/tests/branch_implementations/test_reconcile.py	2008-04-29 16:43:14 +0000
+++ b/bzrlib/tests/branch_implementations/test_reconcile.py	2008-06-11 07:52:25 +0000
@@ -43,6 +43,11 @@
         # Now, try to set an invalid history
         try:
             tree.branch.set_revision_history([r1, r2b, r5])
+            if tree.branch.last_revision_info() != (3, r5):
+                # RemoteBranch silently corrects an impossible revision
+                # history given to set_revision_history.  It can be tricked
+                # with set_last_revision_info though.
+                tree.branch.set_last_revision_info(3, r5)
         except errors.NotLefthandHistory:
             # Branch5 allows set_revision_history to be wrong
             # Branch6 raises NotLefthandHistory, but we can force bogus stuff




More information about the bazaar-commits mailing list