/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:
128
128
    This reports on versioned and unknown files, reporting them
129
129
    grouped by state.  Possible states are:
130
130
 
131
 
    added
 
131
    added / A
132
132
        Versioned in the working copy but not in the previous revision.
133
133
 
134
 
    removed
 
134
    removed / D
135
135
        Versioned in the previous revision but removed or deleted
136
136
        in the working copy.
137
137
 
138
 
    renamed
 
138
    renamed / R
139
139
        Path of this file changed from the previous revision;
140
140
        the text may also have changed.  This includes files whose
141
141
        parent directory was renamed.
142
142
 
143
 
    modified
 
143
    modified / M
144
144
        Text has changed since the previous revision.
145
145
 
146
 
    unknown
 
146
    unknown / ?
147
147
        Not versioned and not matching an ignore pattern.
148
148
 
149
149
    To see ignored files use 'bzr ignored'.  For details in the
150
150
    changes to file texts, use 'bzr diff'.
 
151
    
 
152
    --short gives a one character status flag for each item, similar
 
153
    to the SVN's status command.
151
154
 
152
155
    If no arguments are specified, the status of the entire working
153
156
    directory is shown.  Otherwise, only the status of the specified
161
164
    # TODO: --no-recurse, --recurse options
162
165
    
163
166
    takes_args = ['file*']
164
 
    takes_options = ['show-ids', 'revision']
 
167
    takes_options = ['show-ids', 'revision', 'short']
165
168
    aliases = ['st', 'stat']
166
169
 
167
170
    encoding_type = 'replace'
168
171
    
169
172
    @display_command
170
 
    def run(self, show_ids=False, file_list=None, revision=None):
 
173
    def run(self, show_ids=False, file_list=None, revision=None, short=False):
171
174
        from bzrlib.status import show_tree_status
172
175
 
173
176
        tree, file_list = tree_files(file_list)
174
177
            
175
178
        show_tree_status(tree, show_ids=show_ids,
176
179
                         specific_files=file_list, revision=revision,
177
 
                         to_file=self.outf)
 
180
                         to_file=self.outf,
 
181
                         short=short)
178
182
 
179
183
 
180
184
class cmd_cat_revision(Command):
1209
1213
    #       deleted files.
1210
1214
 
1211
1215
    # TODO: This probably handles non-Unix newlines poorly.
1212
 
    
 
1216
 
1213
1217
    takes_args = ['file*']
1214
 
    takes_options = ['revision', 'diff-options', 'prefix']
 
1218
    takes_options = ['revision', 'diff-options',
 
1219
        Option('prefix', type=str,
 
1220
               short_name='p',
 
1221
               help='Set prefixes to added to old and new filenames, as '
 
1222
                    'two values separated by a colon.'),
 
1223
        ]
1215
1224
    aliases = ['di', 'dif']
1216
1225
    encoding_type = 'exact'
1217
1226
 
1227
1236
        elif prefix == '1':
1228
1237
            old_label = 'old/'
1229
1238
            new_label = 'new/'
1230
 
        else:
1231
 
            if not ':' in prefix:
1232
 
                 raise BzrCommandError(
1233
 
                     "--diff-prefix expects two values separated by a colon")
 
1239
        elif ':' in prefix:
1234
1240
            old_label, new_label = prefix.split(":")
 
1241
        else:
 
1242
            raise BzrCommandError(
 
1243
                "--prefix expects two values separated by a colon")
 
1244
 
 
1245
        if revision and len(revision) > 2:
 
1246
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
 
1247
                                         ' one or two revision specifiers')
1235
1248
        
1236
1249
        try:
1237
1250
            tree1, file_list = internal_tree_files(file_list)
1257
1270
                tree1, tree2 = None, None
1258
1271
            else:
1259
1272
                raise
1260
 
        if revision is not None:
1261
 
            if tree2 is not None:
1262
 
                raise errors.BzrCommandError("Can't specify -r with two branches")
1263
 
            if (len(revision) == 1) or (revision[1].spec is None):
1264
 
                return diff_cmd_helper(tree1, file_list, diff_options,
1265
 
                                       revision[0], 
1266
 
                                       old_label=old_label, new_label=new_label)
1267
 
            elif len(revision) == 2:
1268
 
                return diff_cmd_helper(tree1, file_list, diff_options,
1269
 
                                       revision[0], revision[1],
1270
 
                                       old_label=old_label, new_label=new_label)
1271
 
            else:
1272
 
                raise errors.BzrCommandError('bzr diff --revision takes exactly'
1273
 
                                             ' one or two revision identifiers')
1274
 
        else:
1275
 
            if tree2 is not None:
1276
 
                return show_diff_trees(tree1, tree2, sys.stdout, 
1277
 
                                       specific_files=file_list,
1278
 
                                       external_diff_options=diff_options,
1279
 
                                       old_label=old_label, new_label=new_label)
1280
 
            else:
1281
 
                return diff_cmd_helper(tree1, file_list, diff_options,
1282
 
                                       old_label=old_label, new_label=new_label)
 
1273
 
 
1274
        if tree2 is not None:
 
1275
            if revision is not None:
 
1276
                # FIXME: but there should be a clean way to diff between
 
1277
                # non-default versions of two trees, it's not hard to do
 
1278
                # internally...
 
1279
                raise errors.BzrCommandError(
 
1280
                        "Sorry, diffing arbitrary revisions across branches "
 
1281
                        "is not implemented yet")
 
1282
            return show_diff_trees(tree1, tree2, sys.stdout, 
 
1283
                                   specific_files=file_list,
 
1284
                                   external_diff_options=diff_options,
 
1285
                                   old_label=old_label, new_label=new_label)
 
1286
 
 
1287
        return diff_cmd_helper(tree1, file_list, diff_options,
 
1288
                               revision_specs=revision,
 
1289
                               old_label=old_label, new_label=new_label)
1283
1290
 
1284
1291
 
1285
1292
class cmd_deleted(Command):
1371
1378
                            help='show from oldest to newest'),
1372
1379
                     'timezone', 
1373
1380
                     Option('verbose', 
 
1381
                             short_name='v',
1374
1382
                             help='show files changed in each revision'),
1375
1383
                     'show-ids', 'revision',
1376
1384
                     'log-format',
1377
1385
                     'line', 'long', 
1378
1386
                     Option('message',
 
1387
                            short_name='m',
1379
1388
                            help='show revisions whose message matches this regexp',
1380
1389
                            type=str),
1381
1390
                     'short',
1512
1521
class cmd_ls(Command):
1513
1522
    """List files in a tree.
1514
1523
    """
 
1524
 
1515
1525
    # TODO: Take a revision or remote path and list that tree instead.
1516
 
    hidden = True
1517
1526
    takes_options = ['verbose', 'revision',
1518
1527
                     Option('non-recursive',
1519
1528
                            help='don\'t recurse into sub-directories'),
1524
1533
                     Option('ignored', help='Print ignored files'),
1525
1534
 
1526
1535
                     Option('null', help='Null separate the files'),
 
1536
                     'kind',
1527
1537
                    ]
1528
1538
    @display_command
1529
1539
    def run(self, revision=None, verbose=False, 
1530
1540
            non_recursive=False, from_root=False,
1531
1541
            unknown=False, versioned=False, ignored=False,
1532
 
            null=False):
 
1542
            null=False, kind=None):
 
1543
 
 
1544
        if kind and kind not in ('file', 'directory', 'symlink'):
 
1545
            raise errors.BzrCommandError('invalid kind specified')
1533
1546
 
1534
1547
        if verbose and null:
1535
1548
            raise errors.BzrCommandError('Cannot set both --verbose and --null')
1546
1559
            tree = tree.branch.repository.revision_tree(
1547
1560
                revision[0].in_history(tree.branch).rev_id)
1548
1561
 
1549
 
        for fp, fc, kind, fid, entry in tree.list_files(include_root=False):
 
1562
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1550
1563
            if fp.startswith(relpath):
1551
1564
                fp = fp[len(relpath):]
1552
1565
                if non_recursive and '/' in fp:
1553
1566
                    continue
1554
1567
                if not all and not selection[fc]:
1555
1568
                    continue
 
1569
                if kind is not None and fkind != kind:
 
1570
                    continue
1556
1571
                if verbose:
1557
1572
                    kindch = entry.kind_character()
1558
1573
                    self.outf.write('%-8s %s%s\n' % (fc, fp, kindch))
1577
1592
    To remove patterns from the ignore list, edit the .bzrignore file.
1578
1593
 
1579
1594
    Trailing slashes on patterns are ignored. 
1580
 
    If the pattern contains a slash, it is compared to the whole path
1581
 
    from the branch root.  Otherwise, it is compared to only the last
1582
 
    component of the path.  To match a file only in the root directory,
1583
 
    prepend './'.
 
1595
    If the pattern contains a slash or is a regular expression, it is compared 
 
1596
    to the whole path from the branch root.  Otherwise, it is compared to only
 
1597
    the last component of the path.  To match a file only in the root 
 
1598
    directory, prepend './'.
1584
1599
 
1585
1600
    Ignore patterns specifying absolute paths are not allowed.
1586
1601
 
1587
 
    Ignore patterns are case-insensitive on case-insensitive systems.
 
1602
    Ignore patterns may include globbing wildcards such as:
 
1603
      ? - Matches any single character except '/'
 
1604
      * - Matches 0 or more characters except '/'
 
1605
      /**/ - Matches 0 or more directories in a path
 
1606
      [a-z] - Matches a single character from within a group of characters
 
1607
 
 
1608
    Ignore patterns may also be Python regular expressions.  
 
1609
    Regular expression ignore patterns are identified by a 'RE:' prefix 
 
1610
    followed by the regular expression.  Regular expression ignore patterns
 
1611
    may not include named or numbered groups.
1588
1612
 
1589
 
    Note: wildcards must be quoted from the shell on Unix.
 
1613
    Note: ignore patterns containing shell wildcards must be quoted from 
 
1614
    the shell on Unix.
1590
1615
 
1591
1616
    examples:
1592
1617
        bzr ignore ./Makefile
1593
1618
        bzr ignore '*.class'
 
1619
        bzr ignore 'lib/**/*.o'
 
1620
        bzr ignore 'RE:lib/.*\.o'
1594
1621
    """
1595
1622
    takes_args = ['name_pattern*']
1596
1623
    takes_options = [
1734
1761
 
1735
1762
    takes_options = ['revision', 'name-from-revision']
1736
1763
    takes_args = ['filename']
 
1764
    encoding_type = 'exact'
1737
1765
 
1738
1766
    @display_command
1739
1767
    def run(self, filename, revision=None, name_from_revision=False):
1745
1773
        try:
1746
1774
            tree, relpath = WorkingTree.open_containing(filename)
1747
1775
            b = tree.branch
1748
 
        except errors.NotBranchError:
 
1776
        except (errors.NotBranchError, errors.NotLocalUrl):
1749
1777
            pass
1750
1778
 
 
1779
        if revision is not None and revision[0].get_branch() is not None:
 
1780
            b = Branch.open(revision[0].get_branch())
1751
1781
        if tree is None:
1752
1782
            b, relpath = Branch.open_containing(filename)
1753
 
        if revision is not None and revision[0].get_branch() is not None:
1754
 
            b = Branch.open(revision[0].get_branch())
 
1783
            tree = b.basis_tree()
1755
1784
        if revision is None:
1756
1785
            revision_id = b.last_revision()
1757
1786
        else:
1812
1841
                     Option('unchanged',
1813
1842
                            help='commit even if nothing has changed'),
1814
1843
                     Option('file', type=str, 
 
1844
                            short_name='F',
1815
1845
                            argname='msgfile',
1816
1846
                            help='file containing commit message'),
1817
1847
                     Option('strict',
1848
1878
 
1849
1879
        if local and not tree.branch.get_bound_location():
1850
1880
            raise errors.LocalRequiresBoundBranch()
1851
 
        if message is None and not file:
1852
 
            template = make_commit_message_template(tree, selected_list)
1853
 
            message = edit_commit_message(template)
1854
 
            if message is None:
1855
 
                raise errors.BzrCommandError("please specify a commit message"
1856
 
                                             " with either --message or --file")
1857
 
        elif message and file:
1858
 
            raise errors.BzrCommandError("please specify either --message or --file")
1859
 
        
1860
 
        if file:
1861
 
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1862
1881
 
1863
 
        if message == "":
1864
 
            raise errors.BzrCommandError("empty commit message specified")
 
1882
        def get_message(commit_obj):
 
1883
            """Callback to get commit message"""
 
1884
            my_message = message
 
1885
            if my_message is None and not file:
 
1886
                template = make_commit_message_template(tree, selected_list)
 
1887
                my_message = edit_commit_message(template)
 
1888
                if my_message is None:
 
1889
                    raise errors.BzrCommandError("please specify a commit"
 
1890
                        " message with either --message or --file")
 
1891
            elif my_message and file:
 
1892
                raise errors.BzrCommandError(
 
1893
                    "please specify either --message or --file")
 
1894
            if file:
 
1895
                my_message = codecs.open(file, 'rt', 
 
1896
                                         bzrlib.user_encoding).read()
 
1897
            if my_message == "":
 
1898
                raise errors.BzrCommandError("empty commit message specified")
 
1899
            return my_message
1865
1900
        
1866
1901
        if verbose:
1867
1902
            reporter = ReportCommitToLog()
1869
1904
            reporter = NullCommitReporter()
1870
1905
 
1871
1906
        try:
1872
 
            tree.commit(message, specific_files=selected_list,
 
1907
            tree.commit(message_callback=get_message,
 
1908
                        specific_files=selected_list,
1873
1909
                        allow_pointless=unchanged, strict=strict, local=local,
1874
1910
                        reporter=reporter)
1875
1911
        except PointlessCommit:
2055
2091
                     Option('cache-dir', type=str,
2056
2092
                            help='a directory to cache intermediate'
2057
2093
                                 ' benchmark steps'),
 
2094
                     Option('clean-output',
 
2095
                            help='clean temporary tests directories'
 
2096
                                 ' without running tests'),
2058
2097
                     ]
2059
2098
 
2060
2099
    def run(self, testspecs_list=None, verbose=None, one=False,
2061
2100
            keep_output=False, transport=None, benchmark=None,
2062
 
            lsprof_timed=None, cache_dir=None):
 
2101
            lsprof_timed=None, cache_dir=None, clean_output=False):
2063
2102
        import bzrlib.ui
2064
2103
        from bzrlib.tests import selftest
2065
2104
        import bzrlib.benchmarks as benchmarks
2066
2105
        from bzrlib.benchmarks import tree_creator
2067
2106
 
 
2107
        if clean_output:
 
2108
            from bzrlib.tests import clean_selftest_output
 
2109
            clean_selftest_output()
 
2110
            return 0
 
2111
 
2068
2112
        if cache_dir is not None:
2069
2113
            tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
2070
2114
        print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
2079
2123
            if verbose is None:
2080
2124
                verbose = True
2081
2125
            # TODO: should possibly lock the history file...
2082
 
            benchfile = open(".perf_history", "at")
 
2126
            benchfile = open(".perf_history", "at", buffering=1)
2083
2127
        else:
2084
2128
            test_suite_factory = None
2085
2129
            if verbose is None:
2195
2239
    takes_args = ['branch?']
2196
2240
    takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2197
2241
                     Option('show-base', help="Show base revision text in "
2198
 
                            "conflicts"), 
 
2242
                            "conflicts"),
2199
2243
                     Option('uncommitted', help='Apply uncommitted changes'
2200
 
                            ' from a working copy, instead of branch changes')]
 
2244
                            ' from a working copy, instead of branch changes'),
 
2245
                     Option('pull', help='If the destination is already'
 
2246
                             ' completely merged into the source, pull from the'
 
2247
                             ' source rather than merging. When this happens,'
 
2248
                             ' you do not need to commit the result.'),
 
2249
                     ]
2201
2250
 
2202
2251
    def help(self):
2203
2252
        from inspect import getdoc
2205
2254
 
2206
2255
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2207
2256
            show_base=False, reprocess=False, remember=False, 
2208
 
            uncommitted=False):
 
2257
            uncommitted=False, pull=False):
2209
2258
        if merge_type is None:
2210
2259
            merge_type = _mod_merge.Merge3Merger
2211
2260
 
2276
2325
                    merge_type=merge_type,
2277
2326
                    reprocess=reprocess,
2278
2327
                    show_base=show_base,
 
2328
                    pull=pull,
2279
2329
                    pb=pb, file_list=interesting_files)
2280
2330
            finally:
2281
2331
                pb.finished()
2660
2710
    takes_args = ['filename']
2661
2711
    takes_options = [Option('all', help='show annotations on all lines'),
2662
2712
                     Option('long', help='show date in annotations'),
2663
 
                     'revision'
 
2713
                     'revision',
 
2714
                     'show-ids',
2664
2715
                     ]
2665
2716
 
2666
2717
    @display_command
2667
 
    def run(self, filename, all=False, long=False, revision=None):
 
2718
    def run(self, filename, all=False, long=False, revision=None,
 
2719
            show_ids=False):
2668
2720
        from bzrlib.annotate import annotate_file
2669
2721
        tree, relpath = WorkingTree.open_containing(filename)
2670
2722
        branch = tree.branch
2679
2731
            file_id = tree.inventory.path2id(relpath)
2680
2732
            tree = branch.repository.revision_tree(revision_id)
2681
2733
            file_version = tree.inventory[file_id].revision
2682
 
            annotate_file(branch, file_version, file_id, long, all, sys.stdout)
 
2734
            annotate_file(branch, file_version, file_id, long, all, sys.stdout,
 
2735
                          show_ids=show_ids)
2683
2736
        finally:
2684
2737
            branch.unlock()
2685
2738
 
2934
2987
                  this_dir=None, backup_files=False,
2935
2988
                  merge_type=None,
2936
2989
                  file_list=None, show_base=False, reprocess=False,
 
2990
                  pull=False,
2937
2991
                  pb=DummyProgress()):
2938
2992
    """Merge changes into a tree.
2939
2993
 
2988
3042
        if merger.base_rev_id == merger.other_rev_id:
2989
3043
            note('Nothing to do.')
2990
3044
            return 0
 
3045
        if file_list is None:
 
3046
            if pull and merger.base_rev_id == merger.this_rev_id:
 
3047
                count = merger.this_tree.pull(merger.this_branch,
 
3048
                        False, merger.other_rev_id)
 
3049
                note('%d revision(s) pulled.' % (count,))
 
3050
                return 0
2991
3051
        merger.backup_files = backup_files
2992
3052
        merger.merge_type = merge_type 
2993
3053
        merger.set_interesting_files(file_list)