/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:
51
51
""")
52
52
 
53
53
from bzrlib.commands import Command, display_command
54
 
from bzrlib.option import Option
 
54
from bzrlib.option import Option, RegistryOption
55
55
from bzrlib.progress import DummyProgress, ProgressPhase
56
56
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
57
57
 
95
95
 
96
96
def get_format_type(typestring):
97
97
    """Parse and return a format specifier."""
98
 
    if typestring == "weave":
99
 
        return bzrdir.BzrDirFormat6()
 
98
    # Have to use BzrDirMetaFormat1 directly, so that
 
99
    # RepositoryFormat.set_default_format works
100
100
    if typestring == "default":
101
101
        return bzrdir.BzrDirMetaFormat1()
102
 
    if typestring == "metaweave":
103
 
        format = bzrdir.BzrDirMetaFormat1()
104
 
        format.repository_format = repository.RepositoryFormat7()
105
 
        return format
106
 
    if typestring == "knit":
107
 
        format = bzrdir.BzrDirMetaFormat1()
108
 
        format.repository_format = repository.RepositoryFormatKnit1()
109
 
        return format
110
 
    if typestring == "experimental-knit2":
111
 
        format = bzrdir.BzrDirMetaFormat1()
112
 
        format.repository_format = repository.RepositoryFormatKnit2()
113
 
        return format
114
 
    msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
115
 
          "metaweave and weave" % typestring
116
 
    raise errors.BzrCommandError(msg)
 
102
    try:
 
103
        return bzrdir.format_registry.make_bzrdir(typestring)
 
104
    except KeyError:
 
105
        msg = 'Unknown bzr format "%s". See "bzr help formats".' % typestring
 
106
        raise errors.BzrCommandError(msg)
117
107
 
118
108
 
119
109
# TODO: Make sure no commands unconditionally use the working directory as a
460
450
 
461
451
    If the last argument is a versioned directory, all the other names
462
452
    are moved into it.  Otherwise, there must be exactly two arguments
463
 
    and the file is changed to a new name, which must not already exist.
 
453
    and the file is changed to a new name.
 
454
 
 
455
    If OLDNAME does not exist on the filesystem but is versioned and
 
456
    NEWNAME does exist on the filesystem but is not versioned, mv
 
457
    assumes that the file has been manually moved and only updates
 
458
    its internal inventory to reflect that change.
 
459
    The same is valid when moving many SOURCE files to a DESTINATION.
464
460
 
465
461
    Files cannot be moved between branches.
466
462
    """
467
463
 
468
464
    takes_args = ['names*']
 
465
    takes_options = [Option("after", help="move only the bzr identifier"
 
466
        " of the file (file has already been moved). Use this flag if"
 
467
        " bzr is not able to detect this itself.")]
469
468
    aliases = ['move', 'rename']
470
469
    encoding_type = 'replace'
471
470
 
472
 
    def run(self, names_list):
 
471
    def run(self, names_list, after=False):
473
472
        if names_list is None:
474
473
            names_list = []
475
474
 
479
478
        
480
479
        if os.path.isdir(names_list[-1]):
481
480
            # move into existing directory
482
 
            for pair in tree.move(rel_names[:-1], rel_names[-1]):
 
481
            for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
483
482
                self.outf.write("%s => %s\n" % pair)
484
483
        else:
485
484
            if len(names_list) != 2:
486
 
                raise errors.BzrCommandError('to mv multiple files the destination '
487
 
                                             'must be a versioned directory')
488
 
            tree.rename_one(rel_names[0], rel_names[1])
 
485
                raise errors.BzrCommandError('to mv multiple files the'
 
486
                                             ' destination must be a versioned'
 
487
                                             ' directory')
 
488
            tree.rename_one(rel_names[0], rel_names[1], after=after)
489
489
            self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
490
490
            
491
491
    
844
844
                                             % to_location)
845
845
            else:
846
846
                raise
847
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
848
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
849
 
        try:
850
 
            source.create_checkout(to_location, revision_id, lightweight)
851
 
        finally:
852
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
847
        source.create_checkout(to_location, revision_id, lightweight)
853
848
 
854
849
 
855
850
class cmd_renames(Command):
1094
1089
    """
1095
1090
    takes_args = ['location?']
1096
1091
    takes_options = [
1097
 
                     Option('format', 
 
1092
                     RegistryOption('format',
1098
1093
                            help='Specify a format for this branch. Current'
1099
1094
                                 ' formats are: default, knit, metaweave and'
1100
1095
                                 ' weave. Default is knit; metaweave and'
1101
1096
                                 ' weave are deprecated',
1102
 
                            type=get_format_type),
 
1097
                            registry=bzrdir.format_registry,
 
1098
                            converter=get_format_type,
 
1099
                            value_switches=True),
1103
1100
                     ]
1104
1101
    def run(self, location=None, format=None):
1105
1102
        if format is None:
1152
1149
        (add files here)
1153
1150
    """
1154
1151
    takes_args = ["location"] 
1155
 
    takes_options = [Option('format', 
 
1152
    takes_options = [RegistryOption('format',
1156
1153
                            help='Specify a format for this repository.'
1157
1154
                                 ' Current formats are: default, knit,'
1158
1155
                                 ' metaweave and weave. Default is knit;'
1159
1156
                                 ' metaweave and weave are deprecated',
1160
 
                            type=get_format_type),
 
1157
                            registry=bzrdir.format_registry,
 
1158
                            converter=get_format_type,
 
1159
                            value_switches=True),
1161
1160
                     Option('trees',
1162
1161
                             help='Allows branches in repository to have'
1163
1162
                             ' a working tree')]
1522
1521
    """List files in a tree.
1523
1522
    """
1524
1523
 
 
1524
    takes_args = ['path?']
1525
1525
    # TODO: Take a revision or remote path and list that tree instead.
1526
1526
    takes_options = ['verbose', 'revision',
1527
1527
                     Option('non-recursive',
1533
1533
                     Option('ignored', help='Print ignored files'),
1534
1534
 
1535
1535
                     Option('null', help='Null separate the files'),
1536
 
                     'kind',
 
1536
                     'kind', 'show-ids'
1537
1537
                    ]
1538
1538
    @display_command
1539
1539
    def run(self, revision=None, verbose=False, 
1540
1540
            non_recursive=False, from_root=False,
1541
1541
            unknown=False, versioned=False, ignored=False,
1542
 
            null=False, kind=None):
 
1542
            null=False, kind=None, show_ids=False, path=None):
1543
1543
 
1544
1544
        if kind and kind not in ('file', 'directory', 'symlink'):
1545
1545
            raise errors.BzrCommandError('invalid kind specified')
1550
1550
 
1551
1551
        selection = {'I':ignored, '?':unknown, 'V':versioned}
1552
1552
 
1553
 
        tree, relpath = WorkingTree.open_containing(u'.')
 
1553
        if path is None:
 
1554
            fs_path = '.'
 
1555
            prefix = ''
 
1556
        else:
 
1557
            if from_root:
 
1558
                raise errors.BzrCommandError('cannot specify both --from-root'
 
1559
                                             ' and PATH')
 
1560
            fs_path = path
 
1561
            prefix = path
 
1562
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
 
1563
            fs_path)
1554
1564
        if from_root:
1555
1565
            relpath = u''
1556
1566
        elif relpath:
1557
1567
            relpath += '/'
1558
1568
        if revision is not None:
1559
 
            tree = tree.branch.repository.revision_tree(
1560
 
                revision[0].in_history(tree.branch).rev_id)
 
1569
            tree = branch.repository.revision_tree(
 
1570
                revision[0].in_history(branch).rev_id)
 
1571
        elif tree is None:
 
1572
            tree = branch.basis_tree()
1561
1573
 
1562
1574
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1563
1575
            if fp.startswith(relpath):
1564
 
                fp = fp[len(relpath):]
 
1576
                fp = osutils.pathjoin(prefix, fp[len(relpath):])
1565
1577
                if non_recursive and '/' in fp:
1566
1578
                    continue
1567
1579
                if not all and not selection[fc]:
1570
1582
                    continue
1571
1583
                if verbose:
1572
1584
                    kindch = entry.kind_character()
1573
 
                    self.outf.write('%-8s %s%s\n' % (fc, fp, kindch))
 
1585
                    outstring = '%-8s %s%s' % (fc, fp, kindch)
 
1586
                    if show_ids and fid is not None:
 
1587
                        outstring = "%-50s %s" % (outstring, fid)
 
1588
                    self.outf.write(outstring + '\n')
1574
1589
                elif null:
1575
1590
                    self.outf.write(fp + '\0')
 
1591
                    if show_ids:
 
1592
                        if fid is not None:
 
1593
                            self.outf.write(fid)
 
1594
                        self.outf.write('\0')
1576
1595
                    self.outf.flush()
1577
1596
                else:
1578
 
                    self.outf.write(fp + '\n')
 
1597
                    if fid is not None:
 
1598
                        my_id = fid
 
1599
                    else:
 
1600
                        my_id = ''
 
1601
                    if show_ids:
 
1602
                        self.outf.write('%-50s %s\n' % (fp, my_id))
 
1603
                    else:
 
1604
                        self.outf.write(fp + '\n')
1579
1605
 
1580
1606
 
1581
1607
class cmd_unknowns(Command):
1955
1981
    """
1956
1982
    takes_args = ['url?']
1957
1983
    takes_options = [
1958
 
                     Option('format', 
1959
 
                            help='Upgrade to a specific format. Current formats'
1960
 
                                 ' are: default, knit, metaweave and weave.'
1961
 
                                 ' Default is knit; metaweave and weave are'
1962
 
                                 ' deprecated',
1963
 
                            type=get_format_type),
 
1984
                    RegistryOption('format',
 
1985
                        help='Upgrade to a specific format. Current formats'
 
1986
                             ' are: default, knit, metaweave and weave.'
 
1987
                             ' Default is knit; metaweave and weave are'
 
1988
                             ' deprecated',
 
1989
                        registry=bzrdir.format_registry,
 
1990
                        converter=get_format_type,
 
1991
                        value_switches=True),
1964
1992
                    ]
1965
1993
 
1966
1994
 
2038
2066
class cmd_selftest(Command):
2039
2067
    """Run internal test suite.
2040
2068
    
2041
 
    This creates temporary test directories in the working directory,
2042
 
    but not existing data is affected.  These directories are deleted
2043
 
    if the tests pass, or left behind to help in debugging if they
2044
 
    fail and --keep-output is specified.
 
2069
    This creates temporary test directories in the working directory, but not
 
2070
    existing data is affected.  These directories are deleted if the tests
 
2071
    pass, or left behind to help in debugging if they fail and --keep-output
 
2072
    is specified.
2045
2073
    
2046
 
    If arguments are given, they are regular expressions that say
2047
 
    which tests should run.
 
2074
    If arguments are given, they are regular expressions that say which tests
 
2075
    should run.  Tests matching any expression are run, and other tests are
 
2076
    not run.
 
2077
 
 
2078
    Alternatively if --first is given, matching tests are run first and then
 
2079
    all other tests are run.  This is useful if you have been working in a
 
2080
    particular area, but want to make sure nothing else was broken.
2048
2081
 
2049
2082
    If the global option '--no-plugins' is given, plugins are not loaded
2050
2083
    before running the selftests.  This has two effects: features provided or
2051
2084
    modified by plugins will not be tested, and tests provided by plugins will
2052
2085
    not be run.
2053
2086
 
2054
 
    examples:
 
2087
    examples::
2055
2088
        bzr selftest ignore
 
2089
            run only tests relating to 'ignore'
2056
2090
        bzr --no-plugins selftest -v
 
2091
            disable plugins and list tests as they're run
2057
2092
    """
2058
2093
    # TODO: --list should give a list of all available tests
2059
2094
 
2094
2129
                     Option('clean-output',
2095
2130
                            help='clean temporary tests directories'
2096
2131
                                 ' without running tests'),
 
2132
                     Option('first',
 
2133
                            help='run all tests, but run specified tests first',
 
2134
                            )
2097
2135
                     ]
 
2136
    encoding_type = 'replace'
2098
2137
 
2099
2138
    def run(self, testspecs_list=None, verbose=None, one=False,
2100
2139
            keep_output=False, transport=None, benchmark=None,
2101
 
            lsprof_timed=None, cache_dir=None, clean_output=False):
 
2140
            lsprof_timed=None, cache_dir=None, clean_output=False,
 
2141
            first=False):
2102
2142
        import bzrlib.ui
2103
2143
        from bzrlib.tests import selftest
2104
2144
        import bzrlib.benchmarks as benchmarks
2137
2177
                              transport=transport,
2138
2178
                              test_suite_factory=test_suite_factory,
2139
2179
                              lsprof_timed=lsprof_timed,
2140
 
                              bench_history=benchfile)
 
2180
                              bench_history=benchfile,
 
2181
                              matching_tests_first=first,
 
2182
                              )
2141
2183
        finally:
2142
2184
            if benchfile is not None:
2143
2185
                benchfile.close()
2589
2631
            other_branch = parent
2590
2632
            if other_branch is None:
2591
2633
                raise errors.BzrCommandError("No peer location known or specified.")
2592
 
            print "Using last location: " + local_branch.get_parent()
 
2634
            display_url = urlutils.unescape_for_display(parent,
 
2635
                                                        self.outf.encoding)
 
2636
            print "Using last location: " + display_url
 
2637
 
2593
2638
        remote_branch = Branch.open(other_branch)
2594
2639
        if remote_branch.base == local_branch.base:
2595
2640
            remote_branch = local_branch