/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: Robert Collins
  • Date: 2007-04-23 02:29:35 UTC
  • mfrom: (2441 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070423022935-9hhongamvk6bfdso
Resolve conflicts with bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""builtin bzr commands"""
18
18
 
19
19
import os
 
20
from StringIO import StringIO
20
21
 
21
22
from bzrlib.lazy_import import lazy_import
22
23
lazy_import(globals(), """
23
24
import codecs
24
25
import errno
 
26
import smtplib
25
27
import sys
26
28
import tempfile
 
29
import time
27
30
 
28
31
import bzrlib
29
32
from bzrlib import (
37
40
    ignores,
38
41
    log,
39
42
    merge as _mod_merge,
 
43
    merge_directive,
40
44
    osutils,
 
45
    registry,
41
46
    repository,
42
47
    symbol_versioning,
43
48
    transport,
143
148
    unknown
144
149
        Not versioned and not matching an ignore pattern.
145
150
 
146
 
    To see ignored files use 'bzr ignored'.  For details in the
 
151
    To see ignored files use 'bzr ignored'.  For details on the
147
152
    changes to file texts, use 'bzr diff'.
148
153
    
149
154
    --short gives a status flags for each item, similar to the SVN's status
178
183
    # TODO: --no-recurse, --recurse options
179
184
    
180
185
    takes_args = ['file*']
181
 
    takes_options = ['show-ids', 'revision', 'short']
 
186
    takes_options = ['show-ids', 'revision',
 
187
                     Option('short', help='Give short SVN-style status lines'),
 
188
                     Option('versioned', help='Only show versioned files')]
182
189
    aliases = ['st', 'stat']
183
190
 
184
191
    encoding_type = 'replace'
 
192
    _see_also = ['diff', 'revert']
185
193
    
186
194
    @display_command
187
 
    def run(self, show_ids=False, file_list=None, revision=None, short=False):
 
195
    def run(self, show_ids=False, file_list=None, revision=None, short=False,
 
196
            versioned=False):
188
197
        from bzrlib.status import show_tree_status
189
198
 
190
199
        tree, file_list = tree_files(file_list)
191
200
            
192
201
        show_tree_status(tree, show_ids=show_ids,
193
202
                         specific_files=file_list, revision=revision,
194
 
                         to_file=self.outf,
195
 
                         short=short)
 
203
                         to_file=self.outf, short=short, versioned=versioned)
196
204
 
197
205
 
198
206
class cmd_cat_revision(Command):
211
219
    @display_command
212
220
    def run(self, revision_id=None, revision=None):
213
221
 
 
222
        revision_id = osutils.safe_revision_id(revision_id, warn=False)
214
223
        if revision_id is not None and revision is not None:
215
224
            raise errors.BzrCommandError('You can only supply one of'
216
225
                                         ' revision_id or --revision')
236
245
 
237
246
    Since a lightweight checkout is little more than a working tree
238
247
    this will refuse to run against one.
 
248
 
 
249
    To re-create the working tree, use "bzr checkout".
239
250
    """
 
251
    _see_also = ['checkout']
240
252
 
241
253
    takes_args = ['location?']
242
254
 
266
278
    This is equal to the number of revisions on this branch.
267
279
    """
268
280
 
 
281
    _see_also = ['info']
269
282
    takes_args = ['location?']
270
283
 
271
284
    @display_command
331
344
 
332
345
    --file-ids-from will try to use the file ids from the supplied path.
333
346
    It looks up ids trying to find a matching parent directory with the
334
 
    same filename, and then by pure path.
 
347
    same filename, and then by pure path. This option is rarely needed
 
348
    but can be useful when adding the same logical file into two
 
349
    branches that will be merged later (without showing the two different
 
350
    adds as a conflict). It is also useful when merging another project
 
351
    into a subdirectory of this one.
335
352
    """
336
353
    takes_args = ['file*']
337
354
    takes_options = ['no-recurse', 'dry-run', 'verbose',
338
355
                     Option('file-ids-from', type=unicode,
339
356
                            help='Lookup file ids from here')]
340
357
    encoding_type = 'replace'
 
358
    _see_also = ['remove']
341
359
 
342
360
    def run(self, file_list, no_recurse=False, dry_run=False, verbose=False,
343
361
            file_ids_from=None):
422
440
 
423
441
    It is also possible to restrict the list of files to a specific
424
442
    set. For example: bzr inventory --show-ids this/file
425
 
 
426
 
    See also: bzr ls
427
443
    """
428
444
 
429
445
    hidden = True
430
 
 
 
446
    _see_also = ['ls']
431
447
    takes_options = ['revision', 'show-ids', 'kind']
432
 
 
433
448
    takes_args = ['file*']
434
449
 
435
450
    @display_command
546
561
    location can be accessed.
547
562
    """
548
563
 
 
564
    _see_also = ['push', 'update']
549
565
    takes_options = ['remember', 'overwrite', 'revision', 'verbose',
550
566
        Option('directory',
551
567
            help='branch to pull into, '
562
578
            directory=None):
563
579
        from bzrlib.tag import _merge_tags_if_possible
564
580
        # FIXME: too much stuff is in the command class
 
581
        revision_id = None
 
582
        mergeable = None
565
583
        if directory is None:
566
584
            directory = u'.'
567
585
        try:
574
592
        reader = None
575
593
        if location is not None:
576
594
            try:
577
 
                reader = bundle.read_bundle_from_url(location)
 
595
                mergeable = bundle.read_mergeable_from_url(
 
596
                    location)
578
597
            except errors.NotABundle:
579
598
                pass # Continue on considering this url a Branch
580
599
 
589
608
                self.outf.write("Using saved location: %s\n" % display_url)
590
609
                location = stored_loc
591
610
 
592
 
        if reader is not None:
593
 
            install_bundle(branch_to.repository, reader)
 
611
        if mergeable is not None:
 
612
            if revision is not None:
 
613
                raise errors.BzrCommandError(
 
614
                    'Cannot use -r with merge directives or bundles')
 
615
            revision_id = mergeable.install_revisions(branch_to.repository)
594
616
            branch_from = branch_to
595
617
        else:
596
618
            branch_from = Branch.open(location)
598
620
            if branch_to.get_parent() is None or remember:
599
621
                branch_to.set_parent(branch_from.base)
600
622
 
601
 
        rev_id = None
602
 
        if revision is None:
603
 
            if reader is not None:
604
 
                rev_id = reader.target
605
 
        elif len(revision) == 1:
606
 
            rev_id = revision[0].in_history(branch_from).rev_id
607
 
        else:
608
 
            raise errors.BzrCommandError('bzr pull --revision takes one value.')
 
623
        if revision is not None:
 
624
            if len(revision) == 1:
 
625
                revision_id = revision[0].in_history(branch_from).rev_id
 
626
            else:
 
627
                raise errors.BzrCommandError(
 
628
                    'bzr pull --revision takes one value.')
609
629
 
610
630
        old_rh = branch_to.revision_history()
611
631
        if tree_to is not None:
612
 
            result = tree_to.pull(branch_from, overwrite, rev_id,
613
 
                delta.ChangeReporter(unversioned_filter=tree_to.is_ignored))
 
632
            result = tree_to.pull(branch_from, overwrite, revision_id,
 
633
                delta._ChangeReporter(unversioned_filter=tree_to.is_ignored))
614
634
        else:
615
 
            result = branch_to.pull(branch_from, overwrite, rev_id)
 
635
            result = branch_to.pull(branch_from, overwrite, revision_id)
616
636
 
617
637
        result.report(self.outf)
618
638
        if verbose:
619
639
            from bzrlib.log import show_changed_revisions
620
640
            new_rh = branch_to.revision_history()
621
 
            show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
 
641
            show_changed_revisions(branch_to, old_rh, new_rh,
 
642
                                   to_file=self.outf)
622
643
 
623
644
 
624
645
class cmd_push(Command):
647
668
    location can be accessed.
648
669
    """
649
670
 
 
671
    _see_also = ['pull', 'update']
650
672
    takes_options = ['remember', 'overwrite', 'verbose',
651
673
        Option('create-prefix',
652
674
               help='Create the path leading up to the branch '
828
850
 
829
851
    To retrieve the branch as of a particular revision, supply the --revision
830
852
    parameter, as in "branch foo/bar -r 5".
 
853
    """
831
854
 
832
 
    --basis is to speed up branching from remote branches.  When specified, it
833
 
    copies all the file-contents, inventory and revision data from the basis
834
 
    branch before copying anything from the remote branch.
835
 
    """
 
855
    _see_also = ['checkout']
836
856
    takes_args = ['from_location', 'to_location?']
837
 
    takes_options = ['revision', 'basis']
 
857
    takes_options = ['revision']
838
858
    aliases = ['get', 'clone']
839
859
 
840
 
    def run(self, from_location, to_location=None, revision=None, basis=None):
 
860
    def run(self, from_location, to_location=None, revision=None):
841
861
        from bzrlib.tag import _merge_tags_if_possible
842
862
        if revision is None:
843
863
            revision = [None]
848
868
        br_from = Branch.open(from_location)
849
869
        br_from.lock_read()
850
870
        try:
851
 
            if basis is not None:
852
 
                basis_dir = bzrdir.BzrDir.open_containing(basis)[0]
853
 
            else:
854
 
                basis_dir = None
855
871
            if len(revision) == 1 and revision[0] is not None:
856
872
                revision_id = revision[0].in_history(br_from)[1]
857
873
            else:
876
892
                                             % to_location)
877
893
            try:
878
894
                # preserve whatever source format we have.
879
 
                dir = br_from.bzrdir.sprout(to_transport.base,
880
 
                        revision_id, basis_dir)
 
895
                dir = br_from.bzrdir.sprout(to_transport.base, revision_id)
881
896
                branch = dir.open_branch()
882
897
            except errors.NoSuchRevision:
883
898
                to_transport.delete_tree('.')
884
899
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
885
900
                raise errors.BzrCommandError(msg)
886
 
            except errors.UnlistableBranch:
887
 
                osutils.rmtree(to_location)
888
 
                msg = "The branch %s cannot be used as a --basis" % (basis,)
889
 
                raise errors.BzrCommandError(msg)
890
901
            if name:
891
902
                branch.control_files.put_utf8('branch-name', name)
892
903
            _merge_tags_if_possible(br_from, branch)
910
921
    parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
911
922
    out of date [so you cannot commit] but it may be useful (i.e. to examine old
912
923
    code.)
913
 
 
914
 
    --basis is to speed up checking out from remote branches.  When specified, it
915
 
    uses the inventory and file contents from the basis branch in preference to the
916
 
    branch being checked out.
917
 
 
918
 
    See "help checkouts" for more information on checkouts.
919
924
    """
 
925
 
 
926
    _see_also = ['checkouts', 'branch']
920
927
    takes_args = ['branch_location?', 'to_location?']
921
 
    takes_options = ['revision', # , 'basis']
 
928
    takes_options = ['revision',
922
929
                     Option('lightweight',
923
930
                            help="perform a lightweight checkout. Lightweight "
924
931
                                 "checkouts depend on access to the branch for "
929
936
                     ]
930
937
    aliases = ['co']
931
938
 
932
 
    def run(self, branch_location=None, to_location=None, revision=None, basis=None,
 
939
    def run(self, branch_location=None, to_location=None, revision=None,
933
940
            lightweight=False):
934
941
        if revision is None:
935
942
            revision = [None]
976
983
    # TODO: Option to show renames between two historical versions.
977
984
 
978
985
    # TODO: Only show renames under dir, rather than in the whole branch.
 
986
    _see_also = ['status']
979
987
    takes_args = ['dir?']
980
988
 
981
989
    @display_command
1008
1016
    If you want to discard your local changes, you can just do a 
1009
1017
    'bzr revert' instead of 'bzr commit' after the update.
1010
1018
    """
 
1019
 
 
1020
    _see_also = ['pull']
1011
1021
    takes_args = ['dir?']
1012
1022
    aliases = ['up']
1013
1023
 
1051
1061
 
1052
1062
    Branches and working trees will also report any missing revisions.
1053
1063
    """
 
1064
    _see_also = ['revno']
1054
1065
    takes_args = ['location?']
1055
1066
    takes_options = ['verbose']
1056
1067
 
1101
1112
    """
1102
1113
 
1103
1114
    hidden = True
 
1115
    _see_also = ['inventory', 'ls']
1104
1116
    takes_args = ['filename']
1105
1117
 
1106
1118
    @display_command
1153
1165
 
1154
1166
    The branch *MUST* be on a listable system such as local disk or sftp.
1155
1167
    """
 
1168
 
 
1169
    _see_also = ['check']
1156
1170
    takes_args = ['branch?']
1157
1171
 
1158
1172
    def run(self, branch="."):
1163
1177
 
1164
1178
class cmd_revision_history(Command):
1165
1179
    """Display the list of revision ids on a branch."""
 
1180
 
 
1181
    _see_also = ['log']
1166
1182
    takes_args = ['location?']
1167
1183
 
1168
1184
    hidden = True
1177
1193
 
1178
1194
class cmd_ancestry(Command):
1179
1195
    """List all revisions merged into this branch."""
 
1196
 
 
1197
    _see_also = ['log', 'revision-history']
1180
1198
    takes_args = ['location?']
1181
1199
 
1182
1200
    hidden = True
1207
1225
 
1208
1226
    If there is a repository in a parent directory of the location, then 
1209
1227
    the history of the branch will be stored in the repository.  Otherwise
1210
 
    init creates a standalone branch which carries its own history in 
1211
 
    .bzr.
 
1228
    init creates a standalone branch which carries its own history
 
1229
    in the .bzr directory.
1212
1230
 
1213
1231
    If there is already a branch at the location but it has no working tree,
1214
1232
    the tree can be populated with 'bzr checkout'.
1220
1238
        bzr status
1221
1239
        bzr commit -m 'imported project'
1222
1240
    """
 
1241
 
 
1242
    _see_also = ['init-repo', 'branch', 'checkout']
1223
1243
    takes_args = ['location?']
1224
1244
    takes_options = [
1225
1245
         RegistryOption('format',
1281
1301
    """Create a shared repository to hold branches.
1282
1302
 
1283
1303
    New branches created under the repository directory will store their revisions
1284
 
    in the repository, not in the branch directory, if the branch format supports
1285
 
    shared storage.
 
1304
    in the repository, not in the branch directory.
1286
1305
 
1287
1306
    example:
1288
 
        bzr init-repo repo
 
1307
        bzr init-repo --no-trees repo
1289
1308
        bzr init repo/trunk
1290
1309
        bzr checkout --lightweight repo/trunk trunk-checkout
1291
1310
        cd trunk-checkout
1292
1311
        (add files here)
1293
1312
    """
 
1313
 
 
1314
    _see_also = ['init', 'branch', 'checkout']
1294
1315
    takes_args = ["location"]
1295
1316
    takes_options = [RegistryOption('format',
1296
1317
                            help='Specify a format for this repository. See'
1298
1319
                            registry=bzrdir.format_registry,
1299
1320
                            converter=bzrdir.format_registry.make_bzrdir,
1300
1321
                            value_switches=True, title='Repository format'),
1301
 
                     Option('trees',
1302
 
                             help='Allows branches in repository to have'
1303
 
                             ' a working tree')]
 
1322
                     Option('no-trees',
 
1323
                             help='Branches in the repository will default to'
 
1324
                                  ' not having a working tree'),
 
1325
                    ]
1304
1326
    aliases = ["init-repo"]
1305
 
    def run(self, location, format=None, trees=False):
 
1327
 
 
1328
    def run(self, location, format=None, no_trees=False):
1306
1329
        if format is None:
1307
1330
            format = bzrdir.format_registry.make_bzrdir('default')
1308
1331
 
1317
1340
 
1318
1341
        newdir = format.initialize_on_transport(to_transport)
1319
1342
        repo = newdir.create_repository(shared=True)
1320
 
        repo.set_make_working_trees(trees)
 
1343
        repo.set_make_working_trees(not no_trees)
1321
1344
 
1322
1345
 
1323
1346
class cmd_diff(Command):
1336
1359
            Difference between the working tree and revision 1
1337
1360
        bzr diff -r1..2
1338
1361
            Difference between revision 2 and revision 1
1339
 
        bzr diff --diff-prefix old/:new/
 
1362
        bzr diff --prefix old/:new/
1340
1363
            Same as 'bzr diff' but prefix paths with old/ and new/
1341
1364
        bzr diff bzr.mine bzr.dev
1342
1365
            Show the differences between the two working trees
1354
1377
 
1355
1378
    # TODO: This probably handles non-Unix newlines poorly.
1356
1379
 
 
1380
    _see_also = ['status']
1357
1381
    takes_args = ['file*']
1358
1382
    takes_options = ['revision', 'diff-options',
1359
1383
        Option('prefix', type=str,
1360
1384
               short_name='p',
1361
1385
               help='Set prefixes to added to old and new filenames, as '
1362
 
                    'two values separated by a colon.'),
 
1386
                    'two values separated by a colon. (eg "old/:new/")'),
1363
1387
        ]
1364
1388
    aliases = ['di', 'dif']
1365
1389
    encoding_type = 'exact'
1379
1403
        elif ':' in prefix:
1380
1404
            old_label, new_label = prefix.split(":")
1381
1405
        else:
1382
 
            raise BzrCommandError(
1383
 
                "--prefix expects two values separated by a colon")
 
1406
            raise errors.BzrCommandError(
 
1407
                '--prefix expects two values separated by a colon'
 
1408
                ' (eg "old/:new/")')
1384
1409
 
1385
1410
        if revision and len(revision) > 2:
1386
1411
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
1387
1412
                                         ' one or two revision specifiers')
1388
 
        
 
1413
 
1389
1414
        try:
1390
1415
            tree1, file_list = internal_tree_files(file_list)
1391
1416
            tree2 = None
1438
1463
    # directories with readdir, rather than stating each one.  Same
1439
1464
    # level of effort but possibly much less IO.  (Or possibly not,
1440
1465
    # if the directories are very large...)
 
1466
    _see_also = ['status', 'ls']
1441
1467
    takes_options = ['show-ids']
1442
1468
 
1443
1469
    @display_command
1463
1489
 
1464
1490
class cmd_modified(Command):
1465
1491
    """List files modified in working tree.
1466
 
 
1467
 
    See also: "bzr status".
1468
1492
    """
1469
1493
 
1470
1494
    hidden = True
 
1495
    _see_also = ['status', 'ls']
1471
1496
 
1472
1497
    @display_command
1473
1498
    def run(self):
1479
1504
 
1480
1505
class cmd_added(Command):
1481
1506
    """List files added in working tree.
1482
 
 
1483
 
    See also: "bzr status".
1484
1507
    """
1485
1508
 
1486
1509
    hidden = True
 
1510
    _see_also = ['status', 'ls']
1487
1511
 
1488
1512
    @display_command
1489
1513
    def run(self):
1515
1539
 
1516
1540
    The root is the nearest enclosing directory with a .bzr control
1517
1541
    directory."""
 
1542
 
1518
1543
    takes_args = ['filename?']
1519
1544
    @display_command
1520
1545
    def run(self, filename=None):
1682
1707
    """List files in a tree.
1683
1708
    """
1684
1709
 
 
1710
    _see_also = ['status', 'cat']
1685
1711
    takes_args = ['path?']
1686
1712
    # TODO: Take a revision or remote path and list that tree instead.
1687
1713
    takes_options = ['verbose', 'revision',
1771
1797
 
1772
1798
class cmd_unknowns(Command):
1773
1799
    """List unknown files.
1774
 
 
1775
 
    See also: "bzr ls --unknown".
1776
1800
    """
1777
1801
 
1778
1802
    hidden = True
 
1803
    _see_also = ['ls']
1779
1804
 
1780
1805
    @display_command
1781
1806
    def run(self):
1816
1841
        bzr ignore 'lib/**/*.o'
1817
1842
        bzr ignore 'RE:lib/.*\.o'
1818
1843
    """
 
1844
 
 
1845
    _see_also = ['status', 'ignored']
1819
1846
    takes_args = ['name_pattern*']
1820
1847
    takes_options = [
1821
1848
                     Option('old-default-rules',
1871
1898
 
1872
1899
class cmd_ignored(Command):
1873
1900
    """List ignored files and the patterns that matched them.
 
1901
    """
1874
1902
 
1875
 
    See also: bzr ignore"""
 
1903
    _see_also = ['ignore']
1876
1904
    @display_command
1877
1905
    def run(self):
1878
1906
        tree = WorkingTree.open_containing(u'.')[0]
1908
1936
 
1909
1937
 
1910
1938
class cmd_export(Command):
1911
 
    """Export past revision to destination directory.
 
1939
    """Export current or past revision to a destination directory or archive.
1912
1940
 
1913
1941
    If no revision is specified this exports the last committed revision.
1914
1942
 
1916
1944
    given, try to find the format with the extension. If no extension
1917
1945
    is found exports to a directory (equivalent to --format=dir).
1918
1946
 
1919
 
    Root may be the top directory for tar, tgz and tbz2 formats. If none
1920
 
    is given, the top directory will be the root name of the file.
1921
 
 
1922
 
    If branch is omitted then the branch containing the CWD will be used.
1923
 
 
1924
 
    Note: export of tree with non-ascii filenames to zip is not supported.
 
1947
    If root is supplied, it will be used as the root directory inside
 
1948
    container formats (tar, zip, etc). If it is not supplied it will default
 
1949
    to the exported filename. The root option has no effect for 'dir' format.
 
1950
 
 
1951
    If branch is omitted then the branch containing the current working
 
1952
    directory will be used.
 
1953
 
 
1954
    Note: Export of tree with non-ASCII filenames to zip is not supported.
1925
1955
 
1926
1956
     Supported formats       Autodetected by extension
1927
1957
     -----------------       -------------------------
1957
1987
 
1958
1988
 
1959
1989
class cmd_cat(Command):
1960
 
    """Write a file's text from a previous revision."""
1961
 
 
 
1990
    """Write the contents of a file as of a given revision to standard output.
 
1991
 
 
1992
    If no revision is nominated, the last revision is used.
 
1993
 
 
1994
    Note: Take care to redirect standard output when using this command on a
 
1995
    binary file. 
 
1996
    """
 
1997
 
 
1998
    _see_also = ['ls']
1962
1999
    takes_options = ['revision', 'name-from-revision']
1963
2000
    takes_args = ['filename']
1964
2001
    encoding_type = 'exact'
2023
2060
    within it is committed.
2024
2061
 
2025
2062
    A selected-file commit may fail in some cases where the committed
2026
 
    tree would be invalid, such as trying to commit a file in a
2027
 
    newly-added directory that is not itself committed.
 
2063
    tree would be invalid. Consider::
 
2064
 
 
2065
      bzr init foo
 
2066
      mkdir foo/bar
 
2067
      bzr add foo/bar
 
2068
      bzr commit foo -m "committing foo"
 
2069
      bzr mv foo/bar foo/baz
 
2070
      mkdir foo/bar
 
2071
      bzr add foo/bar
 
2072
      bzr commit foo/bar -m "committing bar but not baz"
 
2073
 
 
2074
    In the example above, the last commit will fail by design. This gives
 
2075
    the user the opportunity to decide whether they want to commit the
 
2076
    rename at the same time, separately first, or not at all. (As a general
 
2077
    rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
 
2078
 
 
2079
    Note: A selected-file commit after a merge is not yet supported.
2028
2080
    """
2029
2081
    # TODO: Run hooks on tree to-be-committed, and after commit.
2030
2082
 
2035
2087
 
2036
2088
    # XXX: verbose currently does nothing
2037
2089
 
 
2090
    _see_also = ['uncommit']
2038
2091
    takes_args = ['selected*']
2039
2092
    takes_options = ['message', 'verbose', 
2040
2093
                     Option('unchanged',
2132
2185
    This command checks various invariants about the branch storage to
2133
2186
    detect data corruption or bzr bugs.
2134
2187
    """
 
2188
 
 
2189
    _see_also = ['reconcile']
2135
2190
    takes_args = ['branch?']
2136
2191
    takes_options = ['verbose']
2137
2192
 
2152
2207
    this command. When the default format has changed you may also be warned
2153
2208
    during other operations to upgrade.
2154
2209
    """
 
2210
 
 
2211
    _see_also = ['check']
2155
2212
    takes_args = ['url?']
2156
2213
    takes_options = [
2157
2214
                    RegistryOption('format',
2220
2277
    If unset, the tree root directory name is used as the nickname
2221
2278
    To print the current nickname, execute with no argument.  
2222
2279
    """
 
2280
 
 
2281
    _see_also = ['info']
2223
2282
    takes_args = ['nickname?']
2224
2283
    def run(self, nickname=None):
2225
2284
        branch = Branch.open_containing(u'.')[0]
2230
2289
 
2231
2290
    @display_command
2232
2291
    def printme(self, branch):
2233
 
        print branch.nick 
 
2292
        print branch.nick
2234
2293
 
2235
2294
 
2236
2295
class cmd_selftest(Command):
2289
2348
    hidden = True
2290
2349
    takes_args = ['testspecs*']
2291
2350
    takes_options = ['verbose',
2292
 
                     Option('one', help='stop when one test fails'),
2293
 
                     Option('keep-output', 
 
2351
                     Option('one',
 
2352
                             help='stop when one test fails',
 
2353
                             short_name='1',
 
2354
                             ),
 
2355
                     Option('keep-output',
2294
2356
                            help='keep output directories when tests fail'),
2295
 
                     Option('transport', 
 
2357
                     Option('transport',
2296
2358
                            help='Use a different transport by default '
2297
2359
                                 'throughout the test suite.',
2298
2360
                            type=get_transport_type),
2299
 
                     Option('benchmark', help='run the bzr bencharks.'),
 
2361
                     Option('benchmark', help='run the bzr benchmarks.'),
2300
2362
                     Option('lsprof-timed',
2301
2363
                            help='generate lsprof output for benchmarked'
2302
2364
                                 ' sections of code.'),
2308
2370
                                 ' without running tests'),
2309
2371
                     Option('first',
2310
2372
                            help='run all tests, but run specified tests first',
 
2373
                            short_name='f',
2311
2374
                            ),
2312
2375
                     Option('numbered-dirs',
2313
2376
                            help='use numbered dirs for TestCaseInTempDir'),
2448
2511
 
2449
2512
    Examples:
2450
2513
 
2451
 
    To merge the latest revision from bzr.dev
2452
 
    bzr merge ../bzr.dev
 
2514
    To merge the latest revision from bzr.dev:
 
2515
        bzr merge ../bzr.dev
2453
2516
 
2454
 
    To merge changes up to and including revision 82 from bzr.dev
2455
 
    bzr merge -r 82 ../bzr.dev
 
2517
    To merge changes up to and including revision 82 from bzr.dev:
 
2518
        bzr merge -r 82 ../bzr.dev
2456
2519
 
2457
2520
    To merge the changes introduced by 82, without previous changes:
2458
 
    bzr merge -r 81..82 ../bzr.dev
 
2521
        bzr merge -r 81..82 ../bzr.dev
2459
2522
    
2460
2523
    merge refuses to run if there are any uncommitted changes, unless
2461
2524
    --force is given.
 
2525
    """
2462
2526
 
2463
 
    The following merge types are available:
2464
 
    """
 
2527
    _see_also = ['update', 'remerge']
2465
2528
    takes_args = ['branch?']
2466
2529
    takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2467
2530
        Option('show-base', help="Show base revision text in "
2486
2549
            directory=None,
2487
2550
            ):
2488
2551
        from bzrlib.tag import _merge_tags_if_possible
 
2552
        other_revision_id = None
2489
2553
        if merge_type is None:
2490
2554
            merge_type = _mod_merge.Merge3Merger
2491
2555
 
2498
2562
        #      Either the merge helper code should be updated to take a tree,
2499
2563
        #      (What about tree.merge_from_branch?)
2500
2564
        tree = WorkingTree.open_containing(directory)[0]
2501
 
        change_reporter = delta.ChangeReporter(
 
2565
        change_reporter = delta._ChangeReporter(
2502
2566
            unversioned_filter=tree.is_ignored)
2503
2567
 
2504
2568
        if branch is not None:
2505
2569
            try:
2506
 
                reader = bundle.read_bundle_from_url(branch)
 
2570
                mergeable = bundle.read_mergeable_from_url(
 
2571
                    branch)
2507
2572
            except errors.NotABundle:
2508
2573
                pass # Continue on considering this url a Branch
2509
2574
            else:
2510
 
                conflicts = merge_bundle(reader, tree, not force, merge_type,
2511
 
                                         reprocess, show_base, change_reporter)
2512
 
                if conflicts == 0:
2513
 
                    return 0
2514
 
                else:
2515
 
                    return 1
 
2575
                if revision is not None:
 
2576
                    raise errors.BzrCommandError(
 
2577
                        'Cannot use -r with merge directives or bundles')
 
2578
                other_revision_id = mergeable.install_revisions(
 
2579
                    tree.branch.repository)
 
2580
                revision = [RevisionSpec.from_string(
 
2581
                    'revid:' + other_revision_id)]
2516
2582
 
2517
2583
        if revision is None \
2518
2584
                or len(revision) < 1 or revision[0].needs_branch():
2533
2599
            branch = revision[0].get_branch() or branch
2534
2600
            if len(revision) == 1:
2535
2601
                base = [None, None]
2536
 
                other_branch, path = Branch.open_containing(branch)
2537
 
                revno = revision[0].in_history(other_branch).revno
2538
 
                other = [branch, revno]
 
2602
                if other_revision_id is not None:
 
2603
                    other_branch = None
 
2604
                    path = ""
 
2605
                    other = None
 
2606
                else:
 
2607
                    other_branch, path = Branch.open_containing(branch)
 
2608
                    revno = revision[0].in_history(other_branch).revno
 
2609
                    other = [branch, revno]
2539
2610
            else:
2540
2611
                assert len(revision) == 2
2541
2612
                if None in revision:
2551
2622
                base = [branch, revision[0].in_history(base_branch).revno]
2552
2623
                other = [branch1, revision[1].in_history(other_branch).revno]
2553
2624
 
2554
 
        if tree.branch.get_parent() is None or remember:
 
2625
        if ((tree.branch.get_parent() is None or remember) and
 
2626
            other_branch is not None):
2555
2627
            tree.branch.set_parent(other_branch.base)
2556
2628
 
2557
2629
        # pull tags now... it's a bit inconsistent to do it ahead of copying
2558
2630
        # the history but that's done inside the merge code
2559
 
        _merge_tags_if_possible(other_branch, tree.branch)
 
2631
        if other_branch is not None:
 
2632
            _merge_tags_if_possible(other_branch, tree.branch)
2560
2633
 
2561
2634
        if path != "":
2562
2635
            interesting_files = [path]
2566
2639
        try:
2567
2640
            try:
2568
2641
                conflict_count = _merge_helper(
2569
 
                    other, base, check_clean=(not force),
 
2642
                    other, base, other_rev_id=other_revision_id,
 
2643
                    check_clean=(not force),
2570
2644
                    merge_type=merge_type,
2571
2645
                    reprocess=reprocess,
2572
2646
                    show_base=show_base,
2618
2692
    pending merge, and it lets you specify particular files.
2619
2693
 
2620
2694
    Examples:
 
2695
 
2621
2696
    $ bzr remerge --show-base
2622
2697
        Re-do the merge of all conflicted files, and show the base text in
2623
2698
        conflict regions, in addition to the usual THIS and OTHER texts.
2625
2700
    $ bzr remerge --merge-type weave --reprocess foobar
2626
2701
        Re-do the merge of "foobar", using the weave merge algorithm, with
2627
2702
        additional processing to reduce the size of conflict regions.
2628
 
    
2629
 
    The following merge types are available:"""
 
2703
    """
2630
2704
    takes_args = ['file*']
2631
2705
    takes_options = ['merge-type', 'reprocess',
2632
2706
                     Option('show-base', help="Show base revision text in "
2716
2790
    name.  If you name a directory, all the contents of that directory will be
2717
2791
    reverted.
2718
2792
    """
 
2793
 
 
2794
    _see_also = ['cat', 'export']
2719
2795
    takes_options = ['revision', 'no-backup']
2720
2796
    takes_args = ['file*']
2721
 
    aliases = ['merge-revert']
2722
2797
 
2723
2798
    def run(self, revision=None, no_backup=False, file_list=None):
2724
2799
        if file_list is not None:
2756
2831
 
2757
2832
class cmd_help(Command):
2758
2833
    """Show help on a command or other topic.
 
2834
    """
2759
2835
 
2760
 
    For a list of all available commands, say 'bzr help commands'.
2761
 
    """
 
2836
    _see_also = ['topics']
2762
2837
    takes_options = [Option('long', 'show help on all commands')]
2763
2838
    takes_args = ['topic?']
2764
2839
    aliases = ['?', '--help', '-?', '-h']
2805
2880
 
2806
2881
    OTHER_BRANCH may be local or remote.
2807
2882
    """
 
2883
 
 
2884
    _see_also = ['merge', 'pull']
2808
2885
    takes_args = ['other_branch?']
2809
2886
    takes_options = [Option('reverse', 'Reverse the order of revisions'),
2810
2887
                     Option('mine-only', 
2907
2984
 
2908
2985
class cmd_testament(Command):
2909
2986
    """Show testament (signing-form) of a revision."""
2910
 
    takes_options = ['revision', 
 
2987
    takes_options = ['revision',
2911
2988
                     Option('long', help='Produce long-format testament'), 
2912
2989
                     Option('strict', help='Produce a strict-format'
2913
2990
                            ' testament')]
3023
3100
 
3024
3101
    Once converted into a checkout, commits must succeed on the master branch
3025
3102
    before they will be applied to the local branch.
3026
 
 
3027
 
    See "help checkouts" for more information on checkouts.
3028
3103
    """
3029
3104
 
 
3105
    _see_also = ['checkouts', 'unbind']
3030
3106
    takes_args = ['location?']
3031
3107
    takes_options = []
3032
3108
 
3055
3131
 
3056
3132
    After unbinding, the local branch is considered independent and subsequent
3057
3133
    commits will be local only.
3058
 
 
3059
 
    See "help checkouts" for more information on checkouts.
3060
3134
    """
3061
3135
 
 
3136
    _see_also = ['checkouts', 'bind']
3062
3137
    takes_args = []
3063
3138
    takes_options = []
3064
3139
 
3083
3158
    # unreferenced information in 'branch-as-repository' branches.
3084
3159
    # TODO: jam 20060108 Add the ability for uncommit to remove unreferenced
3085
3160
    # information in shared branches as well.
 
3161
    _see_also = ['commit']
3086
3162
    takes_options = ['verbose', 'revision',
3087
3163
                    Option('dry-run', help='Don\'t actually make changes'),
3088
3164
                    Option('force', help='Say yes to all questions.')]
3212
3288
        ]
3213
3289
 
3214
3290
    def run(self, port=None, inet=False, directory=None, allow_writes=False):
3215
 
        from bzrlib.transport import smart
 
3291
        from bzrlib.smart import medium, server
3216
3292
        from bzrlib.transport import get_transport
 
3293
        from bzrlib.transport.chroot import ChrootServer
 
3294
        from bzrlib.transport.remote import BZR_DEFAULT_PORT
3217
3295
        if directory is None:
3218
3296
            directory = os.getcwd()
3219
3297
        url = urlutils.local_path_to_url(directory)
3220
3298
        if not allow_writes:
3221
3299
            url = 'readonly+' + url
3222
 
        t = get_transport(url)
 
3300
        chroot_server = ChrootServer(get_transport(url))
 
3301
        chroot_server.setUp()
 
3302
        t = get_transport(chroot_server.get_url())
3223
3303
        if inet:
3224
 
            server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
 
3304
            smart_server = medium.SmartServerPipeStreamMedium(
 
3305
                sys.stdin, sys.stdout, t)
3225
3306
        else:
3226
3307
            if port is None:
3227
 
                port = smart.BZR_DEFAULT_PORT
 
3308
                port = BZR_DEFAULT_PORT
3228
3309
                host = '127.0.0.1'
3229
3310
            else:
3230
3311
                if ':' in port:
3232
3313
                else:
3233
3314
                    host = '127.0.0.1'
3234
3315
                port = int(port)
3235
 
            server = smart.SmartTCPServer(t, host=host, port=port)
3236
 
            print 'listening on port: ', server.port
 
3316
            smart_server = server.SmartTCPServer(t, host=host, port=port)
 
3317
            print 'listening on port: ', smart_server.port
3237
3318
            sys.stdout.flush()
3238
 
        server.serve()
 
3319
        # for the duration of this server, no UI output is permitted.
 
3320
        # note that this may cause problems with blackbox tests. This should
 
3321
        # be changed with care though, as we dont want to use bandwidth sending
 
3322
        # progress over stderr to smart server clients!
 
3323
        old_factory = ui.ui_factory
 
3324
        try:
 
3325
            ui.ui_factory = ui.SilentUIFactory()
 
3326
            smart_server.serve()
 
3327
        finally:
 
3328
            ui.ui_factory = old_factory
 
3329
 
3239
3330
 
3240
3331
class cmd_join(Command):
3241
3332
    """Combine a subtree into its containing tree.
3242
3333
    
3243
 
    This is marked as a merge of the subtree into the containing tree, and all
3244
 
    history is preserved.
 
3334
    This command is for experimental use only.  It requires the target tree
 
3335
    to be in dirstate-with-subtree format, which cannot be converted into
 
3336
    earlier formats.
 
3337
 
 
3338
    The TREE argument should be an independent tree, inside another tree, but
 
3339
    not part of it.  (Such trees can be produced by "bzr split", but also by
 
3340
    running "bzr branch" with the target inside a tree.)
 
3341
 
 
3342
    The result is a combined tree, with the subtree no longer an independant
 
3343
    part.  This is marked as a merge of the subtree into the containing tree,
 
3344
    and all history is preserved.
 
3345
 
 
3346
    If --reference is specified, the subtree retains its independence.  It can
 
3347
    be branched by itself, and can be part of multiple projects at the same
 
3348
    time.  But operations performed in the containing tree, such as commit
 
3349
    and merge, will recurse into the subtree.
3245
3350
    """
3246
3351
 
 
3352
    _see_also = ['split']
3247
3353
    takes_args = ['tree']
3248
3354
    takes_options = [Option('reference', 'join by reference')]
 
3355
    hidden = True
3249
3356
 
3250
3357
    def run(self, tree, reference=False):
3251
3358
        sub_tree = WorkingTree.open(tree)
3275
3382
 
3276
3383
class cmd_split(Command):
3277
3384
    """Split a tree into two trees.
 
3385
 
 
3386
    This command is for experimental use only.  It requires the target tree
 
3387
    to be in dirstate-with-subtree format, which cannot be converted into
 
3388
    earlier formats.
 
3389
 
 
3390
    The TREE argument should be a subdirectory of a working tree.  That
 
3391
    subdirectory will be converted into an independent tree, with its own
 
3392
    branch.  Commits in the top-level tree will not apply to the new subtree.
 
3393
    If you want that behavior, do "bzr join --reference TREE".
3278
3394
    """
3279
3395
 
 
3396
    _see_also = ['join']
3280
3397
    takes_args = ['tree']
3281
3398
 
 
3399
    hidden = True
 
3400
 
3282
3401
    def run(self, tree):
3283
3402
        containing_tree, subdir = WorkingTree.open_containing(tree)
3284
3403
        sub_id = containing_tree.path2id(subdir)
3291
3410
 
3292
3411
 
3293
3412
 
 
3413
class cmd_merge_directive(Command):
 
3414
    """Generate a merge directive for auto-merge tools.
 
3415
 
 
3416
    A directive requests a merge to be performed, and also provides all the
 
3417
    information necessary to do so.  This means it must either include a
 
3418
    revision bundle, or the location of a branch containing the desired
 
3419
    revision.
 
3420
 
 
3421
    A submit branch (the location to merge into) must be supplied the first
 
3422
    time the command is issued.  After it has been supplied once, it will
 
3423
    be remembered as the default.
 
3424
 
 
3425
    A public branch is optional if a revision bundle is supplied, but required
 
3426
    if --diff or --plain is specified.  It will be remembered as the default
 
3427
    after the first use.
 
3428
    """
 
3429
 
 
3430
    takes_args = ['submit_branch?', 'public_branch?']
 
3431
 
 
3432
    takes_options = [
 
3433
        RegistryOption.from_kwargs('patch-type',
 
3434
            'The type of patch to include in the directive',
 
3435
            title='Patch type', value_switches=True, enum_switch=False,
 
3436
            bundle='Bazaar revision bundle (default)',
 
3437
            diff='Normal unified diff',
 
3438
            plain='No patch, just directive'),
 
3439
        Option('sign', help='GPG-sign the directive'), 'revision',
 
3440
        Option('mail-to', type=str,
 
3441
            help='Instead of printing the directive, email to this address'),
 
3442
        Option('message', type=str, short_name='m',
 
3443
            help='Message to use when committing this merge')
 
3444
        ]
 
3445
 
 
3446
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
 
3447
            sign=False, revision=None, mail_to=None, message=None):
 
3448
        if patch_type == 'plain':
 
3449
            patch_type = None
 
3450
        branch = Branch.open('.')
 
3451
        stored_submit_branch = branch.get_submit_branch()
 
3452
        if submit_branch is None:
 
3453
            submit_branch = stored_submit_branch
 
3454
        else:
 
3455
            if stored_submit_branch is None:
 
3456
                branch.set_submit_branch(submit_branch)
 
3457
        if submit_branch is None:
 
3458
            submit_branch = branch.get_parent()
 
3459
        if submit_branch is None:
 
3460
            raise errors.BzrCommandError('No submit branch specified or known')
 
3461
 
 
3462
        stored_public_branch = branch.get_public_branch()
 
3463
        if public_branch is None:
 
3464
            public_branch = stored_public_branch
 
3465
        elif stored_public_branch is None:
 
3466
            branch.set_public_branch(public_branch)
 
3467
        if patch_type != "bundle" and public_branch is None:
 
3468
            raise errors.BzrCommandError('No public branch specified or'
 
3469
                                         ' known')
 
3470
        if revision is not None:
 
3471
            if len(revision) != 1:
 
3472
                raise errors.BzrCommandError('bzr merge-directive takes '
 
3473
                    'exactly one revision identifier')
 
3474
            else:
 
3475
                revision_id = revision[0].in_history(branch).rev_id
 
3476
        else:
 
3477
            revision_id = branch.last_revision()
 
3478
        directive = merge_directive.MergeDirective.from_objects(
 
3479
            branch.repository, revision_id, time.time(),
 
3480
            osutils.local_time_offset(), submit_branch,
 
3481
            public_branch=public_branch, patch_type=patch_type,
 
3482
            message=message)
 
3483
        if mail_to is None:
 
3484
            if sign:
 
3485
                self.outf.write(directive.to_signed(branch))
 
3486
            else:
 
3487
                self.outf.writelines(directive.to_lines())
 
3488
        else:
 
3489
            message = directive.to_email(mail_to, branch, sign)
 
3490
            s = smtplib.SMTP()
 
3491
            server = branch.get_config().get_user_option('smtp_server')
 
3492
            if not server:
 
3493
                server = 'localhost'
 
3494
            s.connect(server)
 
3495
            s.sendmail(message['From'], message['To'], message.as_string())
 
3496
 
 
3497
 
3294
3498
class cmd_tag(Command):
3295
3499
    """Create a tag naming a revision.
3296
3500
    
3305
3509
    --force, in which case the tag is moved to point to the new revision.
3306
3510
    """
3307
3511
 
 
3512
    _see_also = ['commit', 'tags']
3308
3513
    takes_args = ['tag_name']
3309
3514
    takes_options = [
3310
3515
        Option('delete',
3356
3561
    This tag shows a table of tag names and the revisions they reference.
3357
3562
    """
3358
3563
 
 
3564
    _see_also = ['tag']
3359
3565
    takes_options = [
3360
3566
        Option('directory',
3361
3567
            help='Branch whose tags should be displayed',
3381
3587
                  file_list=None, show_base=False, reprocess=False,
3382
3588
                  pull=False,
3383
3589
                  pb=DummyProgress(),
3384
 
                  change_reporter=None):
 
3590
                  change_reporter=None,
 
3591
                  other_rev_id=None):
3385
3592
    """Merge changes into a tree.
3386
3593
 
3387
3594
    base_revision
3437
3644
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3438
3645
        merger.pp.next_phase()
3439
3646
        merger.check_basis(check_clean)
3440
 
        merger.set_other(other_revision)
 
3647
        if other_rev_id is not None:
 
3648
            merger.set_other_revision(other_rev_id, this_tree.branch)
 
3649
        else:
 
3650
            merger.set_other(other_revision)
3441
3651
        merger.pp.next_phase()
3442
3652
        merger.set_base(base_revision)
3443
3653
        if merger.base_rev_id == merger.other_rev_id: