~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Ian Clatworthy
  • Date: 2010-03-30 20:13:52 UTC
  • mto: This revision was merged to the branch mainline in revision 5125.
  • Revision ID: ian.clatworthy@canonical.com-20100330201352-vw2gtujybyg3rvwc
whitespace fix in win32 installer

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
580
587
 
581
588
        :return: Tuple with old path name and new path name
582
589
        """
 
590
        def name_gen(base='backup.bzr'):
 
591
            counter = 1
 
592
            name = "%s.~%d~" % (base, counter)
 
593
            while self.root_transport.has(name):
 
594
                counter += 1
 
595
                name = "%s.~%d~" % (base, counter)
 
596
            return name
 
597
 
 
598
        backup_dir=name_gen()
583
599
        pb = ui.ui_factory.nested_progress_bar()
584
600
        try:
585
601
            # FIXME: bug 300001 -- the backup fails if the backup directory
586
602
            # already exists, but it should instead either remove it or make
587
603
            # a new backup directory.
588
604
            #
589
 
            # FIXME: bug 262450 -- the backup directory should have the same
590
 
            # permissions as the .bzr directory (probably a bug in copy_tree)
591
605
            old_path = self.root_transport.abspath('.bzr')
592
 
            new_path = self.root_transport.abspath('backup.bzr')
 
606
            new_path = self.root_transport.abspath(backup_dir)
593
607
            ui.ui_factory.note('making backup of %s\n  to %s' % (old_path, new_path,))
594
 
            self.root_transport.copy_tree('.bzr', 'backup.bzr')
 
608
            self.root_transport.copy_tree('.bzr', backup_dir)
595
609
            return (old_path, new_path)
596
610
        finally:
597
611
            pb.finished()
699
713
        """
700
714
        return None
701
715
 
702
 
    def get_branch_transport(self, branch_format):
 
716
    def get_branch_transport(self, branch_format, name=None):
703
717
        """Get the transport for use by branch format in this BzrDir.
704
718
 
705
719
        Note that bzr dirs that do not support format strings will raise
883
897
        BzrDir._check_supported(format, _unsupported)
884
898
        return format.open(transport, _found=True)
885
899
 
886
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
900
    def open_branch(self, name=None, unsupported=False,
 
901
                    ignore_fallbacks=False):
887
902
        """Open the branch object at this BzrDir if one is present.
888
903
 
889
904
        If unsupported is True, then no longer supported branch formats can
1027
1042
        """
1028
1043
        raise NotImplementedError(self.open_workingtree)
1029
1044
 
1030
 
    def has_branch(self):
 
1045
    def has_branch(self, name=None):
1031
1046
        """Tell if this bzrdir contains a branch.
1032
1047
 
1033
1048
        Note: if you're going to open the branch, you should just go ahead
1035
1050
        branch and discards it, and that's somewhat expensive.)
1036
1051
        """
1037
1052
        try:
1038
 
            self.open_branch()
 
1053
            self.open_branch(name)
1039
1054
            return True
1040
1055
        except errors.NotBranchError:
1041
1056
            return False
1364
1379
            tree.clone(result)
1365
1380
        return result
1366
1381
 
1367
 
    def create_branch(self):
 
1382
    def create_branch(self, name=None):
1368
1383
        """See BzrDir.create_branch."""
1369
 
        return self._format.get_branch_format().initialize(self)
 
1384
        return self._format.get_branch_format().initialize(self, name=name)
1370
1385
 
1371
 
    def destroy_branch(self):
 
1386
    def destroy_branch(self, name=None):
1372
1387
        """See BzrDir.destroy_branch."""
1373
1388
        raise errors.UnsupportedOperation(self.destroy_branch, self)
1374
1389
 
1430
1445
        raise errors.UnsupportedOperation(self.destroy_workingtree_metadata,
1431
1446
                                          self)
1432
1447
 
1433
 
    def get_branch_transport(self, branch_format):
 
1448
    def get_branch_transport(self, branch_format, name=None):
1434
1449
        """See BzrDir.get_branch_transport()."""
 
1450
        if name is not None:
 
1451
            raise errors.NoColocatedBranchSupport(self)
1435
1452
        if branch_format is None:
1436
1453
            return self.transport
1437
1454
        try:
1470
1487
            format = BzrDirFormat.get_default_format()
1471
1488
        return not isinstance(self._format, format.__class__)
1472
1489
 
1473
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
1490
    def open_branch(self, name=None, unsupported=False,
 
1491
                    ignore_fallbacks=False):
1474
1492
        """See BzrDir.open_branch."""
1475
1493
        from bzrlib.branch import BzrBranchFormat4
1476
1494
        format = BzrBranchFormat4()
1477
1495
        self._check_supported(format, unsupported)
1478
 
        return format.open(self, _found=True)
 
1496
        return format.open(self, name, _found=True)
1479
1497
 
1480
1498
    def sprout(self, url, revision_id=None, force_new_repo=False,
1481
1499
               possible_transports=None, accelerator_tree=None,
1598
1616
        """See BzrDir.can_convert_format()."""
1599
1617
        return True
1600
1618
 
1601
 
    def create_branch(self):
 
1619
    def create_branch(self, name=None):
1602
1620
        """See BzrDir.create_branch."""
1603
 
        return self._format.get_branch_format().initialize(self)
 
1621
        return self._format.get_branch_format().initialize(self, name=name)
1604
1622
 
1605
 
    def destroy_branch(self):
 
1623
    def destroy_branch(self, name=None):
1606
1624
        """See BzrDir.create_branch."""
 
1625
        if name is not None:
 
1626
            raise errors.NoColocatedBranchSupport(self)
1607
1627
        self.transport.delete_tree('branch')
1608
1628
 
1609
1629
    def create_repository(self, shared=False):
1652
1672
        format = BranchFormat.find_format(self)
1653
1673
        return format.get_reference(self)
1654
1674
 
1655
 
    def get_branch_transport(self, branch_format):
 
1675
    def get_branch_transport(self, branch_format, name=None):
1656
1676
        """See BzrDir.get_branch_transport()."""
 
1677
        if name is not None:
 
1678
            raise errors.NoColocatedBranchSupport(self)
1657
1679
        # XXX: this shouldn't implicitly create the directory if it's just
1658
1680
        # promising to get a transport -- mbp 20090727
1659
1681
        if branch_format is None:
1730
1752
                return True
1731
1753
        except errors.NoRepositoryPresent:
1732
1754
            pass
1733
 
        try:
1734
 
            if not isinstance(self.open_branch()._format,
 
1755
        for branch in self.list_branches():
 
1756
            if not isinstance(branch._format,
1735
1757
                              format.get_branch_format().__class__):
1736
1758
                # the branch needs an upgrade.
1737
1759
                return True
1738
 
        except errors.NotBranchError:
1739
 
            pass
1740
1760
        try:
1741
1761
            my_wt = self.open_workingtree(recommend_upgrade=False)
1742
1762
            if not isinstance(my_wt._format,
1747
1767
            pass
1748
1768
        return False
1749
1769
 
1750
 
    def open_branch(self, unsupported=False, ignore_fallbacks=False):
 
1770
    def open_branch(self, name=None, unsupported=False,
 
1771
                    ignore_fallbacks=False):
1751
1772
        """See BzrDir.open_branch."""
1752
1773
        format = self.find_branch_format()
1753
1774
        self._check_supported(format, unsupported)
1754
 
        return format.open(self, _found=True, ignore_fallbacks=ignore_fallbacks)
 
1775
        return format.open(self, name=name,
 
1776
            _found=True, ignore_fallbacks=ignore_fallbacks)
1755
1777
 
1756
1778
    def open_repository(self, unsupported=False):
1757
1779
        """See BzrDir.open_repository."""
1789
1811
    Once a format is deprecated, just deprecate the initialize and open
1790
1812
    methods on the format class. Do not deprecate the object, as the
1791
1813
    object will be created every system load.
 
1814
 
 
1815
    :cvar colocated_branches: Whether this formats supports colocated branches.
1792
1816
    """
1793
1817
 
1794
1818
    _default_format = None
1811
1835
 
1812
1836
    _lock_file_name = 'branch-lock'
1813
1837
 
 
1838
    colocated_branches = False
 
1839
    """Whether co-located branches are supported for this control dir format.
 
1840
    """
 
1841
 
1814
1842
    # _lock_class must be set in subclasses to the lock type, typ.
1815
1843
    # TransportLock or LockDir
1816
1844