~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-03-02 20:45:08 UTC
  • mfrom: (5051.3.9 named-branches)
  • Revision ID: pqm@pqm.ubuntu.com-20100302204508-4j07g2h9wj49o494
(Jelmer) Add name argument to BzrDir.create_branch(),
        BzrDir.destroy_branch() and BzrDir.open_branch().

Show diffs side-by-side

added added

removed removed

Lines of Context:
396
396
        """Destroy the repository in this BzrDir"""
397
397
        raise NotImplementedError(self.destroy_repository)
398
398
 
399
 
    def create_branch(self):
 
399
    def create_branch(self, name=None):
400
400
        """Create a branch in this BzrDir.
401
401
 
 
402
        :param name: Name of the colocated branch to create, None for
 
403
            the default branch.
 
404
 
402
405
        The bzrdir's format will control what branch format is created.
403
406
        For more control see BranchFormatXX.create(a_bzrdir).
404
407
        """
405
408
        raise NotImplementedError(self.create_branch)
406
409
 
407
 
    def destroy_branch(self):
408
 
        """Destroy the branch in this BzrDir"""
 
410
    def destroy_branch(self, name=None):
 
411
        """Destroy a branch in this BzrDir.
 
412
        
 
413
        :param name: Name of the branch to destroy, None for the default 
 
414
            branch.
 
415
        """
409
416
        raise NotImplementedError(self.destroy_branch)
410
417
 
411
418
    @staticmethod
892
899
        BzrDir._check_supported(format, _unsupported)
893
900
        return format.open(transport, _found=True)
894
901
 
895
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
902
    def open_branch(self, name=None, unsupported=False,
 
903
                    ignore_fallbacks=False):
896
904
        """Open the branch object at this BzrDir if one is present.
897
905
 
898
906
        If unsupported is True, then no longer supported branch formats can
1036
1044
        """
1037
1045
        raise NotImplementedError(self.open_workingtree)
1038
1046
 
1039
 
    def has_branch(self):
 
1047
    def has_branch(self, name=None):
1040
1048
        """Tell if this bzrdir contains a branch.
1041
1049
 
1042
1050
        Note: if you're going to open the branch, you should just go ahead
1044
1052
        branch and discards it, and that's somewhat expensive.)
1045
1053
        """
1046
1054
        try:
1047
 
            self.open_branch()
 
1055
            self.open_branch(name)
1048
1056
            return True
1049
1057
        except errors.NotBranchError:
1050
1058
            return False
1373
1381
            tree.clone(result)
1374
1382
        return result
1375
1383
 
1376
 
    def create_branch(self):
 
1384
    def create_branch(self, name=None):
1377
1385
        """See BzrDir.create_branch."""
 
1386
        if name is not None:
 
1387
            raise errors.NoColocatedBranchSupport(self)
1378
1388
        return self._format.get_branch_format().initialize(self)
1379
1389
 
1380
 
    def destroy_branch(self):
 
1390
    def destroy_branch(self, name=None):
1381
1391
        """See BzrDir.destroy_branch."""
1382
1392
        raise errors.UnsupportedOperation(self.destroy_branch, self)
1383
1393
 
1479
1489
            format = BzrDirFormat.get_default_format()
1480
1490
        return not isinstance(self._format, format.__class__)
1481
1491
 
1482
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
1492
    def open_branch(self, name=None, unsupported=False,
 
1493
                    ignore_fallbacks=False):
1483
1494
        """See BzrDir.open_branch."""
 
1495
        if name is not None:
 
1496
            raise errors.NoColocatedBranchSupport(self)
1484
1497
        from bzrlib.branch import BzrBranchFormat4
1485
1498
        format = BzrBranchFormat4()
1486
1499
        self._check_supported(format, unsupported)
1607
1620
        """See BzrDir.can_convert_format()."""
1608
1621
        return True
1609
1622
 
1610
 
    def create_branch(self):
 
1623
    def create_branch(self, name=None):
1611
1624
        """See BzrDir.create_branch."""
 
1625
        if name is not None:
 
1626
            raise errors.NoColocatedBranchSupport(self)
1612
1627
        return self._format.get_branch_format().initialize(self)
1613
1628
 
1614
 
    def destroy_branch(self):
 
1629
    def destroy_branch(self, name=None):
1615
1630
        """See BzrDir.create_branch."""
 
1631
        if name is not None:
 
1632
            raise errors.NoColocatedBranchSupport(self)
1616
1633
        self.transport.delete_tree('branch')
1617
1634
 
1618
1635
    def create_repository(self, shared=False):
1739
1756
                return True
1740
1757
        except errors.NoRepositoryPresent:
1741
1758
            pass
1742
 
        try:
1743
 
            if not isinstance(self.open_branch()._format,
 
1759
        for branch in self.list_branches():
 
1760
            if not isinstance(branch._format,
1744
1761
                              format.get_branch_format().__class__):
1745
1762
                # the branch needs an upgrade.
1746
1763
                return True
1747
 
        except errors.NotBranchError:
1748
 
            pass
1749
1764
        try:
1750
1765
            my_wt = self.open_workingtree(recommend_upgrade=False)
1751
1766
            if not isinstance(my_wt._format,
1756
1771
            pass
1757
1772
        return False
1758
1773
 
1759
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
1774
    def open_branch(self, name=None, unsupported=False,
 
1775
                    ignore_fallbacks=False):
1760
1776
        """See BzrDir.open_branch."""
 
1777
        if name is not None:
 
1778
            raise errors.NoColocatedBranchSupport(self)
1761
1779
        format = self.find_branch_format()
1762
1780
        self._check_supported(format, unsupported)
1763
1781
        return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
1820
1838
 
1821
1839
    _lock_file_name = 'branch-lock'
1822
1840
 
 
1841
    colocated_branches = False
 
1842
    """Whether co-located branches are supported for this control dir format.
 
1843
    """
 
1844
 
1823
1845
    # _lock_class must be set in subclasses to the lock type, typ.
1824
1846
    # TransportLock or LockDir
1825
1847