~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-19 20:39:33 UTC
  • mfrom: (1869 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1871.
  • Revision ID: john@arbash-meinel.com-20060719203933-0fc9037bdb449761
[merge] bzr.dev 1869

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import sys
25
25
 
26
26
import bzrlib
 
27
from bzrlib import (
 
28
    branch,
 
29
    bundle,
 
30
    bzrdir,
 
31
    config,
 
32
    errors,
 
33
    ignores,
 
34
    log,
 
35
    osutils,
 
36
    repository,
 
37
    transport,
 
38
    ui,
 
39
    urlutils,
 
40
    )
27
41
from bzrlib.branch import Branch, BranchReferenceFormat
28
 
from bzrlib import (bundle, branch, bzrdir, errors, ignores,
29
 
                    osutils, ui, config, repository, log)
30
42
from bzrlib.bundle import read_bundle_from_url
31
43
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
32
44
from bzrlib.conflicts import ConflictList
42
54
from bzrlib.revisionspec import RevisionSpec
43
55
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
44
56
from bzrlib.transport.local import LocalTransport
45
 
import bzrlib.urlutils as urlutils
46
57
from bzrlib.workingtree import WorkingTree
47
58
 
48
59
 
516
527
            create_prefix=False, verbose=False):
517
528
        # FIXME: Way too big!  Put this into a function called from the
518
529
        # command.
519
 
        from bzrlib.transport import get_transport
520
530
        
521
531
        br_from = Branch.open_containing('.')[0]
522
532
        stored_loc = br_from.get_push_location()
529
539
                self.outf.write("Using saved location: %s\n" % display_url)
530
540
                location = stored_loc
531
541
 
532
 
        transport = get_transport(location)
533
 
        location_url = transport.base
 
542
        to_transport = transport.get_transport(location)
 
543
        location_url = to_transport.base
534
544
 
535
545
        old_rh = []
536
546
        try:
538
548
            br_to = dir_to.open_branch()
539
549
        except NotBranchError:
540
550
            # create a branch.
541
 
            transport = transport.clone('..')
 
551
            to_transport = to_transport.clone('..')
542
552
            if not create_prefix:
543
553
                try:
544
 
                    relurl = transport.relpath(location_url)
 
554
                    relurl = to_transport.relpath(location_url)
545
555
                    mutter('creating directory %s => %s', location_url, relurl)
546
 
                    transport.mkdir(relurl)
 
556
                    to_transport.mkdir(relurl)
547
557
                except NoSuchFile:
548
558
                    raise BzrCommandError("Parent directory of %s "
549
559
                                          "does not exist." % location)
550
560
            else:
551
 
                current = transport.base
552
 
                needed = [(transport, transport.relpath(location_url))]
 
561
                current = to_transport.base
 
562
                needed = [(to_transport, to_transport.relpath(location_url))]
553
563
                while needed:
554
564
                    try:
555
 
                        transport, relpath = needed[-1]
556
 
                        transport.mkdir(relpath)
 
565
                        to_transport, relpath = needed[-1]
 
566
                        to_transport.mkdir(relpath)
557
567
                        needed.pop()
558
568
                    except NoSuchFile:
559
 
                        new_transport = transport.clone('..')
 
569
                        new_transport = to_transport.clone('..')
560
570
                        needed.append((new_transport,
561
 
                                       new_transport.relpath(transport.base)))
562
 
                        if new_transport.base == transport.base:
 
571
                                       new_transport.relpath(to_transport.base)))
 
572
                        if new_transport.base == to_transport.base:
563
573
                            raise BzrCommandError("Could not create "
564
574
                                                  "path prefix.")
565
575
            dir_to = br_from.bzrdir.clone(location_url,
618
628
    aliases = ['get', 'clone']
619
629
 
620
630
    def run(self, from_location, to_location=None, revision=None, basis=None):
621
 
        from bzrlib.transport import get_transport
622
631
        if revision is None:
623
632
            revision = [None]
624
633
        elif len(revision) > 1:
651
660
            else:
652
661
                name = os.path.basename(to_location) + '\n'
653
662
 
654
 
            to_transport = get_transport(to_location)
 
663
            to_transport = transport.get_transport(to_location)
655
664
            try:
656
665
                to_transport.mkdir('.')
657
666
            except errors.FileExists:
1016
1025
            format = get_format_type('default')
1017
1026
        if location is None:
1018
1027
            location = u'.'
1019
 
        else:
1020
 
            # The path has to exist to initialize a
1021
 
            # branch inside of it.
1022
 
            # Just using os.mkdir, since I don't
1023
 
            # believe that we want to create a bunch of
1024
 
            # locations if the user supplies an extended path
1025
 
            if not os.path.exists(location):
1026
 
                os.mkdir(location)
 
1028
 
 
1029
        to_transport = transport.get_transport(location)
 
1030
 
 
1031
        # The path has to exist to initialize a
 
1032
        # branch inside of it.
 
1033
        # Just using os.mkdir, since I don't
 
1034
        # believe that we want to create a bunch of
 
1035
        # locations if the user supplies an extended path
 
1036
        # TODO: create-prefix
 
1037
        try:
 
1038
            to_transport.mkdir('.')
 
1039
        except errors.FileExists:
 
1040
            pass
 
1041
                    
1027
1042
        try:
1028
1043
            existing_bzrdir = bzrdir.BzrDir.open(location)
1029
1044
        except NotBranchError:
1031
1046
            bzrdir.BzrDir.create_branch_convenience(location, format=format)
1032
1047
        else:
1033
1048
            if existing_bzrdir.has_branch():
1034
 
                if existing_bzrdir.has_workingtree():
1035
 
                    raise errors.AlreadyBranchError(location)
1036
 
                else:
1037
 
                    raise errors.BranchExistsWithoutWorkingTree(location)
 
1049
                if (isinstance(to_transport, LocalTransport)
 
1050
                    and not existing_bzrdir.has_workingtree()):
 
1051
                        raise errors.BranchExistsWithoutWorkingTree(location)
 
1052
                raise errors.AlreadyBranchError(location)
1038
1053
            else:
1039
1054
                existing_bzrdir.create_branch()
1040
1055
                existing_bzrdir.create_workingtree()
1066
1081
                             ' a working tree')]
1067
1082
    aliases = ["init-repo"]
1068
1083
    def run(self, location, format=None, trees=False):
1069
 
        from bzrlib.transport import get_transport
1070
1084
        if format is None:
1071
1085
            format = get_format_type('default')
1072
 
        transport = get_transport(location)
1073
 
        if not transport.has('.'):
1074
 
            transport.mkdir('')
1075
 
        newdir = format.initialize_on_transport(transport)
 
1086
 
 
1087
        if location is None:
 
1088
            location = '.'
 
1089
 
 
1090
        to_transport = transport.get_transport(location)
 
1091
        try:
 
1092
            to_transport.mkdir('.')
 
1093
        except errors.FileExists:
 
1094
            pass
 
1095
 
 
1096
        newdir = format.initialize_on_transport(to_transport)
1076
1097
        repo = newdir.create_repository(shared=True)
1077
1098
        repo.set_make_working_trees(trees)
1078
1099
 
2637
2658
    takes_args = ['location?']
2638
2659
    aliases = []
2639
2660
 
2640
 
    def run(self, location=None, 
 
2661
    def run(self, location=None,
2641
2662
            dry_run=False, verbose=False,
2642
2663
            revision=None, force=False):
2643
 
        from bzrlib.log import log_formatter
 
2664
        from bzrlib.log import log_formatter, show_log
2644
2665
        import sys
2645
2666
        from bzrlib.uncommit import uncommit
2646
2667
 
2654
2675
            tree = None
2655
2676
            b = control.open_branch()
2656
2677
 
 
2678
        rev_id = None
2657
2679
        if revision is None:
2658
2680
            revno = b.revno()
2659
 
            rev_id = b.last_revision()
2660
2681
        else:
2661
 
            revno, rev_id = revision[0].in_history(b)
 
2682
            # 'bzr uncommit -r 10' actually means uncommit
 
2683
            # so that the final tree is at revno 10.
 
2684
            # but bzrlib.uncommit.uncommit() actually uncommits
 
2685
            # the revisions that are supplied.
 
2686
            # So we need to offset it by one
 
2687
            revno = revision[0].in_history(b).revno+1
 
2688
 
 
2689
        if revno <= b.revno():
 
2690
            rev_id = b.get_rev_id(revno)
2662
2691
        if rev_id is None:
2663
 
            print 'No revisions to uncommit.'
2664
 
 
2665
 
        for r in range(revno, b.revno()+1):
2666
 
            rev_id = b.get_rev_id(r)
2667
 
            lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2668
 
            lf.show(r, b.repository.get_revision(rev_id), None)
 
2692
            self.outf.write('No revisions to uncommit.\n')
 
2693
            return 1
 
2694
 
 
2695
        lf = log_formatter('short',
 
2696
                           to_file=self.outf,
 
2697
                           show_timezone='original')
 
2698
 
 
2699
        show_log(b,
 
2700
                 lf,
 
2701
                 verbose=False,
 
2702
                 direction='forward',
 
2703
                 start_revision=revno,
 
2704
                 end_revision=b.revno())
2669
2705
 
2670
2706
        if dry_run:
2671
2707
            print 'Dry-run, pretending to remove the above revisions.'