~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Update test support, and remove deprecated functions pullable_revisions and get_intervening_revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import errno
21
21
import os
22
 
from shutil import rmtree
23
22
import sys
24
23
 
25
24
import bzrlib
85
84
    """Parse and return a format specifier."""
86
85
    if typestring == "weave":
87
86
        return bzrdir.BzrDirFormat6()
88
 
    if typestring == "metadir":
 
87
    if typestring == "default":
89
88
        return bzrdir.BzrDirMetaFormat1()
 
89
    if typestring == "metaweave":
 
90
        format = bzrdir.BzrDirMetaFormat1()
 
91
        format.repository_format = bzrlib.repository.RepositoryFormat7()
 
92
        return format
90
93
    if typestring == "knit":
91
94
        format = bzrdir.BzrDirMetaFormat1()
92
95
        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
93
96
        return format
94
 
    msg = "No known bzr-dir format %s. Supported types are: weave, metadir\n" %\
95
 
        (typestring)
 
97
    msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
 
98
          "metaweave and weave" % typestring
96
99
    raise BzrCommandError(msg)
97
100
 
98
101
 
476
479
        # command.
477
480
        from bzrlib.transport import get_transport
478
481
        
479
 
        tree_from = WorkingTree.open_containing(u'.')[0]
480
 
        br_from = tree_from.branch
481
 
        stored_loc = tree_from.branch.get_push_location()
 
482
        br_from = Branch.open_containing('.')[0]
 
483
        stored_loc = br_from.get_push_location()
482
484
        if location is None:
483
485
            if stored_loc is None:
484
486
                raise BzrCommandError("No push location known or specified.")
562
564
    aliases = ['get', 'clone']
563
565
 
564
566
    def run(self, from_location, to_location=None, revision=None, basis=None):
 
567
        from bzrlib.osutils import rmtree
565
568
        if revision is None:
566
569
            revision = [None]
567
570
        elif len(revision) > 1:
642
645
 
643
646
    --basis is to speed up checking out from remote branches.  When specified, it
644
647
    uses the inventory and file contents from the basis branch in preference to the
645
 
    branch being checked out. [Not implemented yet.]
 
648
    branch being checked out.
646
649
    """
647
650
    takes_args = ['branch_location?', 'to_location?']
648
651
    takes_options = ['revision', # , 'basis']
766
769
 
767
770
 
768
771
class cmd_info(Command):
769
 
    """Show statistical information about a branch."""
770
 
    takes_args = ['branch?']
 
772
    """Show information about a working tree, branch or repository.
 
773
 
 
774
    This command will show all known locations and formats associated to the
 
775
    tree, branch or repository.  Statistical information is included with
 
776
    each report.
 
777
 
 
778
    Branches and working trees will also report any missing revisions.
 
779
    """
 
780
    takes_args = ['location?']
771
781
    takes_options = ['verbose']
772
 
    
 
782
 
773
783
    @display_command
774
 
    def run(self, branch=None, verbose=False):
775
 
        import bzrlib.info
776
 
        bzrlib.info.show_bzrdir_info(bzrdir.BzrDir.open_containing(branch)[0],
777
 
                                     verbose=verbose)
 
784
    def run(self, location=None, verbose=False):
 
785
        from bzrlib.info import show_bzrdir_info
 
786
        show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
 
787
                         verbose=verbose)
778
788
 
779
789
 
780
790
class cmd_remove(Command):
901
911
    takes_args = ['location?']
902
912
    takes_options = [
903
913
                     Option('format', 
904
 
                            help='Create a specific format rather than the'
905
 
                                 ' current default format. Currently this '
906
 
                                 ' option only accepts "metadir"',
 
914
                            help='Specify a format for this branch. Current'
 
915
                                 ' formats are: default, knit, metaweave and'
 
916
                                 ' weave. Default is knit; metaweave and'
 
917
                                 ' weave are deprecated',
907
918
                            type=get_format_type),
908
919
                     ]
909
920
    def run(self, location=None, format=None):
910
921
        from bzrlib.branch import Branch
 
922
        if format is None:
 
923
            format = get_format_type('default')
911
924
        if location is None:
912
925
            location = u'.'
913
926
        else:
950
963
    """
951
964
    takes_args = ["location"] 
952
965
    takes_options = [Option('format', 
953
 
                            help='Use a specific format rather than the'
954
 
                            ' current default format. Currently this'
955
 
                            ' option accepts "weave", "metadir" and "knit"',
 
966
                            help='Specify a format for this repository.'
 
967
                                 ' Current formats are: default, knit,'
 
968
                                 ' metaweave and weave. Default is knit;'
 
969
                                 ' metaweave and weave are deprecated',
956
970
                            type=get_format_type),
957
971
                     Option('trees',
958
972
                             help='Allows branches in repository to have'
959
973
                             ' a working tree')]
960
974
    aliases = ["init-repo"]
961
975
    def run(self, location, format=None, trees=False):
962
 
        from bzrlib.bzrdir import BzrDirMetaFormat1
963
976
        from bzrlib.transport import get_transport
964
977
        if format is None:
965
 
            format = BzrDirMetaFormat1()
 
978
            format = get_format_type('default')
966
979
        transport = get_transport(location)
967
980
        if not transport.has('.'):
968
981
            transport.mkdir('')
977
990
    If files are listed, only the changes in those files are listed.
978
991
    Otherwise, all changes for the tree are listed.
979
992
 
 
993
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
 
994
    produces patches suitable for "patch -p1".
 
995
 
980
996
    examples:
981
997
        bzr diff
982
998
        bzr diff -r1
983
999
        bzr diff -r1..2
 
1000
        bzr diff --diff-prefix old/:new/
 
1001
        bzr diff bzr.mine bzr.dev
 
1002
        bzr diff foo.c
984
1003
    """
985
 
    # TODO: Allow diff across branches.
986
1004
    # TODO: Option to use external diff command; could be GNU diff, wdiff,
987
1005
    #       or a graphical diff.
988
1006
 
989
1007
    # TODO: Python difflib is not exactly the same as unidiff; should
990
1008
    #       either fix it up or prefer to use an external diff.
991
1009
 
992
 
    # TODO: If a directory is given, diff everything under that.
993
 
 
994
1010
    # TODO: Selected-file diff is inefficient and doesn't show you
995
1011
    #       deleted files.
996
1012
 
997
1013
    # TODO: This probably handles non-Unix newlines poorly.
998
1014
    
999
1015
    takes_args = ['file*']
1000
 
    takes_options = ['revision', 'diff-options']
 
1016
    takes_options = ['revision', 'diff-options', 'prefix']
1001
1017
    aliases = ['di', 'dif']
1002
1018
 
1003
1019
    @display_command
1004
 
    def run(self, revision=None, file_list=None, diff_options=None):
 
1020
    def run(self, revision=None, file_list=None, diff_options=None,
 
1021
            prefix=None):
1005
1022
        from bzrlib.diff import diff_cmd_helper, show_diff_trees
 
1023
 
 
1024
        if (prefix is None) or (prefix == '0'):
 
1025
            # diff -p0 format
 
1026
            old_label = ''
 
1027
            new_label = ''
 
1028
        elif prefix == '1':
 
1029
            old_label = 'old/'
 
1030
            new_label = 'new/'
 
1031
        else:
 
1032
            if not ':' in prefix:
 
1033
                 raise BzrError("--diff-prefix expects two values separated by a colon")
 
1034
            old_label, new_label = prefix.split(":")
 
1035
        
1006
1036
        try:
1007
1037
            tree1, file_list = internal_tree_files(file_list)
1008
1038
            tree2 = None
1023
1053
                raise BzrCommandError("Can't specify -r with two branches")
1024
1054
            if (len(revision) == 1) or (revision[1].spec is None):
1025
1055
                return diff_cmd_helper(tree1, file_list, diff_options,
1026
 
                                       revision[0])
 
1056
                                       revision[0], 
 
1057
                                       old_label=old_label, new_label=new_label)
1027
1058
            elif len(revision) == 2:
1028
1059
                return diff_cmd_helper(tree1, file_list, diff_options,
1029
 
                                       revision[0], revision[1])
 
1060
                                       revision[0], revision[1],
 
1061
                                       old_label=old_label, new_label=new_label)
1030
1062
            else:
1031
1063
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
1032
1064
        else:
1033
1065
            if tree2 is not None:
1034
1066
                return show_diff_trees(tree1, tree2, sys.stdout, 
1035
1067
                                       specific_files=file_list,
1036
 
                                       external_diff_options=diff_options)
 
1068
                                       external_diff_options=diff_options,
 
1069
                                       old_label=old_label, new_label=new_label)
1037
1070
            else:
1038
 
                return diff_cmd_helper(tree1, file_list, diff_options)
 
1071
                return diff_cmd_helper(tree1, file_list, diff_options,
 
1072
                                       old_label=old_label, new_label=new_label)
1039
1073
 
1040
1074
 
1041
1075
class cmd_deleted(Command):
1638
1672
    takes_args = ['url?']
1639
1673
    takes_options = [
1640
1674
                     Option('format', 
1641
 
                            help='Upgrade to a specific format rather than the'
1642
 
                                 ' current default format. Currently this'
1643
 
                                 ' option accepts "weave", "metadir" and'
1644
 
                                 ' "knit".',
 
1675
                            help='Upgrade to a specific format. Current formats'
 
1676
                                 ' are: default, knit, metaweave and weave.'
 
1677
                                 ' Default is knit; metaweave and weave are'
 
1678
                                 ' deprecated',
1645
1679
                            type=get_format_type),
1646
1680
                    ]
1647
1681
 
1648
1682
 
1649
1683
    def run(self, url='.', format=None):
1650
1684
        from bzrlib.upgrade import upgrade
 
1685
        if format is None:
 
1686
            format = get_format_type('default')
1651
1687
        upgrade(url, format)
1652
1688
 
1653
1689
 
2248
2284
    shown only at the top, unless the --all option is given.
2249
2285
    """
2250
2286
    # TODO: annotate directories; showing when each file was last changed
2251
 
    # TODO: annotate a previous version of a file
2252
2287
    # TODO: if the working copy is modified, show annotations on that 
2253
2288
    #       with new uncommitted lines marked
2254
2289
    aliases = ['blame', 'praise']
2255
2290
    takes_args = ['filename']
2256
2291
    takes_options = [Option('all', help='show annotations on all lines'),
2257
2292
                     Option('long', help='show date in annotations'),
 
2293
                     'revision'
2258
2294
                     ]
2259
2295
 
2260
2296
    @display_command
2261
 
    def run(self, filename, all=False, long=False):
 
2297
    def run(self, filename, all=False, long=False, revision=None):
2262
2298
        from bzrlib.annotate import annotate_file
2263
2299
        tree, relpath = WorkingTree.open_containing(filename)
2264
2300
        branch = tree.branch
2265
2301
        branch.lock_read()
2266
2302
        try:
 
2303
            if revision is None:
 
2304
                revision_id = branch.last_revision()
 
2305
            elif len(revision) != 1:
 
2306
                raise BzrCommandError('bzr annotate --revision takes exactly 1 argument')
 
2307
            else:
 
2308
                revision_id = revision[0].in_history(branch).rev_id
2267
2309
            file_id = tree.inventory.path2id(relpath)
2268
 
            tree = branch.repository.revision_tree(branch.last_revision())
 
2310
            tree = branch.repository.revision_tree(revision_id)
2269
2311
            file_version = tree.inventory[file_id].revision
2270
2312
            annotate_file(branch, file_version, file_id, long, all, sys.stdout)
2271
2313
        finally:
2425
2467
 
2426
2468
    CAUTION: Locks should only be broken when you are sure that the process
2427
2469
    holding the lock has been stopped.
 
2470
 
 
2471
    You can get information on what locks are open via the 'bzr info' command.
2428
2472
    
2429
2473
    example:
2430
 
        bzr break-lock .
 
2474
        bzr break-lock
2431
2475
    """
2432
 
    takes_args = ['location']
2433
 
    takes_options = [Option('show',
2434
 
                            help="just show information on the lock, " \
2435
 
                                 "don't break it"),
2436
 
                    ]
2437
 
    def run(self, location, show=False):
2438
 
        raise NotImplementedError("sorry, break-lock is not complete yet; "
2439
 
                "you can remove the 'held' directory manually to break the lock")
 
2476
    takes_args = ['location?']
 
2477
 
 
2478
    def run(self, location=None, show=False):
 
2479
        if location is None:
 
2480
            location = u'.'
 
2481
        control, relpath = bzrdir.BzrDir.open_containing(location)
 
2482
        try:
 
2483
            control.break_lock()
 
2484
        except NotImplementedError:
 
2485
            pass
 
2486
        
2440
2487
 
2441
2488
 
2442
2489
# command-line interpretation helper for merge-related commands