~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2006-03-05 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 1590.
  • Revision ID: robertc@robertcollins.net-20060305114854-d95dbe4adfee32e9
Make bound branch creation happen via 'checkout'

Show diffs side-by-side

added added

removed removed

Lines of Context:
549
549
    branch before copying anything from the remote branch.
550
550
    """
551
551
    takes_args = ['from_location', 'to_location?']
552
 
    takes_options = ['revision', 'basis', 'bound']
 
552
    takes_options = ['revision', 'basis']
553
553
    aliases = ['get', 'clone']
554
554
 
555
 
    def run(self, from_location, to_location=None, revision=None, basis=None,
556
 
            bound=False):
 
555
    def run(self, from_location, to_location=None, revision=None, basis=None):
557
556
        if revision is None:
558
557
            revision = [None]
559
558
        elif len(revision) > 1:
597
596
                else:
598
597
                    raise
599
598
            try:
600
 
                # bound branches require a version upgrade
601
 
                if bound and not isinstance(br_from.bzrdir._format,
602
 
                                            bzrdir.BzrDirMetaFormat1):
603
 
                    old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
604
 
                    bzrlib.bzrdir.BzrDirFormat.set_default_format(
605
 
                        bzrdir.BzrDirMetaFormat1())
606
 
                    try:
607
 
                        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
608
 
                            to_location)
609
 
                    finally:
610
 
                        bzrlib.bzrdir.BzrDirFormat.set_default_format(
611
 
                            old_format)
612
 
                else:
613
 
                    # preserve whatever source version we have.
614
 
                    dir = br_from.bzrdir.sprout(to_location, revision_id, basis_dir)
615
 
                    branch = dir.open_branch()
 
599
                # preserve whatever source format we have.
 
600
                dir = br_from.bzrdir.sprout(to_location, revision_id, basis_dir)
 
601
                branch = dir.open_branch()
616
602
            except bzrlib.errors.NoSuchRevision:
617
603
                rmtree(to_location)
618
604
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
627
613
            note('Branched %d revision(s).' % branch.revno())
628
614
        finally:
629
615
            br_from.unlock()
630
 
        if bound:
631
 
            branch.bind(br_from)
632
616
 
633
617
 
634
618
class cmd_checkout(Command):
647
631
    branch being checked out. [Not implemented yet.]
648
632
    """
649
633
    takes_args = ['branch_location', 'to_location?']
650
 
    takes_options = ['revision'] # , 'basis']
 
634
    takes_options = ['revision', # , 'basis']
 
635
                     Option('lightweight',
 
636
                            help="perform a lightweight checkout. Lightweight "
 
637
                                 "checkouts depend on access to the branch for "
 
638
                                 "every operation. Normal checkouts can perform "
 
639
                                 "common operations like diff and status without "
 
640
                                 "such access, and also support local commits."
 
641
                            ),
 
642
                     ]
651
643
 
652
 
    def run(self, branch_location, to_location=None, revision=None, basis=None):
 
644
    def run(self, branch_location, to_location=None, revision=None, basis=None,
 
645
            lightweight=False):
653
646
        if revision is None:
654
647
            revision = [None]
655
648
        elif len(revision) > 1:
673
666
                                      to_location)
674
667
            else:
675
668
                raise
676
 
        checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
677
 
        bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
678
 
        checkout.create_workingtree(revision_id)
 
669
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
 
670
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
671
        try:
 
672
            if lightweight:
 
673
                checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
 
674
                bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
 
675
            else:
 
676
                checkout_branch =  bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
677
                    to_location, force_new_tree=False)
 
678
                checkout = checkout_branch.bzrdir
 
679
                checkout_branch.bind(source)
 
680
                if revision_id is not None:
 
681
                    rh = checkout_branch.revision_history()
 
682
                    checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
 
683
            checkout.create_workingtree(revision_id)
 
684
        finally:
 
685
            bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
679
686
 
680
687
 
681
688
class cmd_renames(Command):
717
724
            if tree.last_revision() == tree.branch.last_revision():
718
725
                # may be up to date, check master too.
719
726
                master = tree.branch.get_master_branch()
720
 
                if master and master.last_revision == tree.last_revision():
 
727
                if master is None or master.last_revision == tree.last_revision():
721
728
                    note("Tree is up to date.")
722
729
                    return
723
730
            conflicts = tree.update()
2159
2166
 
2160
2167
 
2161
2168
class cmd_bind(Command):
2162
 
    """Bind the current branch to its parent.
 
2169
    """Bind the current branch to a master branch.
2163
2170
 
2164
 
    After binding, commits must succeed on the parent branch
2165
 
    before they can be done on the local one.
 
2171
    After binding, commits must succeed on the master branch
 
2172
    before they are executed on the local one.
2166
2173
    """
2167
2174
 
2168
 
    takes_args = ['location?']
 
2175
    takes_args = ['location']
2169
2176
    takes_options = []
2170
2177
 
2171
2178
    def run(self, location=None):
2172
2179
        b, relpath = Branch.open_containing(u'.')
2173
 
        if location is None:
2174
 
            location = b.get_bound_location()
2175
 
        if location is None:
2176
 
            location = b.get_parent()
2177
 
        if location is None:
2178
 
            raise BzrCommandError('Branch has no parent,'
2179
 
                                  ' you must supply a bind location.')
2180
2180
        b_other = Branch.open(location)
2181
2181
        try:
2182
2182
            b.bind(b_other)