/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2006-08-02 13:02:47 UTC
  • mfrom: (1907 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1934.
  • Revision ID: abentley@panoramicfeedback.com-20060802130247-bf2502d680abed61
Rough merge of bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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, osutils, ui, config,
29
 
    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:
800
809
    'bzr revert' instead of 'bzr commit' after the update.
801
810
    """
802
811
    takes_args = ['dir?']
 
812
    aliases = ['up']
803
813
 
804
814
    def run(self, dir='.'):
805
815
        tree = WorkingTree.open_containing(dir)[0]
806
816
        tree.lock_write()
 
817
        existing_pending_merges = tree.pending_merges()
807
818
        try:
808
819
            last_rev = tree.last_revision() 
809
820
            if last_rev == tree.branch.last_revision():
816
827
            conflicts = tree.update()
817
828
            revno = tree.branch.revision_id_to_revno(tree.last_revision())
818
829
            note('Updated to revision %d.' % (revno,))
 
830
            if tree.pending_merges() != existing_pending_merges:
 
831
                note('Your local commits will now show as pending merges with '
 
832
                     "'bzr status', and can be committed with 'bzr commit'.")
819
833
            if conflicts != 0:
820
834
                return 1
821
835
            else:
866
880
                raise BzrCommandError('Specify one or more files to remove, or'
867
881
                                      ' use --new.')
868
882
        else:
869
 
            from bzrlib.delta import compare_trees
870
 
            added = [compare_trees(tree.basis_tree(), tree,
871
 
                                   specific_files=file_list).added]
872
 
            file_list = sorted([f[0] for f in added[0]], reverse=True)
 
883
            added = tree.changes_from(tree.basis_tree(),
 
884
                specific_files=file_list).added
 
885
            file_list = sorted([f[0] for f in added], reverse=True)
873
886
            if len(file_list) == 0:
874
887
                raise BzrCommandError('No matching files.')
875
888
        tree.remove(file_list, verbose=verbose, to_file=self.outf)
1023
1036
            branch_format = get_format_type('default')
1024
1037
        if location is None:
1025
1038
            location = u'.'
1026
 
        else:
1027
 
            # The path has to exist to initialize a
1028
 
            # branch inside of it.
1029
 
            # Just using os.mkdir, since I don't
1030
 
            # believe that we want to create a bunch of
1031
 
            # locations if the user supplies an extended path
1032
 
            if not os.path.exists(location):
1033
 
                os.mkdir(location)
 
1039
 
 
1040
        to_transport = transport.get_transport(location)
 
1041
 
 
1042
        # The path has to exist to initialize a
 
1043
        # branch inside of it.
 
1044
        # Just using os.mkdir, since I don't
 
1045
        # believe that we want to create a bunch of
 
1046
        # locations if the user supplies an extended path
 
1047
        # TODO: create-prefix
 
1048
        try:
 
1049
            to_transport.mkdir('.')
 
1050
        except errors.FileExists:
 
1051
            pass
 
1052
                    
1034
1053
        try:
1035
1054
            existing_bzrdir = bzrdir.BzrDir.open(location)
1036
1055
        except NotBranchError:
1039
1058
                                                    format=branch_format)
1040
1059
        else:
1041
1060
            if existing_bzrdir.has_branch():
1042
 
                if existing_bzrdir.has_workingtree():
1043
 
                    raise errors.AlreadyBranchError(location)
1044
 
                else:
1045
 
                    raise errors.BranchExistsWithoutWorkingTree(location)
 
1061
                if (isinstance(to_transport, LocalTransport)
 
1062
                    and not existing_bzrdir.has_workingtree()):
 
1063
                        raise errors.BranchExistsWithoutWorkingTree(location)
 
1064
                raise errors.AlreadyBranchError(location)
1046
1065
            else:
1047
1066
                existing_bzrdir.create_branch()
1048
1067
                existing_bzrdir.create_workingtree()
1069
1088
                             ' a working tree')]
1070
1089
    aliases = ["init-repo"]
1071
1090
    def run(self, location, repository_format=None, trees=False):
1072
 
        from bzrlib.transport import get_transport
1073
1091
        if repository_format is None:
1074
1092
            repository_format = get_format_type('default')
1075
1093
        transport = get_transport(location)
1076
 
        if not transport.has('.'):
1077
 
            transport.mkdir('')
1078
 
        newdir = repository_format.initialize_on_transport(transport)
 
1094
        to_transport = transport.get_transport(location)
 
1095
        try:
 
1096
            to_transport.mkdir('.')
 
1097
        except errors.FileExists:
 
1098
            pass
 
1099
 
 
1100
        newdir = format.initialize_on_transport(to_transport)
1079
1101
        repo = newdir.create_repository(shared=True)
1080
1102
        repo.set_make_working_trees(trees)
1081
1103
 
1152
1174
                raise BzrCommandError("Files are in different branches")
1153
1175
            file_list = None
1154
1176
        except NotBranchError:
1155
 
            # Don't raise an error when bzr diff is called from
1156
 
            # outside a working tree.
1157
 
            tree1, tree2 = None, None
 
1177
            if (revision is not None and len(revision) == 2
 
1178
                and not revision[0].needs_branch()
 
1179
                and not revision[1].needs_branch()):
 
1180
                # If both revision specs include a branch, we can
 
1181
                # diff them without needing a local working tree
 
1182
                tree1, tree2 = None, None
 
1183
            else:
 
1184
                raise
1158
1185
        if revision is not None:
1159
1186
            if tree2 is not None:
1160
1187
                raise BzrCommandError("Can't specify -r with two branches")
1208
1235
    hidden = True
1209
1236
    @display_command
1210
1237
    def run(self):
1211
 
        from bzrlib.delta import compare_trees
1212
 
 
1213
1238
        tree = WorkingTree.open_containing(u'.')[0]
1214
 
        td = compare_trees(tree.basis_tree(), tree)
1215
 
 
 
1239
        td = tree.changes_from(tree.basis_tree())
1216
1240
        for path, id, kind, text_modified, meta_modified in td.modified:
1217
1241
            self.outf.write(path + '\n')
1218
1242
 
1465
1489
        from bzrlib.atomicfile import AtomicFile
1466
1490
        if old_default_rules is not None:
1467
1491
            # dump the rules and exit
1468
 
            for pattern in bzrlib.DEFAULT_IGNORE:
 
1492
            for pattern in ignores.OLD_DEFAULTS:
1469
1493
                print pattern
1470
1494
            return
1471
1495
        if name_pattern is None:
1717
1741
            raise BzrCommandError("Commit refused because there are unknown "
1718
1742
                                  "files in the working tree.")
1719
1743
        except errors.BoundBranchOutOfDate, e:
1720
 
            raise BzrCommandError(str(e)
1721
 
                                  + ' Either unbind, update, or'
1722
 
                                    ' pass --local to commit.')
1723
 
 
 
1744
            raise BzrCommandError(str(e) + "\n"
 
1745
                'To commit to master branch, run update and then commit.\n'
 
1746
                'You can also pass --local to commit to continue working '
 
1747
                'disconnected.')
1724
1748
 
1725
1749
class cmd_check(Command):
1726
1750
    """Validate consistency of branch history.
1961
1985
 
1962
1986
def show_version():
1963
1987
    import bzrlib
1964
 
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
 
1988
    print "Bazaar (bzr) %s" % bzrlib.__version__
1965
1989
    # is bzrlib itself in a branch?
1966
1990
    branch = _get_bzr_branch()
1967
1991
    if branch:
1993
2017
 
1994
2018
class cmd_version(Command):
1995
2019
    """Show version of bzr."""
 
2020
 
1996
2021
    @display_command
1997
2022
    def run(self):
1998
2023
        show_version()
1999
2024
 
 
2025
 
2000
2026
class cmd_rocks(Command):
2001
2027
    """Statement of optimism."""
 
2028
 
2002
2029
    hidden = True
 
2030
 
2003
2031
    @display_command
2004
2032
    def run(self):
2005
2033
        print "it sure does!"
2006
2034
 
2007
2035
 
2008
2036
class cmd_find_merge_base(Command):
2009
 
    """Find and print a base revision for merging two branches.
2010
 
    """
 
2037
    """Find and print a base revision for merging two branches."""
2011
2038
    # TODO: Options to specify revisions on either side, as if
2012
2039
    #       merging only part of the history.
2013
2040
    takes_args = ['branch', 'other']
2377
2404
        if other_branch is None:
2378
2405
            other_branch = parent
2379
2406
            if other_branch is None:
2380
 
                raise BzrCommandError("No missing location known or specified.")
 
2407
                raise BzrCommandError("No peer location known or specified.")
2381
2408
            print "Using last location: " + local_branch.get_parent()
2382
2409
        remote_branch = Branch.open(other_branch)
2383
2410
        if remote_branch.base == local_branch.base:
2617
2644
    takes_args = ['location?']
2618
2645
    aliases = []
2619
2646
 
2620
 
    def run(self, location=None, 
 
2647
    def run(self, location=None,
2621
2648
            dry_run=False, verbose=False,
2622
2649
            revision=None, force=False):
2623
 
        from bzrlib.log import log_formatter
 
2650
        from bzrlib.log import log_formatter, show_log
2624
2651
        import sys
2625
2652
        from bzrlib.uncommit import uncommit
2626
2653
 
2634
2661
            tree = None
2635
2662
            b = control.open_branch()
2636
2663
 
 
2664
        rev_id = None
2637
2665
        if revision is None:
2638
2666
            revno = b.revno()
2639
 
            rev_id = b.last_revision()
2640
2667
        else:
2641
 
            revno, rev_id = revision[0].in_history(b)
 
2668
            # 'bzr uncommit -r 10' actually means uncommit
 
2669
            # so that the final tree is at revno 10.
 
2670
            # but bzrlib.uncommit.uncommit() actually uncommits
 
2671
            # the revisions that are supplied.
 
2672
            # So we need to offset it by one
 
2673
            revno = revision[0].in_history(b).revno+1
 
2674
 
 
2675
        if revno <= b.revno():
 
2676
            rev_id = b.get_rev_id(revno)
2642
2677
        if rev_id is None:
2643
 
            print 'No revisions to uncommit.'
2644
 
 
2645
 
        for r in range(revno, b.revno()+1):
2646
 
            rev_id = b.get_rev_id(r)
2647
 
            lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2648
 
            lf.show(r, b.repository.get_revision(rev_id), None)
 
2678
            self.outf.write('No revisions to uncommit.\n')
 
2679
            return 1
 
2680
 
 
2681
        lf = log_formatter('short',
 
2682
                           to_file=self.outf,
 
2683
                           show_timezone='original')
 
2684
 
 
2685
        show_log(b,
 
2686
                 lf,
 
2687
                 verbose=False,
 
2688
                 direction='forward',
 
2689
                 start_revision=revno,
 
2690
                 end_revision=b.revno())
2649
2691
 
2650
2692
        if dry_run:
2651
2693
            print 'Dry-run, pretending to remove the above revisions.'