Rev 4229: (robertc) Lift up Branch7.set_stacked_on_url to Branch, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Apr 1 07:34:37 BST 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 4229
revision-id: pqm at pqm.ubuntu.com-20090401063434-motksin95y4undi6
parent: pqm at pqm.ubuntu.com-20090401054055-ljlwhq6q0w6eju8s
parent: robertc at robertcollins.net-20090401054558-i6u5qxltq0q096or
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-04-01 07:34:34 +0100
message:
(robertc) Lift up Branch7.set_stacked_on_url to Branch,
allowing reuse by RemoteBranch and decreasing round trips for pushing
new stacked branches. (Robert Collins, Andrew Bennetts)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
------------------------------------------------------------
revno: 4226.1.4
revision-id: robertc at robertcollins.net-20090401054558-i6u5qxltq0q096or
parent: robertc at robertcollins.net-20090401050238-fdgxounwbejqff9z
committer: Robert Collins <robertc at robertcollins.net>
branch nick: Branch.set_stacked_on_url
timestamp: Wed 2009-04-01 16:45:58 +1100
message:
Simplify code in RemoteBranch to use helpers from Branch.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
------------------------------------------------------------
revno: 4226.1.3
revision-id: robertc at robertcollins.net-20090401050238-fdgxounwbejqff9z
parent: robertc at robertcollins.net-20090401040529-vwb8tpu42jk2m0w6
committer: Robert Collins <robertc at robertcollins.net>
branch nick: Branch.set_stacked_on_url
timestamp: Wed 2009-04-01 16:02:38 +1100
message:
Lift Branch.set_stacked_on_url up from BzrBranch7.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
=== modified file 'NEWS'
--- a/NEWS 2009-03-31 08:50:05 +0000
+++ b/NEWS 2009-04-01 05:02:38 +0000
@@ -222,6 +222,11 @@
Internals
*********
+* ``Branch`` now implements ``set_stacked_on_url`` in the base class as
+ the implementation is generic and should impact foreign formats. This
+ helps performance for ``RemoteBranch`` push operations to new stacked
+ branches. (Robert Collins, Andrew Bennetts)
+
* ``BtreeIndex._spill_mem_keys_to_disk()`` now generates disk index with
optmizations turned off. This only has effect when processing > 100,000
keys during something like ``bzr pack``. (John Arbash Meinel)
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-03-25 04:20:12 +0000
+++ b/bzrlib/branch.py 2009-04-01 05:45:58 +0000
@@ -99,6 +99,11 @@
def _open_hook(self):
"""Called by init to allow simpler extension of the base class."""
+ def _activate_fallback_location(self, url):
+ """Activate the branch/repository from url as a fallback repository."""
+ self.repository.add_fallback_repository(
+ self._get_fallback_repository(url))
+
def break_lock(self):
"""Break a lock if one is present from another instance.
@@ -113,6 +118,11 @@
if master is not None:
master.break_lock()
+ def _check_stackable_repo(self):
+ if not self.repository._format.supports_external_lookups:
+ raise errors.UnstackableRepositoryFormat(self.repository._format,
+ self.repository.base)
+
@staticmethod
def open(base, _unsupported=False, possible_transports=None):
"""Open the branch rooted at base.
@@ -157,6 +167,13 @@
def get_config(self):
return BranchConfig(self)
+ def _get_fallback_repository(self, url):
+ """Get the repository we fallback to at url."""
+ url = urlutils.join(self.base, url)
+ a_bzrdir = bzrdir.BzrDir.open(url,
+ possible_transports=[self.bzrdir.root_transport])
+ return a_bzrdir.open_branch().repository
+
def _get_tags_bytes(self):
"""Get the bytes of a serialised tags dict.
@@ -569,7 +586,33 @@
:raises UnstackableRepositoryFormat: If the repository does not support
stacking.
"""
- raise NotImplementedError(self.set_stacked_on_url)
+ if not self._format.supports_stacking():
+ raise errors.UnstackableBranchFormat(self._format, self.base)
+ self._check_stackable_repo()
+ if not url:
+ try:
+ old_url = self.get_stacked_on_url()
+ except (errors.NotStacked, errors.UnstackableBranchFormat,
+ errors.UnstackableRepositoryFormat):
+ return
+ url = ''
+ # repositories don't offer an interface to remove fallback
+ # repositories today; take the conceptually simpler option and just
+ # reopen it.
+ self.repository = self.bzrdir.find_repository()
+ # for every revision reference the branch has, ensure it is pulled
+ # in.
+ source_repository = self._get_fallback_repository(old_url)
+ for revision_id in chain([self.last_revision()],
+ self.tags.get_reverse_tag_dict()):
+ self.repository.fetch(source_repository, revision_id,
+ find_ghosts=True)
+ else:
+ self._activate_fallback_location(url)
+ # write this out after the repository is stacked to avoid setting a
+ # stacked config that doesn't work.
+ self._set_config_location('stacked_on_location', url)
+
def _set_tags_bytes(self, bytes):
"""Mirror method for _get_tags_bytes.
@@ -2161,9 +2204,6 @@
self._transport.put_bytes('parent', url + '\n',
mode=self.bzrdir._get_file_mode())
- def set_stacked_on_url(self, url):
- raise errors.UnstackableBranchFormat(self._format, self.base)
-
class BzrBranch5(BzrBranch):
"""A format 5 branch. This supports new features over plain branches.
@@ -2295,18 +2335,6 @@
class BzrBranch7(BzrBranch5):
"""A branch with support for a fallback repository."""
- def _get_fallback_repository(self, url):
- """Get the repository we fallback to at url."""
- url = urlutils.join(self.base, url)
- a_bzrdir = bzrdir.BzrDir.open(url,
- possible_transports=[self._transport])
- return a_bzrdir.open_branch().repository
-
- def _activate_fallback_location(self, url):
- """Activate the branch/repository from url as a fallback repository."""
- self.repository.add_fallback_repository(
- self._get_fallback_repository(url))
-
def _open_hook(self):
if self._ignore_fallbacks:
return
@@ -2325,11 +2353,6 @@
"None, not a URL." % hook_name)
self._activate_fallback_location(url)
- def _check_stackable_repo(self):
- if not self.repository._format.supports_external_lookups:
- raise errors.UnstackableRepositoryFormat(self.repository._format,
- self.repository.base)
-
def __init__(self, *args, **kwargs):
self._ignore_fallbacks = kwargs.get('ignore_fallbacks', False)
super(BzrBranch7, self).__init__(*args, **kwargs)
@@ -2510,32 +2533,6 @@
self.get_config().set_user_option('append_revisions_only', value,
warn_masked=True)
- def set_stacked_on_url(self, url):
- self._check_stackable_repo()
- if not url:
- try:
- old_url = self.get_stacked_on_url()
- except (errors.NotStacked, errors.UnstackableBranchFormat,
- errors.UnstackableRepositoryFormat):
- return
- url = ''
- # repositories don't offer an interface to remove fallback
- # repositories today; take the conceptually simpler option and just
- # reopen it.
- self.repository = self.bzrdir.find_repository()
- # for every revision reference the branch has, ensure it is pulled
- # in.
- source_repository = self._get_fallback_repository(old_url)
- for revision_id in chain([self.last_revision()],
- self.tags.get_reverse_tag_dict()):
- self.repository.fetch(source_repository, revision_id,
- find_ghosts=True)
- else:
- self._activate_fallback_location(url)
- # write this out after the repository is stacked to avoid setting a
- # stacked config that doesn't work.
- self._set_config_location('stacked_on_location', url)
-
def _get_append_revisions_only(self):
value = self.get_config().get_user_option('append_revisions_only')
return value == 'True'
@@ -2594,9 +2591,6 @@
def get_stacked_on_url(self):
raise errors.UnstackableBranchFormat(self._format, self.base)
- def set_stacked_on_url(self, url):
- raise errors.UnstackableBranchFormat(self._format, self.base)
-
######################################################################
# results of operations
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-04-01 03:53:19 +0000
+++ b/bzrlib/remote.py 2009-04-01 05:45:58 +0000
@@ -1935,12 +1935,7 @@
except (errors.NotStacked, errors.UnstackableBranchFormat,
errors.UnstackableRepositoryFormat), e:
return
- # it's relative to this branch...
- fallback_url = urlutils.join(self.base, fallback_url)
- transports = [self.bzrdir.root_transport]
- stacked_on = branch.Branch.open(fallback_url,
- possible_transports=transports)
- self.repository.add_fallback_repository(stacked_on.repository)
+ self._activate_fallback_location(fallback_url)
def _get_real_transport(self):
# if we try vfs access, return the real branch's vfs transport
@@ -2288,17 +2283,6 @@
self._ensure_real()
return self._real_branch._set_parent_location(url)
- def set_stacked_on_url(self, stacked_location):
- """Set the URL this branch is stacked against.
-
- :raises UnstackableBranchFormat: If the branch does not support
- stacking.
- :raises UnstackableRepositoryFormat: If the repository does not support
- stacking.
- """
- self._ensure_real()
- return self._real_branch.set_stacked_on_url(stacked_location)
-
@needs_write_lock
def pull(self, source, overwrite=False, stop_revision=None,
**kwargs):
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2009-04-01 03:53:19 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2009-04-01 05:02:38 +0000
@@ -217,7 +217,7 @@
# being too low. If rpc_count increases, more network roundtrips have
# become necessary for this use case. Please do not adjust this number
# upwards without agreement from bzr's network support maintainers.
- self.assertLength(52, self.hpss_calls)
+ self.assertLength(47, self.hpss_calls)
remote = Branch.open('public')
self.assertEndsWith(remote.get_stacked_on_url(), '/parent')
More information about the bazaar-commits
mailing list