Rev 3235: Ensure opening a stacked branch gives a ready to use repository. in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
Robert Collins
robertc at robertcollins.net
Mon Feb 25 05:13:22 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch
------------------------------------------------------------
revno: 3235
revision-id:robertc at robertcollins.net-20080225051318-akvbqjbo0q7512a2
parent: robertc at robertcollins.net-20080225041844-ftrxtegzo0yts6hv
committer: Robert Collins <robertc at robertcollins.net>
branch nick: StackableBranch
timestamp: Mon 2008-02-25 16:13:18 +1100
message:
Ensure opening a stacked branch gives a ready to use repository.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/test_branch.py test_branch.py-20060116013032-97819aa07b8ab3b5
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2008-02-25 04:18:44 +0000
+++ b/bzrlib/branch.py 2008-02-25 05:13:18 +0000
@@ -103,6 +103,10 @@
self.tags = self._make_tags()
self._revision_history_cache = None
self._revision_id_to_revno_cache = None
+ self._open_hook()
+
+ def _open_hook(self):
+ """Called by init to allow simpler extension of the base class."""
def break_lock(self):
"""Break a lock if one is present from another instance.
@@ -1352,7 +1356,6 @@
def __init__(self, _format=None,
_control_files=None, a_bzrdir=None, _repository=None):
"""Create new branch object at a particular location."""
- Branch.__init__(self)
if a_bzrdir is None:
raise ValueError('a_bzrdir must be supplied')
else:
@@ -1367,6 +1370,7 @@
self.control_files = _control_files
self._transport = _control_files._transport
self.repository = _repository
+ Branch.__init__(self)
def __str__(self):
return '%s(%r)' % (self.__class__.__name__, self.base)
@@ -1755,16 +1759,6 @@
It has support for a master_branch which is the data for bound branches.
"""
- def __init__(self,
- _format,
- _control_files,
- a_bzrdir,
- _repository):
- super(BzrBranch5, self).__init__(_format=_format,
- _control_files=_control_files,
- a_bzrdir=a_bzrdir,
- _repository=_repository)
-
@needs_write_lock
def pull(self, source, overwrite=False, stop_revision=None,
run_hooks=True, possible_transports=None):
@@ -1885,6 +1879,20 @@
class BzrBranch7(BzrBranch5):
+ def _activate_fallback_location(self, url):
+ """Activate the branch/repository from url as a fallback repository."""
+ new_repo = bzrdir.BzrDir.open(url).open_branch().repository
+ self.repository.add_fallback_repository(new_repo)
+
+ def _open_hook(self):
+ try:
+ url = self.get_stacked_on()
+ except (errors.UnstackableRepositoryFormat, errors.NotStacked,
+ errors.UnstackableBranchFormat):
+ pass
+ else:
+ self._activate_fallback_location(url)
+
def _check_stackable_repo(self):
if not self.repository._format.supports_external_lookups:
raise errors.UnstackableRepositoryFormat(self.repository._format,
@@ -2022,8 +2030,7 @@
# reopen it.
self.repository = self.bzrdir.find_repository()
else:
- new_repo = bzrdir.BzrDir.open(url).open_branch().repository
- self.repository.add_fallback_repository(new_repo)
+ self._activate_fallback_location(url)
# write this out after the repository is stacked to avoid setting a
# stacked config that doesn't work.
self.control_files.put_utf8('stacked-on', url + '\n')
=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py 2008-02-25 04:18:44 +0000
+++ b/bzrlib/tests/test_branch.py 2008-02-25 05:13:18 +0000
@@ -365,6 +365,14 @@
self.assertRaises(errors.NotStacked, branch.get_stacked_on)
self.assertFalse(branch.repository.has_revision(revid))
+ def test_open_opens_stacked_reference(self):
+ branch = self.make_branch('a', format=self.get_format_name())
+ target = self.make_branch_and_tree('b', format=self.get_format_name())
+ branch.set_stacked_on(target.branch.base)
+ branch = branch.bzrdir.open_branch()
+ revid = target.commit('foo')
+ self.assertTrue(branch.repository.has_revision(revid))
+
class TestBranchReference(TestCaseWithTransport):
"""Tests for the branch reference facility."""
More information about the bazaar-commits
mailing list