~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Move working tree initialisation out from  Branch.initialize, deprecated Branch.initialize to Branch.create.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
from bzrlib.store import copy_all
53
53
from bzrlib.store.text import TextStore
54
54
from bzrlib.store.weave import WeaveStore
55
 
from bzrlib.symbol_versioning import deprecated_nonce, deprecated_passed
 
55
from bzrlib.symbol_versioning import *
56
56
from bzrlib.testament import Testament
57
57
import bzrlib.transactions as transactions
58
58
from bzrlib.transport import Transport, get_transport
168
168
            t = new_t
169
169
 
170
170
    @staticmethod
171
 
    def initialize(base):
172
 
        """Create a new branch, rooted at 'base' (url)
 
171
    def create(base):
 
172
        """Create a new Branch at the url 'bzr'.
173
173
        
174
174
        This will call the current default initializer with base
175
175
        as the only parameter.
177
177
        return Branch._default_initializer(safe_unicode(base))
178
178
 
179
179
    @staticmethod
 
180
    @deprecated_function(zero_eight)
 
181
    def initialize(base):
 
182
        """Create a new working tree and branch, rooted at 'base' (url)
 
183
        """
 
184
        # imported here to prevent scope creep as this is going.
 
185
        from bzrlib.workingtree import WorkingTree
 
186
        return WorkingTree.create_standalone(safe_unicode(base)).branch
 
187
 
 
188
    @staticmethod
180
189
    def get_default_initializer():
181
190
        """Return the initializer being used for new branches."""
182
191
        return Branch._default_initializer
374
383
        If self and other have not diverged, return a list of the revisions
375
384
        present in other, but missing from self.
376
385
 
377
 
        >>> from bzrlib.commit import commit
378
386
        >>> bzrlib.trace.silent = True
379
387
        >>> br1 = ScratchBranch()
380
388
        >>> br2 = ScratchBranch()
381
389
        >>> br1.missing_revisions(br2)
382
390
        []
383
 
        >>> commit(br2, "lala!", rev_id="REVISION-ID-1")
 
391
        >>> br2.working_tree().commit("lala!", rev_id="REVISION-ID-1")
384
392
        >>> br1.missing_revisions(br2)
385
393
        [u'REVISION-ID-1']
386
394
        >>> br2.missing_revisions(br1)
387
395
        []
388
 
        >>> commit(br1, "lala!", rev_id="REVISION-ID-1")
 
396
        >>> br1.working_tree().commit("lala!", rev_id="REVISION-ID-1")
389
397
        >>> br1.missing_revisions(br2)
390
398
        []
391
 
        >>> commit(br2, "lala!", rev_id="REVISION-ID-2A")
 
399
        >>> br2.working_tree().commit("lala!", rev_id="REVISION-ID-2A")
392
400
        >>> br1.missing_revisions(br2)
393
401
        [u'REVISION-ID-2A']
394
 
        >>> commit(br1, "lala!", rev_id="REVISION-ID-2B")
 
402
        >>> br1.working_tree().commit("lala!", rev_id="REVISION-ID-2B")
395
403
        >>> br1.missing_revisions(br2)
396
404
        Traceback (most recent call last):
397
405
        DivergedBranches: These branches have diverged.  Try merge.
630
638
    def initialize(self, url):
631
639
        """Create a branch of this format at url and return an open branch."""
632
640
        t = get_transport(url)
633
 
        from bzrlib.inventory import Inventory
634
641
        from bzrlib.weavefile import write_weave_v5
635
642
        from bzrlib.weave import Weave
636
643
        
637
 
        # Create an empty inventory
638
 
        sio = StringIO()
639
 
        # if we want per-tree root ids then this is the place to set
640
 
        # them; they're not needed for now and so ommitted for
641
 
        # simplicity.
642
 
        bzrlib.xml5.serializer_v5.write_inventory(Inventory(), sio)
643
 
        empty_inv = sio.getvalue()
 
644
        # Create an empty weave
644
645
        sio = StringIO()
645
646
        bzrlib.weavefile.write_weave_v5(Weave(), sio)
646
647
        empty_weave = sio.getvalue()
659
660
            ('revision-history', StringIO('')),
660
661
            ('branch-name', StringIO('')),
661
662
            ('branch-lock', StringIO('')),
662
 
            ('pending-merges', StringIO('')),
663
 
            ('inventory', StringIO(empty_inv)),
664
663
            ('inventory.weave', StringIO(empty_weave)),
665
664
        ]
666
665
        control.mkdir_multi(dirs, mode=dir_mode)
836
835
        self._transport = transport
837
836
        if deprecated_passed(init):
838
837
            warn("BzrBranch.__init__(..., init=XXX): The init parameter is "
839
 
                 "deprecated as of bzr 0.8. Please use Branch.initialize().",
840
 
                 DeprecationWarning)
 
838
                 "deprecated as of bzr 0.8. Please use Branch.create().",
 
839
                 DeprecationWarning,
 
840
                 stacklevel=2)
841
841
            if init:
842
842
                # this is slower than before deprecation, oh well never mind.
843
843
                # -> its deprecated.
848
848
            warn("BzrBranch.__init__(..., relax_version_check=XXX_: The "
849
849
                 "relax_version_check parameter is deprecated as of bzr 0.8. "
850
850
                 "Please use Branch.open_downlevel, or a BzrBranchFormat's "
851
 
                 "open() method.", DeprecationWarning)
 
851
                 "open() method.",
 
852
                 DeprecationWarning,
 
853
                 stacklevel=2)
852
854
            if (not relax_version_check
853
855
                and not self._branch_format.is_supported()):
854
856
                raise errors.UnsupportedFormatError(
1044
1046
        for path, f in files:
1045
1047
            if encode:
1046
1048
                if isinstance(f, basestring):
1047
 
                    f = f.encode('utf-8', 'replace')
 
1049
                    f = StringIO(f.encode('utf-8', 'replace'))
1048
1050
                else:
1049
1051
                    f = codecs.getwriter('utf-8')(f, errors='replace')
1050
1052
            path = self._rel_controlfilename(path)
1123
1125
        old_revision = self.last_revision()
1124
1126
        new_revision = rev_history[-1]
1125
1127
        self.put_controlfile('revision-history', '\n'.join(rev_history))
1126
 
        try:
1127
 
            self.working_tree().set_last_revision(new_revision, old_revision)
1128
 
        except NoWorkingTree:
1129
 
            mutter('Unable to set_last_revision without a working tree.')
1130
1128
 
1131
1129
    def has_revision(self, revision_id):
1132
1130
        """See Branch.has_revision."""
1286
1284
    def working_tree(self):
1287
1285
        """See Branch.working_tree."""
1288
1286
        from bzrlib.workingtree import WorkingTree
1289
 
        if self._transport.base.find('://') != -1:
 
1287
        from bzrlib.transport.local import LocalTransport
 
1288
        if (self._transport.base.find('://') != -1 or 
 
1289
            not isinstance(self._transport, LocalTransport)):
1290
1290
            raise NoWorkingTree(self.base)
1291
1291
        return WorkingTree(self.base, branch=self)
1292
1292
 
1502
1502
        """
1503
1503
        if transport is None:
1504
1504
            transport = bzrlib.transport.local.ScratchTransport()
1505
 
            Branch.initialize(transport.base)
 
1505
            # local import for scope restriction
 
1506
            from bzrlib.workingtree import WorkingTree
 
1507
            WorkingTree.create_standalone(transport.base)
1506
1508
            super(ScratchBranch, self).__init__(transport)
1507
1509
        else:
1508
1510
            super(ScratchBranch, self).__init__(transport)