~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Ensure opening a stacked branch gives a ready to use repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        self.tags = self._make_tags()
104
104
        self._revision_history_cache = None
105
105
        self._revision_id_to_revno_cache = None
 
106
        self._open_hook()
 
107
 
 
108
    def _open_hook(self):
 
109
        """Called by init to allow simpler extension of the base class."""
106
110
 
107
111
    def break_lock(self):
108
112
        """Break a lock if one is present from another instance.
1352
1356
    def __init__(self, _format=None,
1353
1357
                 _control_files=None, a_bzrdir=None, _repository=None):
1354
1358
        """Create new branch object at a particular location."""
1355
 
        Branch.__init__(self)
1356
1359
        if a_bzrdir is None:
1357
1360
            raise ValueError('a_bzrdir must be supplied')
1358
1361
        else:
1367
1370
        self.control_files = _control_files
1368
1371
        self._transport = _control_files._transport
1369
1372
        self.repository = _repository
 
1373
        Branch.__init__(self)
1370
1374
 
1371
1375
    def __str__(self):
1372
1376
        return '%s(%r)' % (self.__class__.__name__, self.base)
1755
1759
    It has support for a master_branch which is the data for bound branches.
1756
1760
    """
1757
1761
 
1758
 
    def __init__(self,
1759
 
                 _format,
1760
 
                 _control_files,
1761
 
                 a_bzrdir,
1762
 
                 _repository):
1763
 
        super(BzrBranch5, self).__init__(_format=_format,
1764
 
                                         _control_files=_control_files,
1765
 
                                         a_bzrdir=a_bzrdir,
1766
 
                                         _repository=_repository)
1767
 
        
1768
1762
    @needs_write_lock
1769
1763
    def pull(self, source, overwrite=False, stop_revision=None,
1770
1764
             run_hooks=True, possible_transports=None):
1885
1879
 
1886
1880
class BzrBranch7(BzrBranch5):
1887
1881
 
 
1882
    def _activate_fallback_location(self, url):
 
1883
        """Activate the branch/repository from url as a fallback repository."""
 
1884
        new_repo = bzrdir.BzrDir.open(url).open_branch().repository
 
1885
        self.repository.add_fallback_repository(new_repo)
 
1886
 
 
1887
    def _open_hook(self):
 
1888
        try:
 
1889
            url = self.get_stacked_on()
 
1890
        except (errors.UnstackableRepositoryFormat, errors.NotStacked,
 
1891
            errors.UnstackableBranchFormat):
 
1892
            pass
 
1893
        else:
 
1894
            self._activate_fallback_location(url)
 
1895
 
1888
1896
    def _check_stackable_repo(self):
1889
1897
        if not self.repository._format.supports_external_lookups:
1890
1898
            raise errors.UnstackableRepositoryFormat(self.repository._format,
2022
2030
            # reopen it.
2023
2031
            self.repository = self.bzrdir.find_repository()
2024
2032
        else:
2025
 
            new_repo = bzrdir.BzrDir.open(url).open_branch().repository
2026
 
            self.repository.add_fallback_repository(new_repo)
 
2033
            self._activate_fallback_location(url)
2027
2034
        # write this out after the repository is stacked to avoid setting a
2028
2035
        # stacked config that doesn't work.
2029
2036
        self.control_files.put_utf8('stacked-on', url + '\n')