~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin
  • Date: 2011-05-27 03:06:26 UTC
  • mto: (5425.4.22 220464-stale-locks)
  • mto: This revision was merged to the branch mainline in revision 5970.
  • Revision ID: gzlist@googlemail.com-20110527030626-tzspe5y4wta5n1y8
Get the code for ERROR_ACCESS_DENIED right

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
250
250
    To skip the display of pending merge information altogether, use
251
251
    the no-pending option or specify a file/directory.
252
252
 
253
 
    If a revision argument is given, the status is calculated against
254
 
    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'.
255
259
    """
256
260
 
257
261
    # TODO: --no-recurse, --recurse options
324
328
        if revision_id is None and revision is None:
325
329
            raise errors.BzrCommandError('You must supply either'
326
330
                                         ' --revision or a revision_id')
327
 
        b = WorkingTree.open_containing(directory)[0].branch
 
331
 
 
332
        b = bzrdir.BzrDir.open_containing_tree_or_branch(directory)[1]
328
333
 
329
334
        revisions = b.repository.revisions
330
335
        if revisions is None:
408
413
                self.outf.write(page_bytes[:header_end])
409
414
                page_bytes = data
410
415
            self.outf.write('\nPage %d\n' % (page_idx,))
411
 
            decomp_bytes = zlib.decompress(page_bytes)
412
 
            self.outf.write(decomp_bytes)
413
 
            self.outf.write('\n')
 
416
            if len(page_bytes) == 0:
 
417
                self.outf.write('(empty)\n');
 
418
            else:
 
419
                decomp_bytes = zlib.decompress(page_bytes)
 
420
                self.outf.write(decomp_bytes)
 
421
                self.outf.write('\n')
414
422
 
415
423
    def _dump_entries(self, trans, basename):
416
424
        try:
477
485
            d.destroy_workingtree()
478
486
 
479
487
 
 
488
class cmd_repair_workingtree(Command):
 
489
    __doc__ = """Reset the working tree state file.
 
490
 
 
491
    This is not meant to be used normally, but more as a way to recover from
 
492
    filesystem corruption, etc. This rebuilds the working inventory back to a
 
493
    'known good' state. Any new modifications (adding a file, renaming, etc)
 
494
    will be lost, though modified files will still be detected as such.
 
495
 
 
496
    Most users will want something more like "bzr revert" or "bzr update"
 
497
    unless the state file has become corrupted.
 
498
 
 
499
    By default this attempts to recover the current state by looking at the
 
500
    headers of the state file. If the state file is too corrupted to even do
 
501
    that, you can supply --revision to force the state of the tree.
 
502
    """
 
503
 
 
504
    takes_options = ['revision', 'directory',
 
505
        Option('force',
 
506
               help='Reset the tree even if it doesn\'t appear to be'
 
507
                    ' corrupted.'),
 
508
    ]
 
509
    hidden = True
 
510
 
 
511
    def run(self, revision=None, directory='.', force=False):
 
512
        tree, _ = WorkingTree.open_containing(directory)
 
513
        self.add_cleanup(tree.lock_tree_write().unlock)
 
514
        if not force:
 
515
            try:
 
516
                tree.check_state()
 
517
            except errors.BzrError:
 
518
                pass # There seems to be a real error here, so we'll reset
 
519
            else:
 
520
                # Refuse
 
521
                raise errors.BzrCommandError(
 
522
                    'The tree does not appear to be corrupt. You probably'
 
523
                    ' want "bzr revert" instead. Use "--force" if you are'
 
524
                    ' sure you want to reset the working tree.')
 
525
        if revision is None:
 
526
            revision_ids = None
 
527
        else:
 
528
            revision_ids = [r.as_revision_id(tree.branch) for r in revision]
 
529
        try:
 
530
            tree.reset_state(revision_ids)
 
531
        except errors.BzrError, e:
 
532
            if revision_ids is None:
 
533
                extra = (', the header appears corrupt, try passing -r -1'
 
534
                         ' to set the state to the last commit')
 
535
            else:
 
536
                extra = ''
 
537
            raise errors.BzrCommandError('failed to reset the tree state'
 
538
                                         + extra)
 
539
 
 
540
 
480
541
class cmd_revno(Command):
481
542
    __doc__ = """Show current revision number.
482
543
 
901
962
    match the remote one, use pull --overwrite. This will work even if the two
902
963
    branches have diverged.
903
964
 
904
 
    If there is no default location set, the first pull will set it.  After
905
 
    that, you can omit the location to use the default.  To change the
906
 
    default, use --remember. The value will only be saved if the remote
907
 
    location can be accessed.
 
965
    If there is no default location set, the first pull will set it (use
 
966
    --no-remember to avoid settting it). After that, you can omit the
 
967
    location to use the default.  To change the default, use --remember. The
 
968
    value will only be saved if the remote location can be accessed.
908
969
 
909
970
    Note: The location can be specified either in the form of a branch,
910
971
    or in the form of a path to a file containing a merge directive generated
923
984
                 "branch.  Local pulls are not applied to "
924
985
                 "the master branch."
925
986
            ),
 
987
        Option('show-base',
 
988
            help="Show base revision text in conflicts.")
926
989
        ]
927
990
    takes_args = ['location?']
928
991
    encoding_type = 'replace'
929
992
 
930
 
    def run(self, location=None, remember=False, overwrite=False,
 
993
    def run(self, location=None, remember=None, overwrite=False,
931
994
            revision=None, verbose=False,
932
 
            directory=None, local=False):
 
995
            directory=None, local=False,
 
996
            show_base=False):
933
997
        # FIXME: too much stuff is in the command class
934
998
        revision_id = None
935
999
        mergeable = None
944
1008
            branch_to = Branch.open_containing(directory)[0]
945
1009
            self.add_cleanup(branch_to.lock_write().unlock)
946
1010
 
 
1011
        if tree_to is None and show_base:
 
1012
            raise errors.BzrCommandError("Need working tree for --show-base.")
 
1013
 
947
1014
        if local and not branch_to.get_bound_location():
948
1015
            raise errors.LocalRequiresBoundBranch()
949
1016
 
980
1047
            branch_from = Branch.open(location,
981
1048
                possible_transports=possible_transports)
982
1049
            self.add_cleanup(branch_from.lock_read().unlock)
983
 
 
984
 
            if branch_to.get_parent() is None or remember:
 
1050
            # Remembers if asked explicitly or no previous location is set
 
1051
            if (remember
 
1052
                or (remember is None and branch_to.get_parent() is None)):
985
1053
                branch_to.set_parent(branch_from.base)
986
1054
 
987
1055
        if revision is not None:
994
1062
                view_info=view_info)
995
1063
            result = tree_to.pull(
996
1064
                branch_from, overwrite, revision_id, change_reporter,
997
 
                possible_transports=possible_transports, local=local)
 
1065
                possible_transports=possible_transports, local=local,
 
1066
                show_base=show_base)
998
1067
        else:
999
1068
            result = branch_to.pull(
1000
1069
                branch_from, overwrite, revision_id, local=local)
1004
1073
            log.show_branch_change(
1005
1074
                branch_to, self.outf, result.old_revno,
1006
1075
                result.old_revid)
 
1076
        if getattr(result, 'tag_conflicts', None):
 
1077
            return 1
 
1078
        else:
 
1079
            return 0
1007
1080
 
1008
1081
 
1009
1082
class cmd_push(Command):
1026
1099
    do a merge (see bzr help merge) from the other branch, and commit that.
1027
1100
    After that you will be able to do a push without '--overwrite'.
1028
1101
 
1029
 
    If there is no default push location set, the first push will set it.
1030
 
    After that, you can omit the location to use the default.  To change the
1031
 
    default, use --remember. The value will only be saved if the remote
1032
 
    location can be accessed.
 
1102
    If there is no default push location set, the first push will set it (use
 
1103
    --no-remember to avoid settting it).  After that, you can omit the
 
1104
    location to use the default.  To change the default, use --remember. The
 
1105
    value will only be saved if the remote location can be accessed.
1033
1106
    """
1034
1107
 
1035
1108
    _see_also = ['pull', 'update', 'working-trees']
1056
1129
        Option('strict',
1057
1130
               help='Refuse to push if there are uncommitted changes in'
1058
1131
               ' the working tree, --no-strict disables the check.'),
 
1132
        Option('no-tree',
 
1133
               help="Don't populate the working tree, even for protocols"
 
1134
               " that support it."),
1059
1135
        ]
1060
1136
    takes_args = ['location?']
1061
1137
    encoding_type = 'replace'
1062
1138
 
1063
 
    def run(self, location=None, remember=False, overwrite=False,
 
1139
    def run(self, location=None, remember=None, overwrite=False,
1064
1140
        create_prefix=False, verbose=False, revision=None,
1065
1141
        use_existing_dir=False, directory=None, stacked_on=None,
1066
 
        stacked=False, strict=None):
 
1142
        stacked=False, strict=None, no_tree=False):
1067
1143
        from bzrlib.push import _show_push_branch
1068
1144
 
1069
1145
        if directory is None:
1115
1191
        _show_push_branch(br_from, revision_id, location, self.outf,
1116
1192
            verbose=verbose, overwrite=overwrite, remember=remember,
1117
1193
            stacked_on=stacked_on, create_prefix=create_prefix,
1118
 
            use_existing_dir=use_existing_dir)
 
1194
            use_existing_dir=use_existing_dir, no_tree=no_tree)
1119
1195
 
1120
1196
 
1121
1197
class cmd_branch(Command):
1130
1206
 
1131
1207
    To retrieve the branch as of a particular revision, supply the --revision
1132
1208
    parameter, as in "branch foo/bar -r 5".
 
1209
 
 
1210
    The synonyms 'clone' and 'get' for this command are deprecated.
1133
1211
    """
1134
1212
 
1135
1213
    _see_also = ['checkout']
1165
1243
            files_from=None):
1166
1244
        from bzrlib import switch as _mod_switch
1167
1245
        from bzrlib.tag import _merge_tags_if_possible
 
1246
        if self.invoked_as in ['get', 'clone']:
 
1247
            ui.ui_factory.show_user_warning(
 
1248
                'deprecated_command',
 
1249
                deprecated_name=self.invoked_as,
 
1250
                recommended_name='branch',
 
1251
                deprecated_in_version='2.4')
1168
1252
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1169
1253
            from_location)
1170
1254
        if not (hardlink or files_from):
1363
1447
 
1364
1448
    _see_also = ['pull', 'working-trees', 'status-flags']
1365
1449
    takes_args = ['dir?']
1366
 
    takes_options = ['revision']
 
1450
    takes_options = ['revision',
 
1451
                     Option('show-base',
 
1452
                            help="Show base revision text in conflicts."),
 
1453
                     ]
1367
1454
    aliases = ['up']
1368
1455
 
1369
 
    def run(self, dir='.', revision=None):
 
1456
    def run(self, dir='.', revision=None, show_base=None):
1370
1457
        if revision is not None and len(revision) != 1:
1371
1458
            raise errors.BzrCommandError(
1372
1459
                        "bzr update --revision takes exactly one revision")
1412
1499
                change_reporter,
1413
1500
                possible_transports=possible_transports,
1414
1501
                revision=revision_id,
1415
 
                old_tip=old_tip)
 
1502
                old_tip=old_tip,
 
1503
                show_base=show_base)
1416
1504
        except errors.NoSuchRevision, e:
1417
1505
            raise errors.BzrCommandError(
1418
1506
                                  "branch has no revision %s\n"
1494
1582
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1495
1583
            safe='Backup changed files (default).',
1496
1584
            keep='Delete from bzr but leave the working copy.',
 
1585
            no_backup='Don\'t backup changed files.',
1497
1586
            force='Delete all the specified files, even if they can not be '
1498
 
                'recovered and even if they are non-empty directories.')]
 
1587
                'recovered and even if they are non-empty directories. '
 
1588
                '(deprecated, use no-backup)')]
1499
1589
    aliases = ['rm', 'del']
1500
1590
    encoding_type = 'replace'
1501
1591
 
1502
1592
    def run(self, file_list, verbose=False, new=False,
1503
1593
        file_deletion_strategy='safe'):
 
1594
        if file_deletion_strategy == 'force':
 
1595
            note("(The --force option is deprecated, rather use --no-backup "
 
1596
                "in future.)")
 
1597
            file_deletion_strategy = 'no-backup'
 
1598
 
1504
1599
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1505
1600
 
1506
1601
        if file_list is not None:
1527
1622
            file_deletion_strategy = 'keep'
1528
1623
        tree.remove(file_list, verbose=verbose, to_file=self.outf,
1529
1624
            keep_files=file_deletion_strategy=='keep',
1530
 
            force=file_deletion_strategy=='force')
 
1625
            force=(file_deletion_strategy=='no-backup'))
1531
1626
 
1532
1627
 
1533
1628
class cmd_file_id(Command):
1688
1783
                ),
1689
1784
         Option('append-revisions-only',
1690
1785
                help='Never change revnos or the existing log.'
1691
 
                '  Append revisions to it only.')
 
1786
                '  Append revisions to it only.'),
 
1787
         Option('no-tree',
 
1788
                'Create a branch without a working tree.')
1692
1789
         ]
1693
1790
    def run(self, location=None, format=None, append_revisions_only=False,
1694
 
            create_prefix=False):
 
1791
            create_prefix=False, no_tree=False):
1695
1792
        if format is None:
1696
1793
            format = bzrdir.format_registry.make_bzrdir('default')
1697
1794
        if location is None:
1720
1817
        except errors.NotBranchError:
1721
1818
            # really a NotBzrDir error...
1722
1819
            create_branch = bzrdir.BzrDir.create_branch_convenience
 
1820
            if no_tree:
 
1821
                force_new_tree = False
 
1822
            else:
 
1823
                force_new_tree = None
1723
1824
            branch = create_branch(to_transport.base, format=format,
1724
 
                                   possible_transports=[to_transport])
 
1825
                                   possible_transports=[to_transport],
 
1826
                                   force_new_tree=force_new_tree)
1725
1827
            a_bzrdir = branch.bzrdir
1726
1828
        else:
1727
1829
            from bzrlib.transport.local import LocalTransport
1731
1833
                        raise errors.BranchExistsWithoutWorkingTree(location)
1732
1834
                raise errors.AlreadyBranchError(location)
1733
1835
            branch = a_bzrdir.create_branch()
1734
 
            a_bzrdir.create_workingtree()
 
1836
            if not no_tree:
 
1837
                a_bzrdir.create_workingtree()
1735
1838
        if append_revisions_only:
1736
1839
            try:
1737
1840
                branch.set_append_revisions_only(True)
1831
1934
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
1832
1935
    produces patches suitable for "patch -p1".
1833
1936
 
 
1937
    Note that when using the -r argument with a range of revisions, the
 
1938
    differences are computed between the two specified revisions.  That
 
1939
    is, the command does not show the changes introduced by the first 
 
1940
    revision in the range.  This differs from the interpretation of 
 
1941
    revision ranges used by "bzr log" which includes the first revision
 
1942
    in the range.
 
1943
 
1834
1944
    :Exit values:
1835
1945
        1 - changed
1836
1946
        2 - unrepresentable changes
1854
1964
 
1855
1965
            bzr diff -r1..3 xxx
1856
1966
 
1857
 
        To see the changes introduced in revision X::
 
1967
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1968
 
 
1969
            bzr diff -c2
 
1970
 
 
1971
        To see the changes introduced by revision X::
1858
1972
        
1859
1973
            bzr diff -cX
1860
1974
 
1864
1978
 
1865
1979
            bzr diff -r<chosen_parent>..X
1866
1980
 
1867
 
        The changes introduced by revision 2 (equivalent to -r1..2)::
 
1981
        The changes between the current revision and the previous revision
 
1982
        (equivalent to -c-1 and -r-2..-1)
1868
1983
 
1869
 
            bzr diff -c2
 
1984
            bzr diff -r-2..
1870
1985
 
1871
1986
        Show just the differences for file NEWS::
1872
1987
 
1916
2031
            type=unicode,
1917
2032
            ),
1918
2033
        RegistryOption('format',
 
2034
            short_name='F',
1919
2035
            help='Diff format to use.',
1920
2036
            lazy_registry=('bzrlib.diff', 'format_registry'),
1921
 
            value_switches=False, title='Diff format'),
 
2037
            title='Diff format'),
1922
2038
        ]
1923
2039
    aliases = ['di', 'dif']
1924
2040
    encoding_type = 'exact'
2005
2121
    @display_command
2006
2122
    def run(self, null=False, directory=u'.'):
2007
2123
        tree = WorkingTree.open_containing(directory)[0]
 
2124
        self.add_cleanup(tree.lock_read().unlock)
2008
2125
        td = tree.changes_from(tree.basis_tree())
 
2126
        self.cleanup_now()
2009
2127
        for path, id, kind, text_modified, meta_modified in td.modified:
2010
2128
            if null:
2011
2129
                self.outf.write(path + '\0')
2641
2759
    Patterns prefixed with '!!' act as regular ignore patterns, but have
2642
2760
    precedence over the '!' exception patterns.
2643
2761
 
2644
 
    Note: ignore patterns containing shell wildcards must be quoted from
2645
 
    the shell on Unix.
 
2762
    :Notes: 
 
2763
        
 
2764
    * Ignore patterns containing shell wildcards must be quoted from
 
2765
      the shell on Unix.
 
2766
 
 
2767
    * Ignore patterns starting with "#" act as comments in the ignore file.
 
2768
      To ignore patterns that begin with that character, use the "RE:" prefix.
2646
2769
 
2647
2770
    :Examples:
2648
2771
        Ignore the top level Makefile::
2657
2780
 
2658
2781
            bzr ignore "!special.class"
2659
2782
 
 
2783
        Ignore files whose name begins with the "#" character::
 
2784
 
 
2785
            bzr ignore "RE:^#"
 
2786
 
2660
2787
        Ignore .o files under the lib directory::
2661
2788
 
2662
2789
            bzr ignore "lib/**/*.o"
2670
2797
            bzr ignore "RE:(?!debian/).*"
2671
2798
        
2672
2799
        Ignore everything except the "local" toplevel directory,
2673
 
        but always ignore "*~" autosave files, even under local/::
 
2800
        but always ignore autosave files ending in ~, even under local/::
2674
2801
        
2675
2802
            bzr ignore "*"
2676
2803
            bzr ignore "!./local"
2804
2931
         zip                          .zip
2805
2932
      =================       =========================
2806
2933
    """
 
2934
    encoding = 'exact'
2807
2935
    takes_args = ['dest', 'branch_or_subdir?']
2808
2936
    takes_options = ['directory',
2809
2937
        Option('format',
2987
3115
      to trigger updates to external systems like bug trackers. The --fixes
2988
3116
      option can be used to record the association between a revision and
2989
3117
      one or more bugs. See ``bzr help bugs`` for details.
2990
 
 
2991
 
      A selective commit may fail in some cases where the committed
2992
 
      tree would be invalid. Consider::
2993
 
  
2994
 
        bzr init foo
2995
 
        mkdir foo/bar
2996
 
        bzr add foo/bar
2997
 
        bzr commit foo -m "committing foo"
2998
 
        bzr mv foo/bar foo/baz
2999
 
        mkdir foo/bar
3000
 
        bzr add foo/bar
3001
 
        bzr commit foo/bar -m "committing bar but not baz"
3002
 
  
3003
 
      In the example above, the last commit will fail by design. This gives
3004
 
      the user the opportunity to decide whether they want to commit the
3005
 
      rename at the same time, separately first, or not at all. (As a general
3006
 
      rule, when in doubt, Bazaar has a policy of Doing the Safe Thing.)
3007
3118
    """
3008
 
    # TODO: Run hooks on tree to-be-committed, and after commit.
3009
 
 
3010
 
    # TODO: Strict commit that fails if there are deleted files.
3011
 
    #       (what does "deleted files" mean ??)
3012
 
 
3013
 
    # TODO: Give better message for -s, --summary, used by tla people
3014
 
 
3015
 
    # XXX: verbose currently does nothing
3016
3119
 
3017
3120
    _see_also = ['add', 'bugs', 'hooks', 'uncommit']
3018
3121
    takes_args = ['selected*']
3050
3153
             Option('show-diff', short_name='p',
3051
3154
                    help='When no message is supplied, show the diff along'
3052
3155
                    ' with the status summary in the message editor.'),
 
3156
             Option('lossy', 
 
3157
                    help='When committing to a foreign version control '
 
3158
                    'system do not push data that can not be natively '
 
3159
                    'represented.'),
3053
3160
             ]
3054
3161
    aliases = ['ci', 'checkin']
3055
3162
 
3074
3181
 
3075
3182
    def run(self, message=None, file=None, verbose=False, selected_list=None,
3076
3183
            unchanged=False, strict=False, local=False, fixes=None,
3077
 
            author=None, show_diff=False, exclude=None, commit_time=None):
 
3184
            author=None, show_diff=False, exclude=None, commit_time=None,
 
3185
            lossy=False):
3078
3186
        from bzrlib.errors import (
3079
3187
            PointlessCommit,
3080
3188
            ConflictsInTree,
3094
3202
                raise errors.BzrCommandError(
3095
3203
                    "Could not parse --commit-time: " + str(e))
3096
3204
 
3097
 
        # TODO: Need a blackbox test for invoking the external editor; may be
3098
 
        # slightly problematic to run this cross-platform.
3099
 
 
3100
 
        # TODO: do more checks that the commit will succeed before
3101
 
        # spending the user's valuable time typing a commit message.
3102
 
 
3103
3205
        properties = {}
3104
3206
 
3105
3207
        tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3182
3284
                        reporter=None, verbose=verbose, revprops=properties,
3183
3285
                        authors=author, timestamp=commit_stamp,
3184
3286
                        timezone=offset,
3185
 
                        exclude=tree.safe_relpath_files(exclude))
 
3287
                        exclude=tree.safe_relpath_files(exclude),
 
3288
                        lossy=lossy)
3186
3289
        except PointlessCommit:
3187
3290
            raise errors.BzrCommandError("No changes to commit."
3188
 
                              " Use --unchanged to commit anyhow.")
 
3291
                " Please 'bzr add' the files you want to commit, or use"
 
3292
                " --unchanged to force an empty commit.")
3189
3293
        except ConflictsInTree:
3190
3294
            raise errors.BzrCommandError('Conflicts detected in working '
3191
3295
                'tree.  Use "bzr conflicts" to list, "bzr resolve FILE" to'
3272
3376
 
3273
3377
 
3274
3378
class cmd_upgrade(Command):
3275
 
    __doc__ = """Upgrade branch storage to current format.
3276
 
 
3277
 
    The check command or bzr developers may sometimes advise you to run
3278
 
    this command. When the default format has changed you may also be warned
3279
 
    during other operations to upgrade.
 
3379
    __doc__ = """Upgrade a repository, branch or working tree to a newer format.
 
3380
 
 
3381
    When the default format has changed after a major new release of
 
3382
    Bazaar, you may be informed during certain operations that you
 
3383
    should upgrade. Upgrading to a newer format may improve performance
 
3384
    or make new features available. It may however limit interoperability
 
3385
    with older repositories or with older versions of Bazaar.
 
3386
 
 
3387
    If you wish to upgrade to a particular format rather than the
 
3388
    current default, that can be specified using the --format option.
 
3389
    As a consequence, you can use the upgrade command this way to
 
3390
    "downgrade" to an earlier format, though some conversions are
 
3391
    a one way process (e.g. changing from the 1.x default to the
 
3392
    2.x default) so downgrading is not always possible.
 
3393
 
 
3394
    A backup.bzr.~#~ directory is created at the start of the conversion
 
3395
    process (where # is a number). By default, this is left there on
 
3396
    completion. If the conversion fails, delete the new .bzr directory
 
3397
    and rename this one back in its place. Use the --clean option to ask
 
3398
    for the backup.bzr directory to be removed on successful conversion.
 
3399
    Alternatively, you can delete it by hand if everything looks good
 
3400
    afterwards.
 
3401
 
 
3402
    If the location given is a shared repository, dependent branches
 
3403
    are also converted provided the repository converts successfully.
 
3404
    If the conversion of a branch fails, remaining branches are still
 
3405
    tried.
 
3406
 
 
3407
    For more information on upgrades, see the Bazaar Upgrade Guide,
 
3408
    http://doc.bazaar.canonical.com/latest/en/upgrade-guide/.
3280
3409
    """
3281
3410
 
3282
 
    _see_also = ['check']
 
3411
    _see_also = ['check', 'reconcile', 'formats']
3283
3412
    takes_args = ['url?']
3284
3413
    takes_options = [
3285
 
                    RegistryOption('format',
3286
 
                        help='Upgrade to a specific format.  See "bzr help'
3287
 
                             ' formats" for details.',
3288
 
                        lazy_registry=('bzrlib.bzrdir', 'format_registry'),
3289
 
                        converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
3290
 
                        value_switches=True, title='Branch format'),
3291
 
                    ]
 
3414
        RegistryOption('format',
 
3415
            help='Upgrade to a specific format.  See "bzr help'
 
3416
                 ' formats" for details.',
 
3417
            lazy_registry=('bzrlib.bzrdir', 'format_registry'),
 
3418
            converter=lambda name: bzrdir.format_registry.make_bzrdir(name),
 
3419
            value_switches=True, title='Branch format'),
 
3420
        Option('clean',
 
3421
            help='Remove the backup.bzr directory if successful.'),
 
3422
        Option('dry-run',
 
3423
            help="Show what would be done, but don't actually do anything."),
 
3424
    ]
3292
3425
 
3293
 
    def run(self, url='.', format=None):
 
3426
    def run(self, url='.', format=None, clean=False, dry_run=False):
3294
3427
        from bzrlib.upgrade import upgrade
3295
 
        upgrade(url, format)
 
3428
        exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
 
3429
        if exceptions:
 
3430
            if len(exceptions) == 1:
 
3431
                # Compatibility with historical behavior
 
3432
                raise exceptions[0]
 
3433
            else:
 
3434
                return 3
3296
3435
 
3297
3436
 
3298
3437
class cmd_whoami(Command):
3334
3473
                self.outf.write(c.username() + '\n')
3335
3474
            return
3336
3475
 
 
3476
        if email:
 
3477
            raise errors.BzrCommandError("--email can only be used to display existing "
 
3478
                                         "identity")
 
3479
 
3337
3480
        # display a warning if an email address isn't included in the given name.
3338
3481
        try:
3339
3482
            _mod_config.extract_email_address(name)
3693
3836
    with bzr send. If neither is specified, the default is the upstream branch
3694
3837
    or the branch most recently merged using --remember.
3695
3838
 
3696
 
    When merging a branch, by default the tip will be merged. To pick a different
3697
 
    revision, pass --revision. If you specify two values, the first will be used as
3698
 
    BASE and the second one as OTHER. Merging individual revisions, or a subset of
3699
 
    available revisions, like this is commonly referred to as "cherrypicking".
3700
 
 
3701
 
    Revision numbers are always relative to the branch being merged.
3702
 
 
3703
 
    By default, bzr will try to merge in all new work from the other
3704
 
    branch, automatically determining an appropriate base.  If this
3705
 
    fails, you may need to give an explicit base.
 
3839
    When merging from a branch, by default bzr will try to merge in all new
 
3840
    work from the other branch, automatically determining an appropriate base
 
3841
    revision.  If this fails, you may need to give an explicit base.
 
3842
 
 
3843
    To pick a different ending revision, pass "--revision OTHER".  bzr will
 
3844
    try to merge in all new work up to and including revision OTHER.
 
3845
 
 
3846
    If you specify two values, "--revision BASE..OTHER", only revisions BASE
 
3847
    through OTHER, excluding BASE but including OTHER, will be merged.  If this
 
3848
    causes some revisions to be skipped, i.e. if the destination branch does
 
3849
    not already contain revision BASE, such a merge is commonly referred to as
 
3850
    a "cherrypick". Unlike a normal merge, Bazaar does not currently track
 
3851
    cherrypicks. The changes look like a normal commit, and the history of the
 
3852
    changes from the other branch is not stored in the commit.
 
3853
 
 
3854
    Revision numbers are always relative to the source branch.
3706
3855
 
3707
3856
    Merge will do its best to combine the changes in two branches, but there
3708
3857
    are some kinds of problems only a human can fix.  When it encounters those,
3711
3860
 
3712
3861
    Use bzr resolve when you have fixed a problem.  See also bzr conflicts.
3713
3862
 
3714
 
    If there is no default branch set, the first merge will set it. After
3715
 
    that, you can omit the branch to use the default.  To change the
3716
 
    default, use --remember. The value will only be saved if the remote
3717
 
    location can be accessed.
 
3863
    If there is no default branch set, the first merge will set it (use
 
3864
    --no-remember to avoid settting it). After that, you can omit the branch
 
3865
    to use the default.  To change the default, use --remember. The value will
 
3866
    only be saved if the remote location can be accessed.
3718
3867
 
3719
3868
    The results of the merge are placed into the destination working
3720
3869
    directory, where they can be reviewed (with bzr diff), tested, and then
3732
3881
    you to apply each diff hunk and file change, similar to "shelve".
3733
3882
 
3734
3883
    :Examples:
3735
 
        To merge the latest revision from bzr.dev::
 
3884
        To merge all new revisions from bzr.dev::
3736
3885
 
3737
3886
            bzr merge ../bzr.dev
3738
3887
 
3785
3934
    ]
3786
3935
 
3787
3936
    def run(self, location=None, revision=None, force=False,
3788
 
            merge_type=None, show_base=False, reprocess=None, remember=False,
 
3937
            merge_type=None, show_base=False, reprocess=None, remember=None,
3789
3938
            uncommitted=False, pull=False,
3790
3939
            directory=None,
3791
3940
            preview=False,
3799
3948
        merger = None
3800
3949
        allow_pending = True
3801
3950
        verified = 'inapplicable'
 
3951
 
3802
3952
        tree = WorkingTree.open_containing(directory)[0]
 
3953
        if tree.branch.revno() == 0:
 
3954
            raise errors.BzrCommandError('Merging into empty branches not currently supported, '
 
3955
                                         'https://bugs.launchpad.net/bzr/+bug/308562')
3803
3956
 
3804
3957
        try:
3805
3958
            basis_tree = tree.revision_tree(tree.last_revision())
3853
4006
            merger.other_rev_id is not None):
3854
4007
            note('Nothing to do.')
3855
4008
            return 0
3856
 
        if pull:
 
4009
        if pull and not preview:
3857
4010
            if merger.interesting_files is not None:
3858
4011
                raise errors.BzrCommandError('Cannot pull individual files')
3859
4012
            if (merger.base_rev_id == tree.last_revision()):
3968
4121
        if other_revision_id is None:
3969
4122
            other_revision_id = _mod_revision.ensure_null(
3970
4123
                other_branch.last_revision())
3971
 
        # Remember where we merge from
3972
 
        if ((remember or tree.branch.get_submit_branch() is None) and
3973
 
             user_location is not None):
 
4124
        # Remember where we merge from. We need to remember if:
 
4125
        # - user specify a location (and we don't merge from the parent
 
4126
        #   branch)
 
4127
        # - user ask to remember or there is no previous location set to merge
 
4128
        #   from and user didn't ask to *not* remember
 
4129
        if (user_location is not None
 
4130
            and ((remember
 
4131
                  or (remember is None
 
4132
                      and tree.branch.get_submit_branch() is None)))):
3974
4133
            tree.branch.set_submit_branch(other_branch.base)
3975
 
        _merge_tags_if_possible(other_branch, tree.branch)
 
4134
        # Merge tags (but don't set them in the master branch yet, the user
 
4135
        # might revert this merge).  Commit will propagate them.
 
4136
        _merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
3976
4137
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
3977
4138
            other_revision_id, base_revision_id, other_branch, base_branch)
3978
4139
        if other_path != '':
4146
4307
    last committed revision is used.
4147
4308
 
4148
4309
    To remove only some changes, without reverting to a prior version, use
4149
 
    merge instead.  For example, "merge . --revision -2..-3" will remove the
4150
 
    changes introduced by -2, without affecting the changes introduced by -1.
4151
 
    Or to remove certain changes on a hunk-by-hunk basis, see the Shelf plugin.
 
4310
    merge instead.  For example, "merge . -r -2..-3" (don't forget the ".")
 
4311
    will remove the changes introduced by the second last commit (-2), without
 
4312
    affecting the changes introduced by the last commit (-1).  To remove
 
4313
    certain changes on a hunk-by-hunk basis, see the shelve command.
4152
4314
 
4153
4315
    By default, any files that have been manually changed will be backed up
4154
4316
    first.  (Files changed only by merge are not backed up.)  Backup files have
4184
4346
    target branches.
4185
4347
    """
4186
4348
 
4187
 
    _see_also = ['cat', 'export']
 
4349
    _see_also = ['cat', 'export', 'merge', 'shelve']
4188
4350
    takes_options = [
4189
4351
        'revision',
4190
4352
        Option('no-backup', "Do not save backups of reverted files."),
4483
4645
 
4484
4646
    @display_command
4485
4647
    def run(self, verbose=False):
4486
 
        import bzrlib.plugin
4487
 
        from inspect import getdoc
4488
 
        result = []
4489
 
        for name, plugin in bzrlib.plugin.plugins().items():
4490
 
            version = plugin.__version__
4491
 
            if version == 'unknown':
4492
 
                version = ''
4493
 
            name_ver = '%s %s' % (name, version)
4494
 
            d = getdoc(plugin.module)
4495
 
            if d:
4496
 
                doc = d.split('\n')[0]
4497
 
            else:
4498
 
                doc = '(no description)'
4499
 
            result.append((name_ver, doc, plugin.path()))
4500
 
        for name_ver, doc, path in sorted(result):
4501
 
            self.outf.write("%s\n" % name_ver)
4502
 
            self.outf.write("   %s\n" % doc)
4503
 
            if verbose:
4504
 
                self.outf.write("   %s\n" % path)
4505
 
            self.outf.write("\n")
 
4648
        from bzrlib import plugin
 
4649
        # Don't give writelines a generator as some codecs don't like that
 
4650
        self.outf.writelines(
 
4651
            list(plugin.describe_plugins(show_paths=verbose)))
4506
4652
 
4507
4653
 
4508
4654
class cmd_testament(Command):
4561
4707
    @display_command
4562
4708
    def run(self, filename, all=False, long=False, revision=None,
4563
4709
            show_ids=False, directory=None):
4564
 
        from bzrlib.annotate import annotate_file, annotate_file_tree
 
4710
        from bzrlib.annotate import (
 
4711
            annotate_file_tree,
 
4712
            )
4565
4713
        wt, branch, relpath = \
4566
4714
            _open_directory_or_containing_tree_or_branch(filename, directory)
4567
4715
        if wt is not None:
4570
4718
            self.add_cleanup(branch.lock_read().unlock)
4571
4719
        tree = _get_one_revision_tree('annotate', revision, branch=branch)
4572
4720
        self.add_cleanup(tree.lock_read().unlock)
4573
 
        if wt is not None:
 
4721
        if wt is not None and revision is None:
4574
4722
            file_id = wt.path2id(relpath)
4575
4723
        else:
4576
4724
            file_id = tree.path2id(relpath)
4577
4725
        if file_id is None:
4578
4726
            raise errors.NotVersionedError(filename)
4579
 
        file_version = tree.inventory[file_id].revision
4580
4727
        if wt is not None and revision is None:
4581
4728
            # If there is a tree and we're not annotating historical
4582
4729
            # versions, annotate the working tree's content.
4583
4730
            annotate_file_tree(wt, file_id, self.outf, long, all,
4584
4731
                show_ids=show_ids)
4585
4732
        else:
4586
 
            annotate_file(branch, file_version, file_id, long, all, self.outf,
4587
 
                          show_ids=show_ids)
 
4733
            annotate_file_tree(tree, file_id, self.outf, long, all,
 
4734
                show_ids=show_ids, branch=branch)
4588
4735
 
4589
4736
 
4590
4737
class cmd_re_sign(Command):
4841
4988
    takes_options = [
4842
4989
        Option('config',
4843
4990
               help='LOCATION is the directory where the config lock is.'),
 
4991
        Option('force',
 
4992
            help='Do not ask for confirmation before breaking the lock.'),
4844
4993
        ]
4845
4994
 
4846
 
    def run(self, location=None, config=False):
 
4995
    def run(self, location=None, config=False, force=False):
4847
4996
        if location is None:
4848
4997
            location = u'.'
 
4998
        if force:
 
4999
            ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
 
5000
                None,
 
5001
                {'bzrlib.lockdir.break': True})
4849
5002
        if config:
4850
5003
            conf = _mod_config.LockableConfig(file_name=location)
4851
5004
            conf.break_lock()
5141
5294
    source branch defaults to that containing the working directory, but can
5142
5295
    be changed using --from.
5143
5296
 
 
5297
    Both the submit branch and the public branch follow the usual behavior with
 
5298
    respect to --remember: If there is no default location set, the first send
 
5299
    will set it (use --no-remember to avoid settting it). After that, you can
 
5300
    omit the location to use the default.  To change the default, use
 
5301
    --remember. The value will only be saved if the location can be accessed.
 
5302
 
5144
5303
    In order to calculate those changes, bzr must analyse the submit branch.
5145
5304
    Therefore it is most efficient for the submit branch to be a local mirror.
5146
5305
    If a public location is known for the submit_branch, that location is used
5215
5374
        ]
5216
5375
 
5217
5376
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5218
 
            no_patch=False, revision=None, remember=False, output=None,
 
5377
            no_patch=False, revision=None, remember=None, output=None,
5219
5378
            format=None, mail_to=None, message=None, body=None,
5220
5379
            strict=None, **kwargs):
5221
5380
        from bzrlib.send import send
5347
5506
            if tag_name is None:
5348
5507
                raise errors.BzrCommandError("No tag specified to delete.")
5349
5508
            branch.tags.delete_tag(tag_name)
5350
 
            self.outf.write('Deleted tag %s.\n' % tag_name)
 
5509
            note('Deleted tag %s.' % tag_name)
5351
5510
        else:
5352
5511
            if revision:
5353
5512
                if len(revision) != 1:
5365
5524
            if (not force) and branch.tags.has_tag(tag_name):
5366
5525
                raise errors.TagAlreadyExists(tag_name)
5367
5526
            branch.tags.set_tag(tag_name, revision_id)
5368
 
            self.outf.write('Created tag %s.\n' % tag_name)
 
5527
            note('Created tag %s.' % tag_name)
5369
5528
 
5370
5529
 
5371
5530
class cmd_tags(Command):
5378
5537
    takes_options = [
5379
5538
        custom_help('directory',
5380
5539
            help='Branch whose tags should be displayed.'),
5381
 
        RegistryOption.from_kwargs('sort',
 
5540
        RegistryOption('sort',
5382
5541
            'Sort tags by different criteria.', title='Sorting',
5383
 
            alpha='Sort tags lexicographically (default).',
5384
 
            time='Sort tags chronologically.',
 
5542
            lazy_registry=('bzrlib.tag', 'tag_sort_methods')
5385
5543
            ),
5386
5544
        'show-ids',
5387
5545
        'revision',
5388
5546
    ]
5389
5547
 
5390
5548
    @display_command
5391
 
    def run(self,
5392
 
            directory='.',
5393
 
            sort='alpha',
5394
 
            show_ids=False,
5395
 
            revision=None,
5396
 
            ):
 
5549
    def run(self, directory='.', sort=None, show_ids=False, revision=None):
 
5550
        from bzrlib.tag import tag_sort_methods
5397
5551
        branch, relpath = Branch.open_containing(directory)
5398
5552
 
5399
5553
        tags = branch.tags.get_tag_dict().items()
5408
5562
            # only show revisions between revid1 and revid2 (inclusive)
5409
5563
            tags = [(tag, revid) for tag, revid in tags if
5410
5564
                graph.is_between(revid, revid1, revid2)]
5411
 
        if sort == 'alpha':
5412
 
            tags.sort()
5413
 
        elif sort == 'time':
5414
 
            timestamps = {}
5415
 
            for tag, revid in tags:
5416
 
                try:
5417
 
                    revobj = branch.repository.get_revision(revid)
5418
 
                except errors.NoSuchRevision:
5419
 
                    timestamp = sys.maxint # place them at the end
5420
 
                else:
5421
 
                    timestamp = revobj.timestamp
5422
 
                timestamps[revid] = timestamp
5423
 
            tags.sort(key=lambda x: timestamps[x[1]])
 
5565
        if sort is None:
 
5566
            sort = tag_sort_methods.get()
 
5567
        sort(branch, tags)
5424
5568
        if not show_ids:
5425
5569
            # [ (tag, revid), ... ] -> [ (tag, dotted_revno), ... ]
5426
5570
            for index, (tag, revid) in enumerate(tags):
5428
5572
                    revno = branch.revision_id_to_dotted_revno(revid)
5429
5573
                    if isinstance(revno, tuple):
5430
5574
                        revno = '.'.join(map(str, revno))
5431
 
                except errors.NoSuchRevision:
 
5575
                except (errors.NoSuchRevision, errors.GhostRevisionsHaveNoRevno):
5432
5576
                    # Bad tag data/merges can lead to tagged revisions
5433
5577
                    # which are not in this branch. Fail gracefully ...
5434
5578
                    revno = '?'
5824
5968
            location = "."
5825
5969
        branch = Branch.open_containing(location)[0]
5826
5970
        branch.bzrdir.destroy_branch()
5827
 
        
 
5971
 
5828
5972
 
5829
5973
class cmd_shelve(Command):
5830
5974
    __doc__ = """Temporarily set aside some changes from the current tree.
5849
5993
 
5850
5994
    You can put multiple items on the shelf, and by default, 'unshelve' will
5851
5995
    restore the most recently shelved changes.
 
5996
 
 
5997
    For complicated changes, it is possible to edit the changes in a separate
 
5998
    editor program to decide what the file remaining in the working copy
 
5999
    should look like.  To do this, add the configuration option
 
6000
 
 
6001
        change_editor = PROGRAM @new_path @old_path
 
6002
 
 
6003
    where @new_path is replaced with the path of the new version of the 
 
6004
    file and @old_path is replaced with the path of the old version of 
 
6005
    the file.  The PROGRAM should save the new file with the desired 
 
6006
    contents of the file in the working tree.
 
6007
        
5852
6008
    """
5853
6009
 
5854
6010
    takes_args = ['file*']
5866
6022
        Option('destroy',
5867
6023
               help='Destroy removed changes instead of shelving them.'),
5868
6024
    ]
5869
 
    _see_also = ['unshelve']
 
6025
    _see_also = ['unshelve', 'configuration']
5870
6026
 
5871
6027
    def run(self, revision=None, all=False, file_list=None, message=None,
5872
 
            writer=None, list=False, destroy=False, directory=u'.'):
 
6028
            writer=None, list=False, destroy=False, directory=None):
5873
6029
        if list:
5874
 
            return self.run_for_list()
 
6030
            return self.run_for_list(directory=directory)
5875
6031
        from bzrlib.shelf_ui import Shelver
5876
6032
        if writer is None:
5877
6033
            writer = bzrlib.option.diff_writer_registry.get()
5885
6041
        except errors.UserAbort:
5886
6042
            return 0
5887
6043
 
5888
 
    def run_for_list(self):
5889
 
        tree = WorkingTree.open_containing('.')[0]
 
6044
    def run_for_list(self, directory=None):
 
6045
        if directory is None:
 
6046
            directory = u'.'
 
6047
        tree = WorkingTree.open_containing(directory)[0]
5890
6048
        self.add_cleanup(tree.lock_read().unlock)
5891
6049
        manager = tree.get_shelf_manager()
5892
6050
        shelves = manager.active_shelves()
5951
6109
    """
5952
6110
    takes_options = ['directory',
5953
6111
                     Option('ignored', help='Delete all ignored files.'),
5954
 
                     Option('detritus', help='Delete conflict files, merge'
 
6112
                     Option('detritus', help='Delete conflict files, merge and revert'
5955
6113
                            ' backups, and failed selftest dirs.'),
5956
6114
                     Option('unknown',
5957
6115
                            help='Delete files unknown to bzr (default).'),
6016
6174
            self.outf.write('%s %s\n' % (path, location))
6017
6175
 
6018
6176
 
 
6177
class cmd_export_pot(Command):
 
6178
    __doc__ = """Export command helps and error messages in po format."""
 
6179
 
 
6180
    hidden = True
 
6181
 
 
6182
    def run(self):
 
6183
        from bzrlib.export_pot import export_pot
 
6184
        export_pot(self.outf)
 
6185
 
 
6186
 
6019
6187
def _register_lazy_builtins():
6020
6188
    # register lazy builtins from other modules; called at startup and should
6021
6189
    # be only called once.
6022
6190
    for (name, aliases, module_name) in [
6023
6191
        ('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
 
6192
        ('cmd_config', [], 'bzrlib.config'),
6024
6193
        ('cmd_dpush', [], 'bzrlib.foreign'),
6025
6194
        ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
6026
6195
        ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
6027
6196
        ('cmd_conflicts', [], 'bzrlib.conflicts'),
6028
6197
        ('cmd_sign_my_commits', [], 'bzrlib.sign_my_commits'),
 
6198
        ('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6029
6199
        ]:
6030
6200
        builtin_command_registry.register_lazy(name, aliases, module_name)