~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Merge create_checkout_convenience update

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from warnings import warn
22
22
 
23
23
import bzrlib
24
 
from bzrlib import bzrdir, errors, lockdir, osutils, revision, \
25
 
        tree, \
26
 
        ui, \
 
24
from bzrlib import (
 
25
        bzrdir, 
 
26
        errors, 
 
27
        lockdir, 
 
28
        osutils, 
 
29
        revision,
 
30
        transport,
 
31
        tree,
 
32
        ui,
27
33
        urlutils
 
34
        )
28
35
from bzrlib.config import TreeConfig
29
36
from bzrlib.decorators import needs_read_lock, needs_write_lock
30
37
import bzrlib.errors as errors
568
575
            mainline_parent_id = revision_id
569
576
        return BranchCheckResult(self)
570
577
 
 
578
    def create_checkout_convenience(self, to_location, revision_id=None,
 
579
                                    lightweight=False):
 
580
        """Create a checkout of a branch.
 
581
        
 
582
        :param to_location: The url to produce the checkout at
 
583
        :param revision_id: The revision to check out
 
584
        :param lightweight: If True, produce a lightweight checkout, othewise
 
585
        produce a bound branch (heavyweight checkout)
 
586
        :return: The tree of the created checkout
 
587
        """
 
588
        if lightweight:
 
589
            t = transport.get_transport(to_location)
 
590
            try:
 
591
                t.mkdir('.')
 
592
            except errors.FileExists:
 
593
                pass
 
594
            checkout = bzrdir.BzrDirMetaFormat1().initialize_on_transport(t)
 
595
            BranchReferenceFormat().initialize(checkout, self)
 
596
        else:
 
597
            checkout_branch = bzrdir.BzrDir.create_branch_convenience(
 
598
                to_location, force_new_tree=False)
 
599
            checkout = checkout_branch.bzrdir
 
600
            checkout_branch.bind(self)
 
601
            if revision_id is not None:
 
602
                rh = checkout_branch.revision_history()
 
603
                new_rh = rh[:rh.index(revision_id) + 1]
 
604
                checkout_branch.set_revision_history(new_rh)
 
605
        return checkout.create_workingtree(revision_id)
 
606
 
571
607
 
572
608
class BranchFormat(object):
573
609
    """An encapsulation of the initialization and open routines for a format.