/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: Vincent Ladeuil
  • Date: 2011-07-06 08:58:15 UTC
  • mfrom: (5609.48.2 2.3)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706085815-6leauod52jq2u43d
MergingĀ inĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
 
import codecs
24
23
import cStringIO
25
24
import sys
26
25
import time
33
32
    bzrdir,
34
33
    directory_service,
35
34
    delta,
36
 
    config,
 
35
    config as _mod_config,
37
36
    errors,
38
37
    globbing,
39
38
    hooks,
75
74
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
76
75
 
77
76
 
 
77
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
78
78
def tree_files(file_list, default_branch=u'.', canonicalize=True,
79
79
    apply_view=True):
80
 
    try:
81
 
        return internal_tree_files(file_list, default_branch, canonicalize,
82
 
            apply_view)
83
 
    except errors.FileInWrongBranch, e:
84
 
        raise errors.BzrCommandError("%s is not in the same branch as %s" %
85
 
                                     (e.path, file_list[0]))
 
80
    return internal_tree_files(file_list, default_branch, canonicalize,
 
81
        apply_view)
86
82
 
87
83
 
88
84
def tree_files_for_add(file_list):
152
148
 
153
149
# XXX: Bad function name; should possibly also be a class method of
154
150
# WorkingTree rather than a function.
 
151
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
155
152
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
156
153
    apply_view=True):
157
154
    """Convert command-line paths to a WorkingTree and relative paths.
158
155
 
 
156
    Deprecated: use WorkingTree.open_containing_paths instead.
 
157
 
159
158
    This is typically used for command-line processors that take one or
160
159
    more filenames, and infer the workingtree that contains them.
161
160
 
171
170
 
172
171
    :return: workingtree, [relative_paths]
173
172
    """
174
 
    if file_list is None or len(file_list) == 0:
175
 
        tree = WorkingTree.open_containing(default_branch)[0]
176
 
        if tree.supports_views() and apply_view:
177
 
            view_files = tree.views.lookup_view()
178
 
            if view_files:
179
 
                file_list = view_files
180
 
                view_str = views.view_display_str(view_files)
181
 
                note("Ignoring files outside view. View is %s" % view_str)
182
 
        return tree, file_list
183
 
    tree = WorkingTree.open_containing(file_list[0])[0]
184
 
    return tree, safe_relpath_files(tree, file_list, canonicalize,
185
 
        apply_view=apply_view)
186
 
 
187
 
 
188
 
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
189
 
    """Convert file_list into a list of relpaths in tree.
190
 
 
191
 
    :param tree: A tree to operate on.
192
 
    :param file_list: A list of user provided paths or None.
193
 
    :param apply_view: if True and a view is set, apply it or check that
194
 
        specified files are within it
195
 
    :return: A list of relative paths.
196
 
    :raises errors.PathNotChild: When a provided path is in a different tree
197
 
        than tree.
198
 
    """
199
 
    if file_list is None:
200
 
        return None
201
 
    if tree.supports_views() and apply_view:
202
 
        view_files = tree.views.lookup_view()
203
 
    else:
204
 
        view_files = []
205
 
    new_list = []
206
 
    # tree.relpath exists as a "thunk" to osutils, but canonical_relpath
207
 
    # doesn't - fix that up here before we enter the loop.
208
 
    if canonicalize:
209
 
        fixer = lambda p: osutils.canonical_relpath(tree.basedir, p)
210
 
    else:
211
 
        fixer = tree.relpath
212
 
    for filename in file_list:
213
 
        try:
214
 
            relpath = fixer(osutils.dereference_path(filename))
215
 
            if  view_files and not osutils.is_inside_any(view_files, relpath):
216
 
                raise errors.FileOutsideView(filename, view_files)
217
 
            new_list.append(relpath)
218
 
        except errors.PathNotChild:
219
 
            raise errors.FileInWrongBranch(tree.branch, filename)
220
 
    return new_list
 
173
    return WorkingTree.open_containing_paths(
 
174
        file_list, default_directory='.',
 
175
        canonicalize=True,
 
176
        apply_view=True)
221
177
 
222
178
 
223
179
def _get_view_info_for_change_reporter(tree):
294
250
    To skip the display of pending merge information altogether, use
295
251
    the no-pending option or specify a file/directory.
296
252
 
297
 
    If a revision argument is given, the status is calculated against
298
 
    that revision, or between two revisions if two are provided.
 
253
    To compare the working directory to a specific revision, pass a
 
254
    single revision to the revision argument.
 
255
 
 
256
    To see which files have changed in a specific revision, or between
 
257
    two revisions, pass a revision range to the revision argument.
 
258
    This will produce the same results as calling 'bzr diff --summarize'.
299
259
    """
300
260
 
301
261
    # TODO: --no-recurse, --recurse options
323
283
            raise errors.BzrCommandError('bzr status --revision takes exactly'
324
284
                                         ' one or two revision specifiers')
325
285
 
326
 
        tree, relfile_list = tree_files(file_list)
 
286
        tree, relfile_list = WorkingTree.open_containing_paths(file_list)
327
287
        # Avoid asking for specific files when that is not needed.
328
288
        if relfile_list == ['']:
329
289
            relfile_list = None
761
721
            raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
762
722
 
763
723
        revision = _get_one_revision('inventory', revision)
764
 
        work_tree, file_list = tree_files(file_list)
 
724
        work_tree, file_list = WorkingTree.open_containing_paths(file_list)
765
725
        self.add_cleanup(work_tree.lock_read().unlock)
766
726
        if revision is not None:
767
727
            tree = revision.as_tree(work_tree.branch)
832
792
            names_list = []
833
793
        if len(names_list) < 2:
834
794
            raise errors.BzrCommandError("missing file argument")
835
 
        tree, rel_names = tree_files(names_list, canonicalize=False)
 
795
        tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
836
796
        self.add_cleanup(tree.lock_tree_write().unlock)
837
797
        self._run(tree, names_list, rel_names, after)
838
798
 
843
803
        if after:
844
804
            raise errors.BzrCommandError('--after cannot be specified with'
845
805
                                         ' --auto.')
846
 
        work_tree, file_list = tree_files(names_list, default_branch='.')
 
806
        work_tree, file_list = WorkingTree.open_containing_paths(
 
807
            names_list, default_directory='.')
847
808
        self.add_cleanup(work_tree.lock_tree_write().unlock)
848
809
        rename_map.RenameMap.guess_renames(work_tree, dry_run)
849
810
 
966
927
                 "branch.  Local pulls are not applied to "
967
928
                 "the master branch."
968
929
            ),
 
930
        Option('show-base',
 
931
            help="Show base revision text in conflicts.")
969
932
        ]
970
933
    takes_args = ['location?']
971
934
    encoding_type = 'replace'
972
935
 
973
936
    def run(self, location=None, remember=False, overwrite=False,
974
937
            revision=None, verbose=False,
975
 
            directory=None, local=False):
 
938
            directory=None, local=False,
 
939
            show_base=False):
976
940
        # FIXME: too much stuff is in the command class
977
941
        revision_id = None
978
942
        mergeable = None
987
951
            branch_to = Branch.open_containing(directory)[0]
988
952
            self.add_cleanup(branch_to.lock_write().unlock)
989
953
 
 
954
        if tree_to is None and show_base:
 
955
            raise errors.BzrCommandError("Need working tree for --show-base.")
 
956
 
990
957
        if local and not branch_to.get_bound_location():
991
958
            raise errors.LocalRequiresBoundBranch()
992
959
 
1037
1004
                view_info=view_info)
1038
1005
            result = tree_to.pull(
1039
1006
                branch_from, overwrite, revision_id, change_reporter,
1040
 
                possible_transports=possible_transports, local=local)
 
1007
                possible_transports=possible_transports, local=local,
 
1008
                show_base=show_base)
1041
1009
        else:
1042
1010
            result = branch_to.pull(
1043
1011
                branch_from, overwrite, revision_id, local=local)
1099
1067
        Option('strict',
1100
1068
               help='Refuse to push if there are uncommitted changes in'
1101
1069
               ' the working tree, --no-strict disables the check.'),
 
1070
        Option('no-tree',
 
1071
               help="Don't populate the working tree, even for protocols"
 
1072
               " that support it."),
1102
1073
        ]
1103
1074
    takes_args = ['location?']
1104
1075
    encoding_type = 'replace'
1106
1077
    def run(self, location=None, remember=False, overwrite=False,
1107
1078
        create_prefix=False, verbose=False, revision=None,
1108
1079
        use_existing_dir=False, directory=None, stacked_on=None,
1109
 
        stacked=False, strict=None):
 
1080
        stacked=False, strict=None, no_tree=False):
1110
1081
        from bzrlib.push import _show_push_branch
1111
1082
 
1112
1083
        if directory is None:
1158
1129
        _show_push_branch(br_from, revision_id, location, self.outf,
1159
1130
            verbose=verbose, overwrite=overwrite, remember=remember,
1160
1131
            stacked_on=stacked_on, create_prefix=create_prefix,
1161
 
            use_existing_dir=use_existing_dir)
 
1132
            use_existing_dir=use_existing_dir, no_tree=no_tree)
1162
1133
 
1163
1134
 
1164
1135
class cmd_branch(Command):
1177
1148
 
1178
1149
    _see_also = ['checkout']
1179
1150
    takes_args = ['from_location', 'to_location?']
1180
 
    takes_options = ['revision', Option('hardlink',
1181
 
        help='Hard-link working tree files where possible.'),
 
1151
    takes_options = ['revision',
 
1152
        Option('hardlink', help='Hard-link working tree files where possible.'),
 
1153
        Option('files-from', type=str,
 
1154
               help="Get file contents from this tree."),
1182
1155
        Option('no-tree',
1183
1156
            help="Create a branch without a working-tree."),
1184
1157
        Option('switch',
1202
1175
 
1203
1176
    def run(self, from_location, to_location=None, revision=None,
1204
1177
            hardlink=False, stacked=False, standalone=False, no_tree=False,
1205
 
            use_existing_dir=False, switch=False, bind=False):
 
1178
            use_existing_dir=False, switch=False, bind=False,
 
1179
            files_from=None):
1206
1180
        from bzrlib import switch as _mod_switch
1207
1181
        from bzrlib.tag import _merge_tags_if_possible
1208
1182
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1209
1183
            from_location)
 
1184
        if not (hardlink or files_from):
 
1185
            # accelerator_tree is usually slower because you have to read N
 
1186
            # files (no readahead, lots of seeks, etc), but allow the user to
 
1187
            # explicitly request it
 
1188
            accelerator_tree = None
 
1189
        if files_from is not None and files_from != from_location:
 
1190
            accelerator_tree = WorkingTree.open(files_from)
1210
1191
        revision = _get_one_revision('branch', revision)
1211
1192
        self.add_cleanup(br_from.lock_read().unlock)
1212
1193
        if revision is not None:
1319
1300
            to_location = branch_location
1320
1301
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1321
1302
            branch_location)
 
1303
        if not (hardlink or files_from):
 
1304
            # accelerator_tree is usually slower because you have to read N
 
1305
            # files (no readahead, lots of seeks, etc), but allow the user to
 
1306
            # explicitly request it
 
1307
            accelerator_tree = None
1322
1308
        revision = _get_one_revision('checkout', revision)
1323
 
        if files_from is not None:
 
1309
        if files_from is not None and files_from != branch_location:
1324
1310
            accelerator_tree = WorkingTree.open(files_from)
1325
1311
        if revision is not None:
1326
1312
            revision_id = revision.as_revision_id(source)
1382
1368
    If you want to discard your local changes, you can just do a
1383
1369
    'bzr revert' instead of 'bzr commit' after the update.
1384
1370
 
 
1371
    If you want to restore a file that has been removed locally, use
 
1372
    'bzr revert' instead of 'bzr update'.
 
1373
 
1385
1374
    If the tree's branch is bound to a master branch, it will also update
1386
1375
    the branch from the master.
1387
1376
    """
1388
1377
 
1389
1378
    _see_also = ['pull', 'working-trees', 'status-flags']
1390
1379
    takes_args = ['dir?']
1391
 
    takes_options = ['revision']
 
1380
    takes_options = ['revision',
 
1381
                     Option('show-base',
 
1382
                            help="Show base revision text in conflicts."),
 
1383
                     ]
1392
1384
    aliases = ['up']
1393
1385
 
1394
 
    def run(self, dir='.', revision=None):
 
1386
    def run(self, dir='.', revision=None, show_base=None):
1395
1387
        if revision is not None and len(revision) != 1:
1396
1388
            raise errors.BzrCommandError(
1397
1389
                        "bzr update --revision takes exactly one revision")
1437
1429
                change_reporter,
1438
1430
                possible_transports=possible_transports,
1439
1431
                revision=revision_id,
1440
 
                old_tip=old_tip)
 
1432
                old_tip=old_tip,
 
1433
                show_base=show_base)
1441
1434
        except errors.NoSuchRevision, e:
1442
1435
            raise errors.BzrCommandError(
1443
1436
                                  "branch has no revision %s\n"
1505
1498
class cmd_remove(Command):
1506
1499
    __doc__ = """Remove files or directories.
1507
1500
 
1508
 
    This makes bzr stop tracking changes to the specified files. bzr will delete
1509
 
    them if they can easily be recovered using revert. If no options or
1510
 
    parameters are given bzr will scan for files that are being tracked by bzr
1511
 
    but missing in your tree and stop tracking them for you.
 
1501
    This makes Bazaar stop tracking changes to the specified files. Bazaar will
 
1502
    delete them if they can easily be recovered using revert otherwise they
 
1503
    will be backed up (adding an extention of the form .~#~). If no options or
 
1504
    parameters are given Bazaar will scan for files that are being tracked by
 
1505
    Bazaar but missing in your tree and stop tracking them for you.
1512
1506
    """
1513
1507
    takes_args = ['file*']
1514
1508
    takes_options = ['verbose',
1516
1510
        RegistryOption.from_kwargs('file-deletion-strategy',
1517
1511
            'The file deletion mode to be used.',
1518
1512
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1519
 
            safe='Only delete files if they can be'
1520
 
                 ' safely recovered (default).',
 
1513
            safe='Backup changed files (default).',
1521
1514
            keep='Delete from bzr but leave the working copy.',
 
1515
            no_backup='Don\'t backup changed files.',
1522
1516
            force='Delete all the specified files, even if they can not be '
1523
 
                'recovered and even if they are non-empty directories.')]
 
1517
                'recovered and even if they are non-empty directories. '
 
1518
                '(deprecated, use no-backup)')]
1524
1519
    aliases = ['rm', 'del']
1525
1520
    encoding_type = 'replace'
1526
1521
 
1527
1522
    def run(self, file_list, verbose=False, new=False,
1528
1523
        file_deletion_strategy='safe'):
1529
 
        tree, file_list = tree_files(file_list)
 
1524
        if file_deletion_strategy == 'force':
 
1525
            note("(The --force option is deprecated, rather use --no-backup "
 
1526
                "in future.)")
 
1527
            file_deletion_strategy = 'no-backup'
 
1528
 
 
1529
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1530
1530
 
1531
1531
        if file_list is not None:
1532
1532
            file_list = [f for f in file_list]
1552
1552
            file_deletion_strategy = 'keep'
1553
1553
        tree.remove(file_list, verbose=verbose, to_file=self.outf,
1554
1554
            keep_files=file_deletion_strategy=='keep',
1555
 
            force=file_deletion_strategy=='force')
 
1555
            force=(file_deletion_strategy=='no-backup'))
1556
1556
 
1557
1557
 
1558
1558
class cmd_file_id(Command):
1620
1620
 
1621
1621
    _see_also = ['check']
1622
1622
    takes_args = ['branch?']
 
1623
    takes_options = [
 
1624
        Option('canonicalize-chks',
 
1625
               help='Make sure CHKs are in canonical form (repairs '
 
1626
                    'bug 522637).',
 
1627
               hidden=True),
 
1628
        ]
1623
1629
 
1624
 
    def run(self, branch="."):
 
1630
    def run(self, branch=".", canonicalize_chks=False):
1625
1631
        from bzrlib.reconcile import reconcile
1626
1632
        dir = bzrdir.BzrDir.open(branch)
1627
 
        reconcile(dir)
 
1633
        reconcile(dir, canonicalize_chks=canonicalize_chks)
1628
1634
 
1629
1635
 
1630
1636
class cmd_revision_history(Command):
1707
1713
                ),
1708
1714
         Option('append-revisions-only',
1709
1715
                help='Never change revnos or the existing log.'
1710
 
                '  Append revisions to it only.')
 
1716
                '  Append revisions to it only.'),
 
1717
         Option('no-tree',
 
1718
                'Create a branch without a working tree.')
1711
1719
         ]
1712
1720
    def run(self, location=None, format=None, append_revisions_only=False,
1713
 
            create_prefix=False):
 
1721
            create_prefix=False, no_tree=False):
1714
1722
        if format is None:
1715
1723
            format = bzrdir.format_registry.make_bzrdir('default')
1716
1724
        if location is None:
1739
1747
        except errors.NotBranchError:
1740
1748
            # really a NotBzrDir error...
1741
1749
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1750
            if no_tree:
 
1751
                force_new_tree = False
 
1752
            else:
 
1753
                force_new_tree = None
1742
1754
            branch = create_branch(to_transport.base, format=format,
1743
 
                                   possible_transports=[to_transport])
 
1755
                                   possible_transports=[to_transport],
 
1756
                                   force_new_tree=force_new_tree)
1744
1757
            a_bzrdir = branch.bzrdir
1745
1758
        else:
1746
1759
            from bzrlib.transport.local import LocalTransport
1750
1763
                        raise errors.BranchExistsWithoutWorkingTree(location)
1751
1764
                raise errors.AlreadyBranchError(location)
1752
1765
            branch = a_bzrdir.create_branch()
1753
 
            a_bzrdir.create_workingtree()
 
1766
            if not no_tree:
 
1767
                a_bzrdir.create_workingtree()
1754
1768
        if append_revisions_only:
1755
1769
            try:
1756
1770
                branch.set_append_revisions_only(True)
1850
1864
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1851
1865
    produces patches suitable for "patch -p1".
1852
1866
 
 
1867
    Note that when using the -r argument with a range of revisions, the
 
1868
    differences are computed between the two specified revisions.  That
 
1869
    is, the command does not show the changes introduced by the first 
 
1870
    revision in the range.  This differs from the interpretation of 
 
1871
    revision ranges used by "bzr log" which includes the first revision
 
1872
    in the range.
 
1873
 
1853
1874
    :Exit values:
1854
1875
        1 - changed
1855
1876
        2 - unrepresentable changes
1873
1894
 
1874
1895
            bzr diff -r1..3 xxx
1875
1896
 
1876
 
        To see the changes introduced in revision X::
 
1897
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1898
 
 
1899
            bzr diff -c2
 
1900
 
 
1901
        To see the changes introduced by revision X::
1877
1902
        
1878
1903
            bzr diff -cX
1879
1904
 
1883
1908
 
1884
1909
            bzr diff -r<chosen_parent>..X
1885
1910
 
1886
 
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1911
        The changes between the current revision and the previous revision
 
1912
        (equivalent to -c-1 and -r-2..-1)
1887
1913
 
1888
 
            bzr diff -c2
 
1914
            bzr diff -r-2..
1889
1915
 
1890
1916
        Show just the differences for file NEWS::
1891
1917
 
1906
1932
        Same as 'bzr diff' but prefix paths with old/ and new/::
1907
1933
 
1908
1934
            bzr diff --prefix old/:new/
 
1935
            
 
1936
        Show the differences using a custom diff program with options::
 
1937
        
 
1938
            bzr diff --using /usr/bin/diff --diff-options -wu
1909
1939
    """
1910
1940
    _see_also = ['status']
1911
1941
    takes_args = ['file*']
2020
2050
    @display_command
2021
2051
    def run(self, null=False, directory=u'.'):
2022
2052
        tree = WorkingTree.open_containing(directory)[0]
 
2053
        self.add_cleanup(tree.lock_read().unlock)
2023
2054
        td = tree.changes_from(tree.basis_tree())
 
2055
        self.cleanup_now()
2024
2056
        for path, id, kind, text_modified, meta_modified in td.modified:
2025
2057
            if null:
2026
2058
                self.outf.write(path + '\0')
2656
2688
    Patterns prefixed with '!!' act as regular ignore patterns, but have
2657
2689
    precedence over the '!' exception patterns.
2658
2690
 
2659
 
    Note: ignore patterns containing shell wildcards must be quoted from
2660
 
    the shell on Unix.
 
2691
    :Notes: 
 
2692
        
 
2693
    * Ignore patterns containing shell wildcards must be quoted from
 
2694
      the shell on Unix.
 
2695
 
 
2696
    * Ignore patterns starting with "#" act as comments in the ignore file.
 
2697
      To ignore patterns that begin with that character, use the "RE:" prefix.
2661
2698
 
2662
2699
    :Examples:
2663
2700
        Ignore the top level Makefile::
2672
2709
 
2673
2710
            bzr ignore "!special.class"
2674
2711
 
 
2712
        Ignore files whose name begins with the "#" character::
 
2713
 
 
2714
            bzr ignore "RE:^#"
 
2715
 
2675
2716
        Ignore .o files under the lib directory::
2676
2717
 
2677
2718
            bzr ignore "lib/**/*.o"
2685
2726
            bzr ignore "RE:(?!debian/).*"
2686
2727
        
2687
2728
        Ignore everything except the "local" toplevel directory,
2688
 
        but always ignore "*~" autosave files, even under local/::
 
2729
        but always ignore ``*~`` autosave files, even under local/::
2689
2730
        
2690
2731
            bzr ignore "*"
2691
2732
            bzr ignore "!./local"
3117
3158
 
3118
3159
        properties = {}
3119
3160
 
3120
 
        tree, selected_list = tree_files(selected_list)
 
3161
        tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3121
3162
        if selected_list == ['']:
3122
3163
            # workaround - commit of root of tree should be exactly the same
3123
3164
            # as just default commit in that tree, and succeed even though
3158
3199
        def get_message(commit_obj):
3159
3200
            """Callback to get commit message"""
3160
3201
            if file:
3161
 
                f = codecs.open(file, 'rt', osutils.get_user_encoding())
 
3202
                f = open(file)
3162
3203
                try:
3163
 
                    my_message = f.read()
 
3204
                    my_message = f.read().decode(osutils.get_user_encoding())
3164
3205
                finally:
3165
3206
                    f.close()
3166
3207
            elif message is not None:
3197
3238
                        reporter=None, verbose=verbose, revprops=properties,
3198
3239
                        authors=author, timestamp=commit_stamp,
3199
3240
                        timezone=offset,
3200
 
                        exclude=safe_relpath_files(tree, exclude))
 
3241
                        exclude=tree.safe_relpath_files(exclude))
3201
3242
        except PointlessCommit:
3202
3243
            raise errors.BzrCommandError("No changes to commit."
3203
3244
                              " Use --unchanged to commit anyhow.")
3287
3328
 
3288
3329
 
3289
3330
class cmd_upgrade(Command):
3290
 
    __doc__ = """Upgrade branch storage to current format.
3291
 
 
3292
 
    The check command or bzr developers may sometimes advise you to run
3293
 
    this command. When the default format has changed you may also be warned
3294
 
    during other operations to upgrade.
 
3331
    __doc__ = """Upgrade a repository, branch or working tree to a newer format.
 
3332
 
 
3333
    When the default format has changed after a major new release of
 
3334
    Bazaar, you may be informed during certain operations that you
 
3335
    should upgrade. Upgrading to a newer format may improve performance
 
3336
    or make new features available. It may however limit interoperability
 
3337
    with older repositories or with older versions of Bazaar.
 
3338
 
 
3339
    If you wish to upgrade to a particular format rather than the
 
3340
    current default, that can be specified using the --format option.
 
3341
    As a consequence, you can use the upgrade command this way to
 
3342
    "downgrade" to an earlier format, though some conversions are
 
3343
    a one way process (e.g. changing from the 1.x default to the
 
3344
    2.x default) so downgrading is not always possible.
 
3345
 
 
3346
    A backup.bzr.~#~ directory is created at the start of the conversion
 
3347
    process (where # is a number). By default, this is left there on
 
3348
    completion. If the conversion fails, delete the new .bzr directory
 
3349
    and rename this one back in its place. Use the --clean option to ask
 
3350
    for the backup.bzr directory to be removed on successful conversion.
 
3351
    Alternatively, you can delete it by hand if everything looks good
 
3352
    afterwards.
 
3353
 
 
3354
    If the location given is a shared repository, dependent branches
 
3355
    are also converted provided the repository converts successfully.
 
3356
    If the conversion of a branch fails, remaining branches are still
 
3357
    tried.
 
3358
 
 
3359
    For more information on upgrades, see the Bazaar Upgrade Guide,
 
3360
    http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3295
3361
    """
3296
3362
 
3297
 
    _see_also = ['check']
 
3363
    _see_also = ['check', 'reconcile', 'formats']
3298
3364
    takes_args = ['url?']
3299
3365
    takes_options = [
3300
 
                    RegistryOption('format',
3301
 
                        help='Upgrade to a specific format.  See "bzr help'
3302
 
                             ' formats" for details.',
3303
 
                        lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3304
 
                        converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3305
 
                        value_switches=True, title='Branch format'),
3306
 
                    ]
 
3366
        RegistryOption('format',
 
3367
            help='Upgrade to a specific format.  See "bzr help'
 
3368
                 ' formats" for details.',
 
3369
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
 
3370
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3371
            value_switches=True, title='Branch format'),
 
3372
        Option('clean',
 
3373
            help='Remove the backup.bzr directory if successful.'),
 
3374
        Option('dry-run',
 
3375
            help="Show what would be done, but don't actually do anything."),
 
3376
    ]
3307
3377
 
3308
 
    def run(self, url='.', format=None):
 
3378
    def run(self, url='.', format=None, clean=False, dry_run=False):
3309
3379
        from bzrlib.upgrade import upgrade
3310
 
        upgrade(url, format)
 
3380
        exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
 
3381
        if exceptions:
 
3382
            if len(exceptions) == 1:
 
3383
                # Compatibility with historical behavior
 
3384
                raise exceptions[0]
 
3385
            else:
 
3386
                return 3
3311
3387
 
3312
3388
 
3313
3389
class cmd_whoami(Command):
3340
3416
                try:
3341
3417
                    c = Branch.open_containing(u'.')[0].get_config()
3342
3418
                except errors.NotBranchError:
3343
 
                    c = config.GlobalConfig()
 
3419
                    c = _mod_config.GlobalConfig()
3344
3420
            else:
3345
3421
                c = Branch.open(directory).get_config()
3346
3422
            if email:
3351
3427
 
3352
3428
        # display a warning if an email address isn't included in the given name.
3353
3429
        try:
3354
 
            config.extract_email_address(name)
 
3430
            _mod_config.extract_email_address(name)
3355
3431
        except errors.NoEmailInUsername, e:
3356
3432
            warning('"%s" does not seem to contain an email address.  '
3357
3433
                    'This is allowed, but not recommended.', name)
3363
3439
            else:
3364
3440
                c = Branch.open(directory).get_config()
3365
3441
        else:
3366
 
            c = config.GlobalConfig()
 
3442
            c = _mod_config.GlobalConfig()
3367
3443
        c.set_user_option('email', name)
3368
3444
 
3369
3445
 
3436
3512
                'bzr alias --remove expects an alias to remove.')
3437
3513
        # If alias is not found, print something like:
3438
3514
        # unalias: foo: not found
3439
 
        c = config.GlobalConfig()
 
3515
        c = _mod_config.GlobalConfig()
3440
3516
        c.unset_alias(alias_name)
3441
3517
 
3442
3518
    @display_command
3443
3519
    def print_aliases(self):
3444
3520
        """Print out the defined aliases in a similar format to bash."""
3445
 
        aliases = config.GlobalConfig().get_aliases()
 
3521
        aliases = _mod_config.GlobalConfig().get_aliases()
3446
3522
        for key, value in sorted(aliases.iteritems()):
3447
3523
            self.outf.write('bzr alias %s="%s"\n' % (key, value))
3448
3524
 
3458
3534
 
3459
3535
    def set_alias(self, alias_name, alias_command):
3460
3536
        """Save the alias in the global config."""
3461
 
        c = config.GlobalConfig()
 
3537
        c = _mod_config.GlobalConfig()
3462
3538
        c.set_alias(alias_name, alias_command)
3463
3539
 
3464
3540
 
3499
3575
    If you set BZR_TEST_PDB=1 when running selftest, failing tests will drop
3500
3576
    into a pdb postmortem session.
3501
3577
 
 
3578
    The --coverage=DIRNAME global option produces a report with covered code
 
3579
    indicated.
 
3580
 
3502
3581
    :Examples:
3503
3582
        Run only tests relating to 'ignore'::
3504
3583
 
3588
3667
            randomize=None, exclude=None, strict=False,
3589
3668
            load_list=None, debugflag=None, starting_with=None, subunit=False,
3590
3669
            parallel=None, lsprof_tests=False):
3591
 
        from bzrlib.tests import selftest
3592
 
 
3593
 
        # Make deprecation warnings visible, unless -Werror is set
3594
 
        symbol_versioning.activate_deprecation_warnings(override=False)
 
3670
        from bzrlib import tests
3595
3671
 
3596
3672
        if testspecs_list is not None:
3597
3673
            pattern = '|'.join(testspecs_list)
3638
3714
                          "starting_with": starting_with
3639
3715
                          }
3640
3716
        selftest_kwargs.update(self.additional_selftest_args)
3641
 
        result = selftest(**selftest_kwargs)
 
3717
 
 
3718
        # Make deprecation warnings visible, unless -Werror is set
 
3719
        cleanup = symbol_versioning.activate_deprecation_warnings(
 
3720
            override=False)
 
3721
        try:
 
3722
            result = tests.selftest(**selftest_kwargs)
 
3723
        finally:
 
3724
            cleanup()
3642
3725
        return int(not result)
3643
3726
 
3644
3727
 
3701
3784
    with bzr send. If neither is specified, the default is the upstream branch
3702
3785
    or the branch most recently merged using --remember.
3703
3786
 
3704
 
    When merging a branch, by default the tip will be merged. To pick a different
3705
 
    revision, pass --revision. If you specify two values, the first will be used as
3706
 
    BASE and the second one as OTHER. Merging individual revisions, or a subset of
3707
 
    available revisions, like this is commonly referred to as "cherrypicking".
3708
 
 
3709
 
    Revision numbers are always relative to the branch being merged.
3710
 
 
3711
 
    By default, bzr will try to merge in all new work from the other
3712
 
    branch, automatically determining an appropriate base.  If this
3713
 
    fails, you may need to give an explicit base.
 
3787
    When merging from a branch, by default bzr will try to merge in all new
 
3788
    work from the other branch, automatically determining an appropriate base
 
3789
    revision.  If this fails, you may need to give an explicit base.
 
3790
 
 
3791
    To pick a different ending revision, pass "--revision OTHER".  bzr will
 
3792
    try to merge in all new work up to and including revision OTHER.
 
3793
 
 
3794
    If you specify two values, "--revision BASE..OTHER", only revisions BASE
 
3795
    through OTHER, excluding BASE but including OTHER, will be merged.  If this
 
3796
    causes some revisions to be skipped, i.e. if the destination branch does
 
3797
    not already contain revision BASE, such a merge is commonly referred to as
 
3798
    a "cherrypick".
 
3799
 
 
3800
    Revision numbers are always relative to the source branch.
3714
3801
 
3715
3802
    Merge will do its best to combine the changes in two branches, but there
3716
3803
    are some kinds of problems only a human can fix.  When it encounters those,
3740
3827
    you to apply each diff hunk and file change, similar to "shelve".
3741
3828
 
3742
3829
    :Examples:
3743
 
        To merge the latest revision from bzr.dev::
 
3830
        To merge all new revisions from bzr.dev::
3744
3831
 
3745
3832
            bzr merge ../bzr.dev
3746
3833
 
3861
3948
            merger.other_rev_id is not None):
3862
3949
            note('Nothing to do.')
3863
3950
            return 0
3864
 
        if pull:
 
3951
        if pull and not preview:
3865
3952
            if merger.interesting_files is not None:
3866
3953
                raise errors.BzrCommandError('Cannot pull individual files')
3867
3954
            if (merger.base_rev_id == tree.last_revision()):
3980
4067
        if ((remember or tree.branch.get_submit_branch() is None) and
3981
4068
             user_location is not None):
3982
4069
            tree.branch.set_submit_branch(other_branch.base)
3983
 
        _merge_tags_if_possible(other_branch, tree.branch)
 
4070
        # Merge tags (but don't set them in the master branch yet, the user
 
4071
        # might revert this merge).  Commit will propagate them.
 
4072
        _merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
3984
4073
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3985
4074
            other_revision_id, base_revision_id, other_branch, base_branch)
3986
4075
        if other_path != '':
4087
4176
        from bzrlib.conflicts import restore
4088
4177
        if merge_type is None:
4089
4178
            merge_type = _mod_merge.Merge3Merger
4090
 
        tree, file_list = tree_files(file_list)
 
4179
        tree, file_list = WorkingTree.open_containing_paths(file_list)
4091
4180
        self.add_cleanup(tree.lock_write().unlock)
4092
4181
        parents = tree.get_parent_ids()
4093
4182
        if len(parents) != 2:
4154
4243
    last committed revision is used.
4155
4244
 
4156
4245
    To remove only some changes, without reverting to a prior version, use
4157
 
    merge instead.  For example, "merge . --revision -2..-3" will remove the
4158
 
    changes introduced by -2, without affecting the changes introduced by -1.
4159
 
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
 
4246
    merge instead.  For example, "merge . -r -2..-3" (don't forget the ".")
 
4247
    will remove the changes introduced by the second last commit (-2), without
 
4248
    affecting the changes introduced by the last commit (-1).  To remove
 
4249
    certain changes on a hunk-by-hunk basis, see the shelve command.
4160
4250
 
4161
4251
    By default, any files that have been manually changed will be backed up
4162
4252
    first.  (Files changed only by merge are not backed up.)  Backup files have
4192
4282
    target branches.
4193
4283
    """
4194
4284
 
4195
 
    _see_also = ['cat', 'export']
 
4285
    _see_also = ['cat', 'export', 'merge', 'shelve']
4196
4286
    takes_options = [
4197
4287
        'revision',
4198
4288
        Option('no-backup', "Do not save backups of reverted files."),
4203
4293
 
4204
4294
    def run(self, revision=None, no_backup=False, file_list=None,
4205
4295
            forget_merges=None):
4206
 
        tree, file_list = tree_files(file_list)
 
4296
        tree, file_list = WorkingTree.open_containing_paths(file_list)
4207
4297
        self.add_cleanup(tree.lock_tree_write().unlock)
4208
4298
        if forget_merges:
4209
4299
            tree.set_parent_ids(tree.get_parent_ids()[:1])
4812
4902
            self.outf.write('The above revision(s) will be removed.\n')
4813
4903
 
4814
4904
        if not force:
4815
 
            if not ui.ui_factory.get_boolean('Are you sure'):
4816
 
                self.outf.write('Canceled')
 
4905
            if not ui.ui_factory.confirm_action(
 
4906
                    'Uncommit these revisions',
 
4907
                    'bzrlib.builtins.uncommit',
 
4908
                    {}):
 
4909
                self.outf.write('Canceled\n')
4817
4910
                return 0
4818
4911
 
4819
4912
        mutter('Uncommitting from {%s} to {%s}',
4825
4918
 
4826
4919
 
4827
4920
class cmd_break_lock(Command):
4828
 
    __doc__ = """Break a dead lock on a repository, branch or working directory.
 
4921
    __doc__ = """Break a dead lock.
 
4922
 
 
4923
    This command breaks a lock on a repository, branch, working directory or
 
4924
    config file.
4829
4925
 
4830
4926
    CAUTION: Locks should only be broken when you are sure that the process
4831
4927
    holding the lock has been stopped.
4836
4932
    :Examples:
4837
4933
        bzr break-lock
4838
4934
        bzr break-lock bzr+ssh://example.com/bzr/foo
 
4935
        bzr break-lock --conf ~/.bazaar
4839
4936
    """
 
4937
 
4840
4938
    takes_args = ['location?']
 
4939
    takes_options = [
 
4940
        Option('config',
 
4941
               help='LOCATION is the directory where the config lock is.'),
 
4942
        Option('force',
 
4943
            help='Do not ask for confirmation before breaking the lock.'),
 
4944
        ]
4841
4945
 
4842
 
    def run(self, location=None, show=False):
 
4946
    def run(self, location=None, config=False, force=False):
4843
4947
        if location is None:
4844
4948
            location = u'.'
4845
 
        control, relpath = bzrdir.BzrDir.open_containing(location)
4846
 
        try:
4847
 
            control.break_lock()
4848
 
        except NotImplementedError:
4849
 
            pass
 
4949
        if force:
 
4950
            ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
 
4951
                None,
 
4952
                {'bzrlib.lockdir.break': True})
 
4953
        if config:
 
4954
            conf = _mod_config.LockableConfig(file_name=location)
 
4955
            conf.break_lock()
 
4956
        else:
 
4957
            control, relpath = bzrdir.BzrDir.open_containing(location)
 
4958
            try:
 
4959
                control.break_lock()
 
4960
            except NotImplementedError:
 
4961
                pass
4850
4962
 
4851
4963
 
4852
4964
class cmd_wait_until_signalled(Command):
4937
5049
    not part of it.  (Such trees can be produced by "bzr split", but also by
4938
5050
    running "bzr branch" with the target inside a tree.)
4939
5051
 
4940
 
    The result is a combined tree, with the subtree no longer an independant
 
5052
    The result is a combined tree, with the subtree no longer an independent
4941
5053
    part.  This is marked as a merge of the subtree into the containing tree,
4942
5054
    and all history is preserved.
4943
5055
    """
5339
5451
            if tag_name is None:
5340
5452
                raise errors.BzrCommandError("No tag specified to delete.")
5341
5453
            branch.tags.delete_tag(tag_name)
5342
 
            self.outf.write('Deleted tag %s.\n' % tag_name)
 
5454
            note('Deleted tag %s.' % tag_name)
5343
5455
        else:
5344
5456
            if revision:
5345
5457
                if len(revision) != 1:
5357
5469
            if (not force) and branch.tags.has_tag(tag_name):
5358
5470
                raise errors.TagAlreadyExists(tag_name)
5359
5471
            branch.tags.set_tag(tag_name, revision_id)
5360
 
            self.outf.write('Created tag %s.\n' % tag_name)
 
5472
            note('Created tag %s.' % tag_name)
5361
5473
 
5362
5474
 
5363
5475
class cmd_tags(Command):
5370
5482
    takes_options = [
5371
5483
        custom_help('directory',
5372
5484
            help='Branch whose tags should be displayed.'),
5373
 
        RegistryOption.from_kwargs('sort',
 
5485
        RegistryOption('sort',
5374
5486
            'Sort tags by different criteria.', title='Sorting',
5375
 
            alpha='Sort tags lexicographically (default).',
5376
 
            time='Sort tags chronologically.',
 
5487
            lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5377
5488
            ),
5378
5489
        'show-ids',
5379
5490
        'revision',
5380
5491
    ]
5381
5492
 
5382
5493
    @display_command
5383
 
    def run(self,
5384
 
            directory='.',
5385
 
            sort='alpha',
5386
 
            show_ids=False,
5387
 
            revision=None,
5388
 
            ):
 
5494
    def run(self, directory='.', sort=None, show_ids=False, revision=None):
 
5495
        from bzrlib.tag import tag_sort_methods
5389
5496
        branch, relpath = Branch.open_containing(directory)
5390
5497
 
5391
5498
        tags = branch.tags.get_tag_dict().items()
5400
5507
            # only show revisions between revid1 and revid2 (inclusive)
5401
5508
            tags = [(tag, revid) for tag, revid in tags if
5402
5509
                graph.is_between(revid, revid1, revid2)]
5403
 
        if sort == 'alpha':
5404
 
            tags.sort()
5405
 
        elif sort == 'time':
5406
 
            timestamps = {}
5407
 
            for tag, revid in tags:
5408
 
                try:
5409
 
                    revobj = branch.repository.get_revision(revid)
5410
 
                except errors.NoSuchRevision:
5411
 
                    timestamp = sys.maxint # place them at the end
5412
 
                else:
5413
 
                    timestamp = revobj.timestamp
5414
 
                timestamps[revid] = timestamp
5415
 
            tags.sort(key=lambda x: timestamps[x[1]])
 
5510
        if sort is None:
 
5511
            sort = tag_sort_methods.get()
 
5512
        sort(branch, tags)
5416
5513
        if not show_ids:
5417
5514
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5418
5515
            for index, (tag, revid) in enumerate(tags):
5705
5802
            name=None,
5706
5803
            switch=None,
5707
5804
            ):
5708
 
        tree, file_list = tree_files(file_list, apply_view=False)
 
5805
        tree, file_list = WorkingTree.open_containing_paths(file_list,
 
5806
            apply_view=False)
5709
5807
        current_view, view_dict = tree.views.get_view_info()
5710
5808
        if name is None:
5711
5809
            name = current_view
5815
5913
            location = "."
5816
5914
        branch = Branch.open_containing(location)[0]
5817
5915
        branch.bzrdir.destroy_branch()
5818
 
        
 
5916
 
5819
5917
 
5820
5918
class cmd_shelve(Command):
5821
5919
    __doc__ = """Temporarily set aside some changes from the current tree.
5840
5938
 
5841
5939
    You can put multiple items on the shelf, and by default, 'unshelve' will
5842
5940
    restore the most recently shelved changes.
 
5941
 
 
5942
    For complicated changes, it is possible to edit the changes in a separate
 
5943
    editor program to decide what the file remaining in the working copy
 
5944
    should look like.  To do this, add the configuration option
 
5945
 
 
5946
        change_editor = PROGRAM @new_path @old_path
 
5947
 
 
5948
    where @new_path is replaced with the path of the new version of the 
 
5949
    file and @old_path is replaced with the path of the old version of 
 
5950
    the file.  The PROGRAM should save the new file with the desired 
 
5951
    contents of the file in the working tree.
 
5952
        
5843
5953
    """
5844
5954
 
5845
5955
    takes_args = ['file*']
5857
5967
        Option('destroy',
5858
5968
               help='Destroy removed changes instead of shelving them.'),
5859
5969
    ]
5860
 
    _see_also = ['unshelve']
 
5970
    _see_also = ['unshelve', 'configuration']
5861
5971
 
5862
5972
    def run(self, revision=None, all=False, file_list=None, message=None,
5863
 
            writer=None, list=False, destroy=False, directory=u'.'):
 
5973
            writer=None, list=False, destroy=False, directory=None):
5864
5974
        if list:
5865
 
            return self.run_for_list()
 
5975
            return self.run_for_list(directory=directory)
5866
5976
        from bzrlib.shelf_ui import Shelver
5867
5977
        if writer is None:
5868
5978
            writer = bzrlib.option.diff_writer_registry.get()
5876
5986
        except errors.UserAbort:
5877
5987
            return 0
5878
5988
 
5879
 
    def run_for_list(self):
5880
 
        tree = WorkingTree.open_containing('.')[0]
 
5989
    def run_for_list(self, directory=None):
 
5990
        if directory is None:
 
5991
            directory = u'.'
 
5992
        tree = WorkingTree.open_containing(directory)[0]
5881
5993
        self.add_cleanup(tree.lock_read().unlock)
5882
5994
        manager = tree.get_shelf_manager()
5883
5995
        shelves = manager.active_shelves()
6012
6124
    # be only called once.
6013
6125
    for (name, aliases, module_name) in [
6014
6126
        ('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
 
6127
        ('cmd_config', [], 'bzrlib.config'),
6015
6128
        ('cmd_dpush', [], 'bzrlib.foreign'),
6016
6129
        ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6017
6130
        ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6018
6131
        ('cmd_conflicts', [], 'bzrlib.conflicts'),
6019
6132
        ('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
 
6133
        ('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6020
6134
        ]:
6021
6135
        builtin_command_registry.register_lazy(name, aliases, module_name)