/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

Merge from 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
 
375
386
    encoding_type = 'replace'
376
387
 
377
388
    def run(self, names_list):
 
389
        if names_list is None:
 
390
            names_list = []
 
391
 
378
392
        if len(names_list) < 2:
379
393
            raise BzrCommandError("missing file argument")
380
394
        tree, rel_names = tree_files(names_list)
513
527
            create_prefix=False, verbose=False):
514
528
        # FIXME: Way too big!  Put this into a function called from the
515
529
        # command.
516
 
        from bzrlib.transport import get_transport
517
530
        
518
531
        br_from = Branch.open_containing('.')[0]
519
532
        stored_loc = br_from.get_push_location()
526
539
                self.outf.write("Using saved location: %s\n" % display_url)
527
540
                location = stored_loc
528
541
 
529
 
        transport = get_transport(location)
530
 
        location_url = transport.base
 
542
        to_transport = transport.get_transport(location)
 
543
        location_url = to_transport.base
531
544
 
532
545
        old_rh = []
533
546
        try:
535
548
            br_to = dir_to.open_branch()
536
549
        except NotBranchError:
537
550
            # create a branch.
538
 
            transport = transport.clone('..')
 
551
            to_transport = to_transport.clone('..')
539
552
            if not create_prefix:
540
553
                try:
541
 
                    relurl = transport.relpath(location_url)
 
554
                    relurl = to_transport.relpath(location_url)
542
555
                    mutter('creating directory %s => %s', location_url, relurl)
543
 
                    transport.mkdir(relurl)
 
556
                    to_transport.mkdir(relurl)
544
557
                except NoSuchFile:
545
558
                    raise BzrCommandError("Parent directory of %s "
546
559
                                          "does not exist." % location)
547
560
            else:
548
 
                current = transport.base
549
 
                needed = [(transport, transport.relpath(location_url))]
 
561
                current = to_transport.base
 
562
                needed = [(to_transport, to_transport.relpath(location_url))]
550
563
                while needed:
551
564
                    try:
552
 
                        transport, relpath = needed[-1]
553
 
                        transport.mkdir(relpath)
 
565
                        to_transport, relpath = needed[-1]
 
566
                        to_transport.mkdir(relpath)
554
567
                        needed.pop()
555
568
                    except NoSuchFile:
556
 
                        new_transport = transport.clone('..')
 
569
                        new_transport = to_transport.clone('..')
557
570
                        needed.append((new_transport,
558
 
                                       new_transport.relpath(transport.base)))
559
 
                        if new_transport.base == transport.base:
 
571
                                       new_transport.relpath(to_transport.base)))
 
572
                        if new_transport.base == to_transport.base:
560
573
                            raise BzrCommandError("Could not create "
561
574
                                                  "path prefix.")
562
575
            dir_to = br_from.bzrdir.clone(location_url,
615
628
    aliases = ['get', 'clone']
616
629
 
617
630
    def run(self, from_location, to_location=None, revision=None, basis=None):
618
 
        from bzrlib.transport import get_transport
619
631
        if revision is None:
620
632
            revision = [None]
621
633
        elif len(revision) > 1:
648
660
            else:
649
661
                name = os.path.basename(to_location) + '\n'
650
662
 
651
 
            to_transport = get_transport(to_location)
 
663
            to_transport = transport.get_transport(to_location)
652
664
            try:
653
665
                to_transport.mkdir('.')
654
666
            except errors.FileExists:
787
799
    'bzr revert' instead of 'bzr commit' after the update.
788
800
    """
789
801
    takes_args = ['dir?']
 
802
    aliases = ['up']
790
803
 
791
804
    def run(self, dir='.'):
792
805
        tree = WorkingTree.open_containing(dir)[0]
793
806
        tree.lock_write()
 
807
        existing_pending_merges = tree.pending_merges()
794
808
        try:
795
809
            last_rev = tree.last_revision() 
796
810
            if last_rev == tree.branch.last_revision():
803
817
            conflicts = tree.update()
804
818
            revno = tree.branch.revision_id_to_revno(tree.last_revision())
805
819
            note('Updated to revision %d.' % (revno,))
 
820
            if tree.pending_merges() != existing_pending_merges:
 
821
                note('Your local commits will now show as pending merges with '
 
822
                     "'bzr status', and can be committed with 'bzr commit'.")
806
823
            if conflicts != 0:
807
824
                return 1
808
825
            else:
853
870
                raise BzrCommandError('Specify one or more files to remove, or'
854
871
                                      ' use --new.')
855
872
        else:
856
 
            from bzrlib.delta import compare_trees
857
 
            added = [compare_trees(tree.basis_tree(), tree,
858
 
                                   specific_files=file_list).added]
859
 
            file_list = sorted([f[0] for f in added[0]], reverse=True)
 
873
            added = tree.changes_from(tree.basis_tree(),
 
874
                specific_files=file_list).added
 
875
            file_list = sorted([f[0] for f in added], reverse=True)
860
876
            if len(file_list) == 0:
861
877
                raise BzrCommandError('No matching files.')
862
878
        tree.remove(file_list, verbose=verbose, to_file=self.outf)
1003
1019
            format = get_format_type('default')
1004
1020
        if location is None:
1005
1021
            location = u'.'
1006
 
        else:
1007
 
            # The path has to exist to initialize a
1008
 
            # branch inside of it.
1009
 
            # Just using os.mkdir, since I don't
1010
 
            # believe that we want to create a bunch of
1011
 
            # locations if the user supplies an extended path
1012
 
            if not os.path.exists(location):
1013
 
                os.mkdir(location)
 
1022
 
 
1023
        to_transport = transport.get_transport(location)
 
1024
 
 
1025
        # The path has to exist to initialize a
 
1026
        # branch inside of it.
 
1027
        # Just using os.mkdir, since I don't
 
1028
        # believe that we want to create a bunch of
 
1029
        # locations if the user supplies an extended path
 
1030
        # TODO: create-prefix
 
1031
        try:
 
1032
            to_transport.mkdir('.')
 
1033
        except errors.FileExists:
 
1034
            pass
 
1035
                    
1014
1036
        try:
1015
1037
            existing_bzrdir = bzrdir.BzrDir.open(location)
1016
1038
        except NotBranchError:
1018
1040
            bzrdir.BzrDir.create_branch_convenience(location, format=format)
1019
1041
        else:
1020
1042
            if existing_bzrdir.has_branch():
1021
 
                if existing_bzrdir.has_workingtree():
1022
 
                    raise errors.AlreadyBranchError(location)
1023
 
                else:
1024
 
                    raise errors.BranchExistsWithoutWorkingTree(location)
 
1043
                if (isinstance(to_transport, LocalTransport)
 
1044
                    and not existing_bzrdir.has_workingtree()):
 
1045
                        raise errors.BranchExistsWithoutWorkingTree(location)
 
1046
                raise errors.AlreadyBranchError(location)
1025
1047
            else:
1026
1048
                existing_bzrdir.create_branch()
1027
1049
                existing_bzrdir.create_workingtree()
1053
1075
                             ' a working tree')]
1054
1076
    aliases = ["init-repo"]
1055
1077
    def run(self, location, format=None, trees=False):
1056
 
        from bzrlib.transport import get_transport
1057
1078
        if format is None:
1058
1079
            format = get_format_type('default')
1059
 
        transport = get_transport(location)
1060
 
        if not transport.has('.'):
1061
 
            transport.mkdir('')
1062
 
        newdir = format.initialize_on_transport(transport)
 
1080
 
 
1081
        if location is None:
 
1082
            location = '.'
 
1083
 
 
1084
        to_transport = transport.get_transport(location)
 
1085
        try:
 
1086
            to_transport.mkdir('.')
 
1087
        except errors.FileExists:
 
1088
            pass
 
1089
 
 
1090
        newdir = format.initialize_on_transport(to_transport)
1063
1091
        repo = newdir.create_repository(shared=True)
1064
1092
        repo.set_make_working_trees(trees)
1065
1093
 
1066
1094
 
1067
1095
class cmd_diff(Command):
1068
 
    """Show differences in working tree.
 
1096
    """Show differences in the working tree or between revisions.
1069
1097
    
1070
1098
    If files are listed, only the changes in those files are listed.
1071
1099
    Otherwise, all changes for the tree are listed.
1075
1103
 
1076
1104
    examples:
1077
1105
        bzr diff
 
1106
            Shows the difference in the working tree versus the last commit
1078
1107
        bzr diff -r1
 
1108
            Difference between the working tree and revision 1
1079
1109
        bzr diff -r1..2
 
1110
            Difference between revision 2 and revision 1
1080
1111
        bzr diff --diff-prefix old/:new/
 
1112
            Same as 'bzr diff' but prefix paths with old/ and new/
1081
1113
        bzr diff bzr.mine bzr.dev
 
1114
            Show the differences between the two working trees
1082
1115
        bzr diff foo.c
 
1116
            Show just the differences for 'foo.c'
1083
1117
    """
1084
1118
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
1085
1119
    #       or a graphical diff.
1129
1163
                # FIXME diff those two files. rbc 20051123
1130
1164
                raise BzrCommandError("Files are in different branches")
1131
1165
            file_list = None
 
1166
        except NotBranchError:
 
1167
            if (revision is not None and len(revision) == 2
 
1168
                and not revision[0].needs_branch()
 
1169
                and not revision[1].needs_branch()):
 
1170
                # If both revision specs include a branch, we can
 
1171
                # diff them without needing a local working tree
 
1172
                tree1, tree2 = None, None
 
1173
            else:
 
1174
                raise
1132
1175
        if revision is not None:
1133
1176
            if tree2 is not None:
1134
1177
                raise BzrCommandError("Can't specify -r with two branches")
1182
1225
    hidden = True
1183
1226
    @display_command
1184
1227
    def run(self):
1185
 
        from bzrlib.delta import compare_trees
1186
 
 
1187
1228
        tree = WorkingTree.open_containing(u'.')[0]
1188
 
        td = compare_trees(tree.basis_tree(), tree)
1189
 
 
 
1229
        td = tree.changes_from(tree.basis_tree())
1190
1230
        for path, id, kind, text_modified, meta_modified in td.modified:
1191
1231
            self.outf.write(path + '\n')
1192
1232
 
1459
1499
        from bzrlib.atomicfile import AtomicFile
1460
1500
        if old_default_rules is not None:
1461
1501
            # dump the rules and exit
1462
 
            for pattern in bzrlib.DEFAULT_IGNORE:
 
1502
            for pattern in ignores.OLD_DEFAULTS:
1463
1503
                print pattern
1464
1504
            return
1465
1505
        if name_pattern is None:
1711
1751
            raise BzrCommandError("Commit refused because there are unknown "
1712
1752
                                  "files in the working tree.")
1713
1753
        except errors.BoundBranchOutOfDate, e:
1714
 
            raise BzrCommandError(str(e)
1715
 
                                  + ' Either unbind, update, or'
1716
 
                                    ' pass --local to commit.')
1717
 
 
 
1754
            raise BzrCommandError(str(e) + "\n"
 
1755
                'To commit to master branch, run update and then commit.\n'
 
1756
                'You can also pass --local to commit to continue working '
 
1757
                'disconnected.')
1718
1758
 
1719
1759
class cmd_check(Command):
1720
1760
    """Validate consistency of branch history.
1809
1849
                self.outf.write(c.username() + '\n')
1810
1850
            return
1811
1851
 
 
1852
        # display a warning if an email address isn't included in the given name.
 
1853
        try:
 
1854
            config.extract_email_address(name)
 
1855
        except BzrError, e:
 
1856
            warning('"%s" does not seem to contain an email address.  '
 
1857
                    'This is allowed, but not recommended.', name)
 
1858
        
1812
1859
        # use global config unless --branch given
1813
1860
        if branch:
1814
1861
            c = Branch.open_containing('.')[0].get_config()
1948
1995
 
1949
1996
def show_version():
1950
1997
    import bzrlib
1951
 
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
 
1998
    print "Bazaar (bzr) %s" % bzrlib.__version__
1952
1999
    # is bzrlib itself in a branch?
1953
2000
    branch = _get_bzr_branch()
1954
2001
    if branch:
1980
2027
 
1981
2028
class cmd_version(Command):
1982
2029
    """Show version of bzr."""
 
2030
 
1983
2031
    @display_command
1984
2032
    def run(self):
1985
2033
        show_version()
1986
2034
 
 
2035
 
1987
2036
class cmd_rocks(Command):
1988
2037
    """Statement of optimism."""
 
2038
 
1989
2039
    hidden = True
 
2040
 
1990
2041
    @display_command
1991
2042
    def run(self):
1992
2043
        print "it sure does!"
1993
2044
 
1994
2045
 
1995
2046
class cmd_find_merge_base(Command):
1996
 
    """Find and print a base revision for merging two branches.
1997
 
    """
 
2047
    """Find and print a base revision for merging two branches."""
1998
2048
    # TODO: Options to specify revisions on either side, as if
1999
2049
    #       merging only part of the history.
2000
2050
    takes_args = ['branch', 'other']
2367
2417
        if other_branch is None:
2368
2418
            other_branch = parent
2369
2419
            if other_branch is None:
2370
 
                raise BzrCommandError("No missing location known or specified.")
 
2420
                raise BzrCommandError("No peer location known or specified.")
2371
2421
            print "Using last location: " + local_branch.get_parent()
2372
2422
        remote_branch = Branch.open(other_branch)
2373
2423
        if remote_branch.base == local_branch.base:
2609
2659
    takes_args = ['location?']
2610
2660
    aliases = []
2611
2661
 
2612
 
    def run(self, location=None, 
 
2662
    def run(self, location=None,
2613
2663
            dry_run=False, verbose=False,
2614
2664
            revision=None, force=False):
2615
 
        from bzrlib.log import log_formatter
 
2665
        from bzrlib.log import log_formatter, show_log
2616
2666
        import sys
2617
2667
        from bzrlib.uncommit import uncommit
2618
2668
 
2626
2676
            tree = None
2627
2677
            b = control.open_branch()
2628
2678
 
 
2679
        rev_id = None
2629
2680
        if revision is None:
2630
2681
            revno = b.revno()
2631
 
            rev_id = b.last_revision()
2632
2682
        else:
2633
 
            revno, rev_id = revision[0].in_history(b)
 
2683
            # 'bzr uncommit -r 10' actually means uncommit
 
2684
            # so that the final tree is at revno 10.
 
2685
            # but bzrlib.uncommit.uncommit() actually uncommits
 
2686
            # the revisions that are supplied.
 
2687
            # So we need to offset it by one
 
2688
            revno = revision[0].in_history(b).revno+1
 
2689
 
 
2690
        if revno <= b.revno():
 
2691
            rev_id = b.get_rev_id(revno)
2634
2692
        if rev_id is None:
2635
 
            print 'No revisions to uncommit.'
2636
 
 
2637
 
        for r in range(revno, b.revno()+1):
2638
 
            rev_id = b.get_rev_id(r)
2639
 
            lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2640
 
            lf.show(r, b.repository.get_revision(rev_id), None)
 
2693
            self.outf.write('No revisions to uncommit.\n')
 
2694
            return 1
 
2695
 
 
2696
        lf = log_formatter('short',
 
2697
                           to_file=self.outf,
 
2698
                           show_timezone='original')
 
2699
 
 
2700
        show_log(b,
 
2701
                 lf,
 
2702
                 verbose=False,
 
2703
                 direction='forward',
 
2704
                 start_revision=revno,
 
2705
                 end_revision=b.revno())
2641
2706
 
2642
2707
        if dry_run:
2643
2708
            print 'Dry-run, pretending to remove the above revisions.'