~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Robert Collins
  • Date: 2005-08-25 06:02:26 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050825060226-115adb0093d707ad
pull the important stuff out of cmd_branch.run to branch.copy_branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
664
664
    aliases = ['get', 'clone']
665
665
 
666
666
    def run(self, from_location, to_location=None, revision=None):
 
667
        from bzrlib.branch import copy_branch, find_cached_branch
 
668
        import tempfile
667
669
        import errno
668
 
        from bzrlib.merge import merge
669
 
        from bzrlib.branch import DivergedBranches, \
670
 
             find_cached_branch, Branch
671
 
        from shutil import rmtree
672
 
        from meta_store import CachedStore
673
 
        import tempfile
674
670
        cache_root = tempfile.mkdtemp()
675
 
 
676
 
        if revision is None:
677
 
            revision = [None]
678
 
        elif len(revision) > 1:
679
 
            raise BzrCommandError('bzr branch --revision takes exactly 1 revision value')
680
 
 
681
671
        try:
 
672
            if revision is None:
 
673
                revision = [None]
 
674
            elif len(revision) > 1:
 
675
                raise BzrCommandError(
 
676
                    'bzr branch --revision takes exactly 1 revision value')
682
677
            try:
683
678
                br_from = find_cached_branch(from_location, cache_root)
684
679
            except OSError, e:
687
682
                                          ' exist.' % to_location)
688
683
                else:
689
684
                    raise
690
 
 
691
685
            if to_location is None:
692
686
                to_location = os.path.basename(from_location.rstrip("/\\"))
693
 
 
694
687
            try:
695
688
                os.mkdir(to_location)
696
689
            except OSError, e:
702
695
                                          to_location)
703
696
                else:
704
697
                    raise
705
 
            br_to = Branch(to_location, init=True)
706
 
 
707
 
            br_to.set_root_id(br_from.get_root_id())
708
 
 
709
 
            if revision:
710
 
                if revision[0] is None:
711
 
                    revno = br_from.revno()
712
 
                else:
713
 
                    revno, rev_id = br_from.get_revision_info(revision[0])
714
 
                try:
715
 
                    br_to.update_revisions(br_from, stop_revision=revno)
716
 
                except bzrlib.errors.NoSuchRevision:
717
 
                    rmtree(to_location)
718
 
                    msg = "The branch %s has no revision %d." % (from_location,
719
 
                                                                 revno)
720
 
                    raise BzrCommandError(msg)
721
 
 
722
 
            merge((to_location, -1), (to_location, 0), this_dir=to_location,
723
 
                  check_clean=False, ignore_zero=True)
724
 
            from_location = pull_loc(br_from)
725
 
            br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
698
            try:
 
699
                copy_branch(br_from, to_location, revision[0])
 
700
            except bzrlib.errors.NoSuchRevision:
 
701
                rmtree(to_location)
 
702
                msg = "The branch %s has no revision %d." % (from_location, revision[0])
 
703
                raise BzrCommandError(msg)
726
704
        finally:
727
705
            rmtree(cache_root)
728
706