~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
                            sha_strings,
40
40
                            sha_string,
41
41
                            )
 
42
import bzrlib.revision
42
43
from bzrlib.store.revision.text import TextRevisionStore
43
44
from bzrlib.store.text import TextStore
44
45
from bzrlib.store.versioned import WeaveStore
460
461
        _unsupported is a private parameter to the BzrDir class.
461
462
        """
462
463
        t = get_transport(base)
463
 
        mutter("trying to open %r with transport %r", base, t)
 
464
        # mutter("trying to open %r with transport %r", base, t)
464
465
        format = BzrDirFormat.find_format(t)
465
466
        BzrDir._check_supported(format, _unsupported)
466
467
        return format.open(t, _found=True)
615
616
                # XXX FIXME RBC 20060214 need tests for this when the basis
616
617
                # is incomplete
617
618
                result_repo.fetch(basis_repo, revision_id=revision_id)
618
 
            result_repo.fetch(source_repository, revision_id=revision_id)
 
619
            if source_repository is not None:
 
620
                result_repo.fetch(source_repository, revision_id=revision_id)
619
621
        if source_branch is not None:
620
622
            source_branch.sprout(result, revision_id=revision_id)
621
623
        else:
685
687
        # done on this format anyway. So - acceptable wart.
686
688
        result = self.open_workingtree()
687
689
        if revision_id is not None:
688
 
            result.set_last_revision(revision_id)
 
690
            if revision_id == bzrlib.revision.NULL_REVISION:
 
691
                result.set_parent_ids([])
 
692
            else:
 
693
                result.set_parent_ids([revision_id])
689
694
        return result
690
695
 
691
696
    def get_branch_transport(self, branch_format):
733
738
        self._check_supported(format, unsupported)
734
739
        return format.open(self, _found=True)
735
740
 
736
 
    def sprout(self, url, revision_id=None, basis=None):
 
741
    def sprout(self, url, revision_id=None, basis=None, force_new_repo=False):
737
742
        """See BzrDir.sprout()."""
738
743
        from bzrlib.workingtree import WorkingTreeFormat2
739
744
        self._make_tail(url)
1217
1222
        result = (super(BzrDirFormat5, self).initialize_on_transport(transport))
1218
1223
        RepositoryFormat5().initialize(result, _internal=True)
1219
1224
        if not _cloning:
1220
 
            BzrBranchFormat4().initialize(result)
1221
 
            WorkingTreeFormat2().initialize(result)
 
1225
            branch = BzrBranchFormat4().initialize(result)
 
1226
            try:
 
1227
                WorkingTreeFormat2().initialize(result)
 
1228
            except errors.NotLocalUrl:
 
1229
                # Even though we can't access the working tree, we need to
 
1230
                # create its control files.
 
1231
                WorkingTreeFormat2().stub_initialize_remote(branch.control_files)
1222
1232
        return result
1223
1233
 
1224
1234
    def _open(self, transport):
1271
1281
        result = super(BzrDirFormat6, self).initialize_on_transport(transport)
1272
1282
        RepositoryFormat6().initialize(result, _internal=True)
1273
1283
        if not _cloning:
1274
 
            BzrBranchFormat4().initialize(result)
 
1284
            branch = BzrBranchFormat4().initialize(result)
1275
1285
            try:
1276
1286
                WorkingTreeFormat2().initialize(result)
1277
1287
            except errors.NotLocalUrl:
1278
 
                # emulate pre-check behaviour for working tree and silently 
1279
 
                # fail.
1280
 
                pass
 
1288
                # Even though we can't access the working tree, we need to
 
1289
                # create its control files.
 
1290
                WorkingTreeFormat2().stub_initialize_remote(branch.control_files)
1281
1291
        return result
1282
1292
 
1283
1293
    def _open(self, transport):
1743
1753
        for entry in branch_files:
1744
1754
            self.move_entry('branch', entry)
1745
1755
 
1746
 
        self.step('Upgrading working tree')
1747
 
        self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
1748
 
        self.make_lock('checkout')
1749
 
        self.put_format('checkout', bzrlib.workingtree.WorkingTreeFormat3())
1750
 
        self.bzrdir.transport.delete_multi(self.garbage_inventories, self.pb)
1751
1756
        checkout_files = [('pending-merges', True),
1752
1757
                          ('inventory', True),
1753
1758
                          ('stat-cache', False)]
1754
 
        for entry in checkout_files:
1755
 
            self.move_entry('checkout', entry)
1756
 
        if last_revision is not None:
1757
 
            self.bzrdir._control_files.put_utf8('checkout/last-revision',
1758
 
                                                last_revision)
1759
 
        self.bzrdir._control_files.put_utf8('branch-format', BzrDirMetaFormat1().get_format_string())
 
1759
        # If a mandatory checkout file is not present, the branch does not have
 
1760
        # a functional checkout. Do not create a checkout in the converted
 
1761
        # branch.
 
1762
        for name, mandatory in checkout_files:
 
1763
            if mandatory and name not in bzrcontents:
 
1764
                has_checkout = False
 
1765
                break
 
1766
        else:
 
1767
            has_checkout = True
 
1768
        if not has_checkout:
 
1769
            self.pb.note('No working tree.')
 
1770
            # If some checkout files are there, we may as well get rid of them.
 
1771
            for name, mandatory in checkout_files:
 
1772
                if name in bzrcontents:
 
1773
                    self.bzrdir.transport.delete(name)
 
1774
        else:
 
1775
            self.step('Upgrading working tree')
 
1776
            self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
 
1777
            self.make_lock('checkout')
 
1778
            self.put_format(
 
1779
                'checkout', bzrlib.workingtree.WorkingTreeFormat3())
 
1780
            self.bzrdir.transport.delete_multi(
 
1781
                self.garbage_inventories, self.pb)
 
1782
            for entry in checkout_files:
 
1783
                self.move_entry('checkout', entry)
 
1784
            if last_revision is not None:
 
1785
                self.bzrdir._control_files.put_utf8(
 
1786
                    'checkout/last-revision', last_revision)
 
1787
        self.bzrdir._control_files.put_utf8(
 
1788
            'branch-format', BzrDirMetaFormat1().get_format_string())
1760
1789
        return BzrDir.open(self.bzrdir.root_transport.base)
1761
1790
 
1762
1791
    def make_lock(self, name):