Rev 5285: * Fetching was slightly confused about the best code to use and was in http://bazaar.launchpad.net/~lifeless/bzr/loomsupport
Robert Collins
robertc at robertcollins.net
Mon Jun 14 07:37:20 BST 2010
At http://bazaar.launchpad.net/~lifeless/bzr/loomsupport
------------------------------------------------------------
revno: 5285
revision-id: robertc at robertcollins.net-20100614063711-t97euf6219nh19vo
parent: pqm at pqm.ubuntu.com-20100607023804-g0tttwnphcv00q2o
committer: Robert Collins <robertc at robertcollins.net>
branch nick: loomsupport
timestamp: Mon 2010-06-14 18:37:11 +1200
message:
* Fetching was slightly confused about the best code to use and was
using a new code path for all branches, resulting in more lookups than
necessary on old branches.
(Robert Collins, #593515)
=== modified file 'NEWS'
--- a/NEWS 2010-06-07 02:38:04 +0000
+++ b/NEWS 2010-06-14 06:37:11 +0000
@@ -28,14 +28,20 @@
leading to faster init for directories with existing content.
(Martin [gz], Parth Malwankar, #501307)
+* Explicitly removing ``--profile-imports`` option from parsed command-line
+ arguments on Windows, because bzr script does the same.
+ (Alexander Belchenko, #588277)
+
+* Fetching was slightly confused about the best code to use and was
+ using a new code path for all branches, resulting in more lookups than
+ necessary on old branches.
+ (Robert Collins, #593515)
+
* Final fix for 'no help for command' issue. We now show a clean message
when a command has no help, document how to set help more clearly, and
test that all commands available to the test suite have help.
(Robert Collins, #177500)
-* Explicitly removing ``--profile-imports`` option from parsed command-line
- arguments on Windows, because bzr script does the same.
- (Alexander Belchenko, #588277)
Improvements
************
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2010-05-25 17:27:52 +0000
+++ b/bzrlib/branch.py 2010-06-14 06:37:11 +0000
@@ -29,6 +29,7 @@
errors,
lockdir,
lockable_files,
+ remote,
repository,
revision as _mod_revision,
rio,
@@ -3226,13 +3227,24 @@
class GenericInterBranch(InterBranch):
- """InterBranch implementation that uses public Branch functions.
- """
+ """InterBranch implementation that uses public Branch functions."""
+
+ @classmethod
+ def is_compatible(klass, source, target):
+ # GenericBranch uses the public API, so always compatible
+ return True
@staticmethod
def _get_branch_formats_to_test():
return BranchFormat._default_format, BranchFormat._default_format
+ @classmethod
+ def unwrap_format(klass, format):
+ if isinstance(format, remote.RemoteBranchFormat):
+ format._ensure_real()
+ return format._custom_format
+ return format
+
def update_revisions(self, stop_revision=None, overwrite=False,
graph=None):
"""See InterBranch.update_revisions()."""
@@ -3277,59 +3289,34 @@
self.source.unlock()
def pull(self, overwrite=False, stop_revision=None,
- possible_transports=None, _hook_master=None, run_hooks=True,
+ possible_transports=None, run_hooks=True,
_override_hook_target=None, local=False):
- """See Branch.pull.
+ """Pull from source into self, updating my master if any.
- :param _hook_master: Private parameter - set the branch to
- 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.
- :param local: Only update the local branch, and not the bound branch.
"""
- # This type of branch can't be bound.
- if local:
+ bound_location = self.target.get_bound_location()
+ if local and not bound_location:
raise errors.LocalRequiresBoundBranch()
- result = PullResult()
- result.source_branch = self.source
- if _override_hook_target is None:
- result.target_branch = self.target
- else:
- result.target_branch = _override_hook_target
- self.source.lock_read()
+ master_branch = None
+ if not local and bound_location and self.source.user_url != bound_location:
+ # not pulling from master, so we need to update master.
+ master_branch = self.target.get_master_branch(possible_transports)
+ master_branch.lock_write()
try:
- # We assume that during 'pull' the target repository is closer than
- # the source one.
- self.source.update_references(self.target)
- graph = self.target.repository.get_graph(self.source.repository)
- # TODO: Branch formats should have a flag that indicates
- # that revno's are expensive, and pull() should honor that flag.
- # -- JRV20090506
- result.old_revno, result.old_revid = \
- self.target.last_revision_info()
- self.target.update_revisions(self.source, stop_revision,
- overwrite=overwrite, graph=graph)
- # TODO: The old revid should be specified when merging tags,
- # so a tags implementation that versions tags can only
- # pull in the most recent changes. -- JRV20090506
- result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
- overwrite)
- result.new_revno, result.new_revid = self.target.last_revision_info()
- if _hook_master:
- result.master_branch = _hook_master
- result.local_branch = result.target_branch
- else:
- result.master_branch = result.target_branch
- result.local_branch = None
- if run_hooks:
- for hook in Branch.hooks['post_pull']:
- hook(result)
+ if master_branch:
+ # pull from source into master.
+ master_branch.pull(self.source, overwrite, stop_revision,
+ run_hooks=False)
+ return self._pull(overwrite,
+ stop_revision, _hook_master=master_branch,
+ run_hooks=run_hooks,
+ _override_hook_target=_override_hook_target)
finally:
- self.source.unlock()
- return result
+ if master_branch:
+ master_branch.unlock()
def push(self, overwrite=False, stop_revision=None,
_override_hook_source_branch=None):
@@ -3397,48 +3384,63 @@
_run_hooks()
return result
- @classmethod
- def is_compatible(self, source, target):
- # GenericBranch uses the public API, so always compatible
- return True
-
-
-class InterToBranch5(GenericInterBranch):
-
- @staticmethod
- def _get_branch_formats_to_test():
- return BranchFormat._default_format, BzrBranchFormat5()
-
- def pull(self, overwrite=False, stop_revision=None,
- possible_transports=None, run_hooks=True,
+ def _pull(self, overwrite=False, stop_revision=None,
+ possible_transports=None, _hook_master=None, run_hooks=True,
_override_hook_target=None, local=False):
- """Pull from source into self, updating my master if any.
-
+ """See Branch.pull.
+
+ This function is the core worker, used by GenericInterBranch.pull to
+ avoid duplication when pulling source->master and source->local.
+
+ :param _hook_master: Private parameter - set the branch to
+ 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.
+ :param local: Only update the local branch, and not the bound branch.
"""
- bound_location = self.target.get_bound_location()
- if local and not bound_location:
+ # This type of branch can't be bound.
+ if local:
raise errors.LocalRequiresBoundBranch()
- master_branch = None
- if not local and bound_location and self.source.user_url != bound_location:
- # not pulling from master, so we need to update master.
- master_branch = self.target.get_master_branch(possible_transports)
- master_branch.lock_write()
+ result = PullResult()
+ result.source_branch = self.source
+ if _override_hook_target is None:
+ result.target_branch = self.target
+ else:
+ result.target_branch = _override_hook_target
+ self.source.lock_read()
try:
- if master_branch:
- # pull from source into master.
- master_branch.pull(self.source, overwrite, stop_revision,
- run_hooks=False)
- return super(InterToBranch5, self).pull(overwrite,
- stop_revision, _hook_master=master_branch,
- run_hooks=run_hooks,
- _override_hook_target=_override_hook_target)
+ # We assume that during 'pull' the target repository is closer than
+ # the source one.
+ self.source.update_references(self.target)
+ graph = self.target.repository.get_graph(self.source.repository)
+ # TODO: Branch formats should have a flag that indicates
+ # that revno's are expensive, and pull() should honor that flag.
+ # -- JRV20090506
+ result.old_revno, result.old_revid = \
+ self.target.last_revision_info()
+ self.target.update_revisions(self.source, stop_revision,
+ overwrite=overwrite, graph=graph)
+ # TODO: The old revid should be specified when merging tags,
+ # so a tags implementation that versions tags can only
+ # pull in the most recent changes. -- JRV20090506
+ result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
+ overwrite)
+ result.new_revno, result.new_revid = self.target.last_revision_info()
+ if _hook_master:
+ result.master_branch = _hook_master
+ result.local_branch = result.target_branch
+ else:
+ result.master_branch = result.target_branch
+ result.local_branch = None
+ if run_hooks:
+ for hook in Branch.hooks['post_pull']:
+ hook(result)
finally:
- if master_branch:
- master_branch.unlock()
+ self.source.unlock()
+ return result
InterBranch.register_optimiser(GenericInterBranch)
-InterBranch.register_optimiser(InterToBranch5)
=== modified file 'bzrlib/tests/per_branch/test_pull.py'
--- a/bzrlib/tests/per_branch/test_pull.py 2010-02-10 17:52:08 +0000
+++ b/bzrlib/tests/per_branch/test_pull.py 2010-06-14 06:37:11 +0000
@@ -98,17 +98,6 @@
master_tree.branch.pull, other.branch, local = True)
self.assertEqual([rev1], master_tree.branch.revision_history())
- def test_pull_raises_specific_error_on_master_connection_error(self):
- master_tree = self.make_branch_and_tree('master')
- checkout = master_tree.branch.create_checkout('checkout')
- other = master_tree.branch.bzrdir.sprout('other').open_workingtree()
- # move the branch out of the way on disk to cause a connection
- # error.
- os.rename('master', 'master_gone')
- # try to pull, which should raise a BoundBranchConnectionFailure.
- self.assertRaises(errors.BoundBranchConnectionFailure,
- checkout.branch.pull, other.branch)
-
def test_pull_returns_result(self):
parent = self.make_branch_and_tree('parent')
parent.commit('1st post', rev_id='P1')
=== modified file 'bzrlib/tests/per_interbranch/__init__.py'
--- a/bzrlib/tests/per_interbranch/__init__.py 2009-05-07 05:08:46 +0000
+++ b/bzrlib/tests/per_interbranch/__init__.py 2010-06-14 06:37:11 +0000
@@ -146,6 +146,7 @@
def load_tests(standard_tests, module, loader):
submod_tests = loader.loadTestsFromModuleNames([
+ 'bzrlib.tests.per_interbranch.test_get',
'bzrlib.tests.per_interbranch.test_pull',
'bzrlib.tests.per_interbranch.test_push',
'bzrlib.tests.per_interbranch.test_update_revisions',
=== added file 'bzrlib/tests/per_interbranch/test_get.py'
--- a/bzrlib/tests/per_interbranch/test_get.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/per_interbranch/test_get.py 2010-06-14 06:37:11 +0000
@@ -0,0 +1,34 @@
+# Copyright (C) 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Tests for bzrlib.branch.InterBranch.get."""
+
+from bzrlib import (
+ branch,
+ )
+from bzrlib.tests.per_interbranch import (
+ TestCaseWithInterBranch,
+ )
+
+
+class TestCopyContentInto(TestCaseWithInterBranch):
+
+ def test_gets_right_inter(self):
+ self.tree1 = self.make_branch_and_tree('tree1')
+ branch2 = self.make_to_branch('tree2')
+ self.assertIs(branch.InterBranch.get(
+ self.tree1.branch, branch2).__class__,
+ self.interbranch_class)
=== modified file 'bzrlib/tests/per_interbranch/test_pull.py'
--- a/bzrlib/tests/per_interbranch/test_pull.py 2009-07-10 05:49:34 +0000
+++ b/bzrlib/tests/per_interbranch/test_pull.py 2010-06-14 06:37:11 +0000
@@ -76,13 +76,13 @@
def test_pull_raises_specific_error_on_master_connection_error(self):
master_tree = self.make_from_branch_and_tree('master')
checkout = master_tree.branch.create_checkout('checkout')
- other = self.sprout_to(master_tree.branch.bzrdir, 'other').open_workingtree()
+ other = self.sprout_to(master_tree.branch.bzrdir, 'other').open_branch()
# move the branch out of the way on disk to cause a connection
# error.
os.rename('master', 'master_gone')
# try to pull, which should raise a BoundBranchConnectionFailure.
self.assertRaises(errors.BoundBranchConnectionFailure,
- checkout.branch.pull, other.branch)
+ checkout.branch.pull, other)
def test_pull_returns_result(self):
parent = self.make_from_branch_and_tree('parent')
More information about the bazaar-commits
mailing list