/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""builtin brz commands"""
 
17
"""builtin bzr commands"""
18
18
 
19
19
from __future__ import absolute_import
20
20
 
 
21
import os
 
22
 
 
23
import bzrlib.bzrdir
 
24
 
 
25
from bzrlib import lazy_import
 
26
lazy_import.lazy_import(globals(), """
 
27
import cStringIO
21
28
import errno
22
 
import os
23
29
import sys
24
 
 
25
 
import breezy.bzr
26
 
 
27
 
from . import lazy_import
28
 
lazy_import.lazy_import(globals(), """
29
30
import time
30
31
 
31
 
import breezy
32
 
from breezy import (
33
 
    branch as _mod_branch,
 
32
import bzrlib
 
33
from bzrlib import (
34
34
    bugtracker,
35
35
    bundle,
36
 
    cache_utf8,
 
36
    btree_index,
37
37
    controldir,
38
38
    directory_service,
39
39
    delta,
40
40
    config as _mod_config,
41
41
    errors,
42
42
    globbing,
43
 
    gpg,
44
43
    hooks,
45
 
    lazy_regex,
46
44
    log,
47
45
    merge as _mod_merge,
48
46
    merge_directive,
50
48
    reconfigure,
51
49
    rename_map,
52
50
    revision as _mod_revision,
53
 
    symbol_versioning,
 
51
    static_tuple,
54
52
    timestamp,
55
53
    transport,
56
 
    tree as _mod_tree,
57
54
    ui,
58
55
    urlutils,
59
56
    views,
 
57
    gpg,
60
58
    )
61
 
from breezy.branch import Branch
62
 
from breezy.conflicts import ConflictList
63
 
from breezy.transport import memory
64
 
from breezy.smtp_connection import SMTPConnection
65
 
from breezy.workingtree import WorkingTree
66
 
from breezy.i18n import gettext, ngettext
 
59
from bzrlib.branch import Branch
 
60
from bzrlib.conflicts import ConflictList
 
61
from bzrlib.transport import memory
 
62
from bzrlib.revisionspec import RevisionSpec, RevisionInfo
 
63
from bzrlib.smtp_connection import SMTPConnection
 
64
from bzrlib.workingtree import WorkingTree
 
65
from bzrlib.i18n import gettext, ngettext
67
66
""")
68
67
 
69
 
from .commands import (
 
68
from bzrlib.commands import (
70
69
    Command,
71
70
    builtin_command_registry,
72
71
    display_command,
73
72
    )
74
 
from .option import (
 
73
from bzrlib.option import (
75
74
    ListOption,
76
75
    Option,
77
76
    RegistryOption,
78
77
    custom_help,
79
78
    _parse_revision_str,
80
79
    )
81
 
from .revisionspec import (
82
 
    RevisionSpec,
83
 
    RevisionInfo,
 
80
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
 
81
from bzrlib import (
 
82
    symbol_versioning,
84
83
    )
85
 
from .sixish import (
86
 
    BytesIO,
87
 
    text_type,
88
 
    viewitems,
89
 
    viewvalues,
90
 
)
91
 
from .trace import mutter, note, warning, is_quiet, get_verbosity_level
92
84
 
93
85
 
94
86
def _get_branch_location(control_dir, possible_transports=None):
207
199
        reference = control_dir.get_branch_reference()
208
200
    except errors.NotBranchError:
209
201
        # There is no active branch, just return the colocated branches.
210
 
        for name, branch in viewitems(control_dir.get_branches()):
 
202
        for name, branch in control_dir.get_branches().iteritems():
211
203
            yield name, branch
212
204
        return
213
205
    if reference is not None:
217
209
        ref_branch = None
218
210
    if ref_branch is None or ref_branch.name:
219
211
        if ref_branch is not None:
220
 
            control_dir = ref_branch.controldir
221
 
        for name, branch in viewitems(control_dir.get_branches()):
 
212
            control_dir = ref_branch.bzrdir
 
213
        for name, branch in control_dir.get_branches().iteritems():
222
214
            yield name, branch
223
215
    else:
224
 
        repo = ref_branch.controldir.find_repository()
 
216
        repo = ref_branch.bzrdir.find_repository()
225
217
        for branch in repo.find_branches(using=True):
226
218
            name = urlutils.relative_url(repo.user_url,
227
219
                branch.user_url).rstrip("/")
246
238
            if view_files:
247
239
                for filename in file_list:
248
240
                    if not osutils.is_inside_any(view_files, filename):
249
 
                        raise views.FileOutsideView(filename, view_files)
 
241
                        raise errors.FileOutsideView(filename, view_files)
250
242
        file_list = file_list[:]
251
243
        file_list[0] = tree.abspath(relpath)
252
244
    else:
265
257
        return None
266
258
    if len(revisions) != 1:
267
259
        raise errors.BzrCommandError(gettext(
268
 
            'brz %s --revision takes exactly one revision identifier') % (
 
260
            'bzr %s --revision takes exactly one revision identifier') % (
269
261
                command_name,))
270
262
    return revisions[0]
271
263
 
300
292
        current_view = tree.views.get_view_info()[0]
301
293
        if current_view is not None:
302
294
            view_info = (current_view, tree.views.lookup_view())
303
 
    except views.ViewsNotSupported:
 
295
    except errors.ViewsNotSupported:
304
296
        pass
305
297
    return view_info
306
298
 
351
343
    character: '/', '@' or '*' respectively. These decorations can be
352
344
    disabled using the '--no-classify' option.
353
345
 
354
 
    To see ignored files use 'brz ignored'.  For details on the
355
 
    changes to file texts, use 'brz diff'.
 
346
    To see ignored files use 'bzr ignored'.  For details on the
 
347
    changes to file texts, use 'bzr diff'.
356
348
 
357
349
    Note that --short or -S gives status flags for each item, similar
358
350
    to Subversion's status command. To get output similar to svn -q,
359
 
    use brz status -SV.
 
351
    use bzr status -SV.
360
352
 
361
353
    If no arguments are specified, the status of the entire working
362
354
    directory is shown.  Otherwise, only the status of the specified
373
365
 
374
366
    To see which files have changed in a specific revision, or between
375
367
    two revisions, pass a revision range to the revision argument.
376
 
    This will produce the same results as calling 'brz diff --summarize'.
 
368
    This will produce the same results as calling 'bzr diff --summarize'.
377
369
    """
378
370
 
379
371
    # TODO: --no-recurse/-N, --recurse options
399
391
    def run(self, show_ids=False, file_list=None, revision=None, short=False,
400
392
            versioned=False, no_pending=False, verbose=False,
401
393
            no_classify=False):
402
 
        from .status import show_tree_status
 
394
        from bzrlib.status import show_tree_status
403
395
 
404
396
        if revision and len(revision) > 2:
405
 
            raise errors.BzrCommandError(gettext('brz status --revision takes exactly'
 
397
            raise errors.BzrCommandError(gettext('bzr status --revision takes exactly'
406
398
                                         ' one or two revision specifiers'))
407
399
 
408
400
        tree, relfile_list = WorkingTree.open_containing_paths(file_list)
437
429
 
438
430
    def print_revision(self, revisions, revid):
439
431
        stream = revisions.get_record_stream([(revid,)], 'unordered', True)
440
 
        record = next(stream)
 
432
        record = stream.next()
441
433
        if record.storage_kind == 'absent':
442
434
            raise errors.NoSuchRevision(revisions, revid)
443
435
        revtext = record.get_bytes_as('fulltext')
459
451
            raise errors.BzrCommandError(gettext('Repository %r does not support '
460
452
                'access to raw revision texts'))
461
453
 
462
 
        with b.repository.lock_read():
 
454
        b.repository.lock_read()
 
455
        try:
463
456
            # TODO: jam 20060112 should cat-revision always output utf-8?
464
457
            if revision_id is not None:
465
 
                revision_id = cache_utf8.encode(revision_id)
 
458
                revision_id = osutils.safe_revision_id(revision_id, warn=False)
466
459
                try:
467
460
                    self.print_revision(revisions, revision_id)
468
461
                except errors.NoSuchRevision:
476
469
                            gettext('You cannot specify a NULL revision.'))
477
470
                    rev_id = rev.as_revision_id(b)
478
471
                    self.print_revision(revisions, rev_id)
 
472
        finally:
 
473
            b.repository.unlock()
 
474
        
 
475
 
 
476
class cmd_dump_btree(Command):
 
477
    __doc__ = """Dump the contents of a btree index file to stdout.
 
478
 
 
479
    PATH is a btree index file, it can be any URL. This includes things like
 
480
    .bzr/repository/pack-names, or .bzr/repository/indices/a34b3a...ca4a4.iix
 
481
 
 
482
    By default, the tuples stored in the index file will be displayed. With
 
483
    --raw, we will uncompress the pages, but otherwise display the raw bytes
 
484
    stored in the index.
 
485
    """
 
486
 
 
487
    # TODO: Do we want to dump the internal nodes as well?
 
488
    # TODO: It would be nice to be able to dump the un-parsed information,
 
489
    #       rather than only going through iter_all_entries. However, this is
 
490
    #       good enough for a start
 
491
    hidden = True
 
492
    encoding_type = 'exact'
 
493
    takes_args = ['path']
 
494
    takes_options = [Option('raw', help='Write the uncompressed bytes out,'
 
495
                                        ' rather than the parsed tuples.'),
 
496
                    ]
 
497
 
 
498
    def run(self, path, raw=False):
 
499
        dirname, basename = osutils.split(path)
 
500
        t = transport.get_transport(dirname)
 
501
        if raw:
 
502
            self._dump_raw_bytes(t, basename)
 
503
        else:
 
504
            self._dump_entries(t, basename)
 
505
 
 
506
    def _get_index_and_bytes(self, trans, basename):
 
507
        """Create a BTreeGraphIndex and raw bytes."""
 
508
        bt = btree_index.BTreeGraphIndex(trans, basename, None)
 
509
        bytes = trans.get_bytes(basename)
 
510
        bt._file = cStringIO.StringIO(bytes)
 
511
        bt._size = len(bytes)
 
512
        return bt, bytes
 
513
 
 
514
    def _dump_raw_bytes(self, trans, basename):
 
515
        import zlib
 
516
 
 
517
        # We need to parse at least the root node.
 
518
        # This is because the first page of every row starts with an
 
519
        # uncompressed header.
 
520
        bt, bytes = self._get_index_and_bytes(trans, basename)
 
521
        for page_idx, page_start in enumerate(xrange(0, len(bytes),
 
522
                                                     btree_index._PAGE_SIZE)):
 
523
            page_end = min(page_start + btree_index._PAGE_SIZE, len(bytes))
 
524
            page_bytes = bytes[page_start:page_end]
 
525
            if page_idx == 0:
 
526
                self.outf.write('Root node:\n')
 
527
                header_end, data = bt._parse_header_from_bytes(page_bytes)
 
528
                self.outf.write(page_bytes[:header_end])
 
529
                page_bytes = data
 
530
            self.outf.write('\nPage %d\n' % (page_idx,))
 
531
            if len(page_bytes) == 0:
 
532
                self.outf.write('(empty)\n');
 
533
            else:
 
534
                decomp_bytes = zlib.decompress(page_bytes)
 
535
                self.outf.write(decomp_bytes)
 
536
                self.outf.write('\n')
 
537
 
 
538
    def _dump_entries(self, trans, basename):
 
539
        try:
 
540
            st = trans.stat(basename)
 
541
        except errors.TransportNotPossible:
 
542
            # We can't stat, so we'll fake it because we have to do the 'get()'
 
543
            # anyway.
 
544
            bt, _ = self._get_index_and_bytes(trans, basename)
 
545
        else:
 
546
            bt = btree_index.BTreeGraphIndex(trans, basename, st.st_size)
 
547
        for node in bt.iter_all_entries():
 
548
            # Node is made up of:
 
549
            # (index, key, value, [references])
 
550
            try:
 
551
                refs = node[3]
 
552
            except IndexError:
 
553
                refs_as_tuples = None
 
554
            else:
 
555
                refs_as_tuples = static_tuple.as_tuples(refs)
 
556
            as_tuple = (tuple(node[1]), node[2], refs_as_tuples)
 
557
            self.outf.write('%s\n' % (as_tuple,))
479
558
 
480
559
 
481
560
class cmd_remove_tree(Command):
484
563
    Since a lightweight checkout is little more than a working tree
485
564
    this will refuse to run against one.
486
565
 
487
 
    To re-create the working tree, use "brz checkout".
 
566
    To re-create the working tree, use "bzr checkout".
488
567
    """
489
568
    _see_also = ['checkout', 'working-trees']
490
569
    takes_args = ['location*']
529
608
    'known good' state. Any new modifications (adding a file, renaming, etc)
530
609
    will be lost, though modified files will still be detected as such.
531
610
 
532
 
    Most users will want something more like "brz revert" or "brz update"
 
611
    Most users will want something more like "bzr revert" or "bzr update"
533
612
    unless the state file has become corrupted.
534
613
 
535
614
    By default this attempts to recover the current state by looking at the
556
635
                # Refuse
557
636
                raise errors.BzrCommandError(gettext(
558
637
                    'The tree does not appear to be corrupt. You probably'
559
 
                    ' want "brz revert" instead. Use "--force" if you are'
 
638
                    ' want "bzr revert" instead. Use "--force" if you are'
560
639
                    ' sure you want to reset the working tree.'))
561
640
        if revision is None:
562
641
            revision_ids = None
564
643
            revision_ids = [r.as_revision_id(tree.branch) for r in revision]
565
644
        try:
566
645
            tree.reset_state(revision_ids)
567
 
        except errors.BzrError as e:
 
646
        except errors.BzrError, e:
568
647
            if revision_ids is None:
569
648
                extra = (gettext(', the header appears corrupt, try passing -r -1'
570
649
                         ' to set the state to the last commit'))
695
774
    A warning will be printed when nested trees are encountered,
696
775
    unless they are explicitly ignored.
697
776
 
698
 
    Therefore simply saying 'brz add' will version all files that
 
777
    Therefore simply saying 'bzr add' will version all files that
699
778
    are currently unknown.
700
779
 
701
780
    Adding a file whose parent directory is not versioned will
730
809
               help="Show what would be done, but don't actually do anything."),
731
810
        'verbose',
732
811
        Option('file-ids-from',
733
 
               type=text_type,
 
812
               type=unicode,
734
813
               help='Lookup file ids from this tree.'),
735
814
        ]
736
815
    encoding_type = 'replace'
738
817
 
739
818
    def run(self, file_list, no_recurse=False, dry_run=False, verbose=False,
740
819
            file_ids_from=None):
741
 
        import breezy.add
 
820
        import bzrlib.add
742
821
 
743
822
        base_tree = None
744
823
        if file_ids_from is not None:
750
829
                                            file_ids_from)
751
830
                base_tree = base_branch.basis_tree()
752
831
 
753
 
            action = breezy.add.AddFromBaseAction(base_tree, base_path,
 
832
            action = bzrlib.add.AddFromBaseAction(base_tree, base_path,
754
833
                          to_file=self.outf, should_print=(not is_quiet()))
755
834
        else:
756
 
            action = breezy.add.AddWithSkipLargeAction(to_file=self.outf,
 
835
            action = bzrlib.add.AddWithSkipLargeAction(to_file=self.outf,
757
836
                should_print=(not is_quiet()))
758
837
 
759
838
        if base_tree:
764
843
        self.cleanup_now()
765
844
        if len(ignored) > 0:
766
845
            if verbose:
767
 
                for glob in sorted(ignored):
 
846
                for glob in sorted(ignored.keys()):
768
847
                    for path in ignored[glob]:
769
848
                        self.outf.write(
770
849
                         gettext("ignored {0} matching \"{1}\"\n").format(
789
868
 
790
869
    @classmethod
791
870
    def add_file_with_parents(cls, wt, relpath):
792
 
        if wt.is_versioned(relpath):
 
871
        if wt.path2id(relpath) is not None:
793
872
            return
794
873
        cls.add_file_with_parents(wt, osutils.dirname(relpath))
795
874
        wt.add([relpath])
808
887
            if parents:
809
888
                try:
810
889
                    os.makedirs(dir)
811
 
                except OSError as e:
 
890
                except OSError, e:
812
891
                    if e.errno != errno.EEXIST:
813
892
                        raise
814
893
            else:
840
919
    type using the --kind option.  For example: --kind file.
841
920
 
842
921
    It is also possible to restrict the list of files to a specific
843
 
    set. For example: brz inventory --show-ids this/file
 
922
    set. For example: bzr inventory --show-ids this/file
844
923
    """
845
924
 
846
925
    hidden = True
850
929
        'show-ids',
851
930
        Option('kind',
852
931
               help='List entries of a particular kind: file, directory, symlink.',
853
 
               type=text_type),
 
932
               type=unicode),
854
933
        ]
855
934
    takes_args = ['file*']
856
935
 
873
952
 
874
953
        self.add_cleanup(tree.lock_read().unlock)
875
954
        if file_list is not None:
876
 
            paths = tree.find_related_paths_across_trees(
877
 
                    file_list, extra_trees, require_versioned=True)
 
955
            file_ids = tree.paths2ids(file_list, trees=extra_trees,
 
956
                                      require_versioned=True)
878
957
            # find_ids_across_trees may include some paths that don't
879
958
            # exist in 'tree'.
880
 
            entries = tree.iter_entries_by_dir(specific_files=paths)
 
959
            entries = tree.iter_entries_by_dir(specific_file_ids=file_ids)
881
960
        else:
882
961
            entries = tree.iter_entries_by_dir()
883
962
 
893
972
                self.outf.write('\n')
894
973
 
895
974
 
896
 
class cmd_cp(Command):
897
 
    __doc__ = """Copy a file.
898
 
 
899
 
    :Usage:
900
 
        brz cp OLDNAME NEWNAME
901
 
 
902
 
        brz cp SOURCE... DESTINATION
903
 
 
904
 
    If the last argument is a versioned directory, all the other names
905
 
    are copied into it.  Otherwise, there must be exactly two arguments
906
 
    and the file is copied to a new name.
907
 
 
908
 
    Files cannot be copied between branches. Only files can be copied
909
 
    at the moment.
910
 
    """
911
 
 
912
 
    takes_args = ['names*']
913
 
    takes_options = []
914
 
    aliases = ['copy']
915
 
    encoding_type = 'replace'
916
 
 
917
 
    def run(self, names_list):
918
 
        import shutil
919
 
        if names_list is None:
920
 
            names_list = []
921
 
        if len(names_list) < 2:
922
 
            raise errors.BzrCommandError(gettext("missing file argument"))
923
 
        tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
924
 
        for file_name in rel_names[0:-1]:
925
 
            if file_name == '':
926
 
                raise errors.BzrCommandError(gettext("can not copy root of branch"))
927
 
        self.add_cleanup(tree.lock_tree_write().unlock)
928
 
        into_existing = osutils.isdir(names_list[-1])
929
 
        if not into_existing:
930
 
            try:
931
 
                (src, dst) = rel_names
932
 
            except IndexError:
933
 
                raise errors.BzrCommandError(gettext('to copy multiple files the'
934
 
                                                     ' destination must be a versioned'
935
 
                                                     ' directory'))
936
 
            pairs = [(src, dst)]
937
 
        else:
938
 
            pairs = [(n, osutils.joinpath([rel_names[-1], osutils.basename(n)]))
939
 
                     for n in rel_names[:-1]]
940
 
 
941
 
        for src, dst in pairs:
942
 
            try:
943
 
                src_kind = tree.stored_kind(src)
944
 
            except errors.NoSuchFile:
945
 
                raise errors.BzrCommandError(
946
 
                        gettext('Could not copy %s => %s: %s is not versioned.')
947
 
                        % (src, dst, src))
948
 
            if src_kind is None:
949
 
                raise errors.BzrCommandError(
950
 
                    gettext('Could not copy %s => %s . %s is not versioned\.'
951
 
                        % (src, dst, src)))
952
 
            if src_kind == 'directory':
953
 
                raise errors.BzrCommandError(
954
 
                    gettext('Could not copy %s => %s . %s is a directory.'
955
 
                        % (src, dst, src)))
956
 
            dst_parent = osutils.split(dst)[0]
957
 
            if dst_parent != '':
958
 
                try:
959
 
                    dst_parent_kind = tree.stored_kind(dst_parent)
960
 
                except errors.NoSuchFile:
961
 
                    raise errors.BzrCommandError(
962
 
                            gettext('Could not copy %s => %s: %s is not versioned.')
963
 
                            % (src, dst, dst_parent))
964
 
                if dst_parent_kind != 'directory':
965
 
                    raise errors.BzrCommandError(
966
 
                            gettext('Could not copy to %s: %s is not a directory.')
967
 
                            % (dst_parent, dst_parent))
968
 
 
969
 
            tree.copy_one(src, dst)
970
 
 
971
 
 
972
975
class cmd_mv(Command):
973
976
    __doc__ = """Move or rename a file.
974
977
 
975
978
    :Usage:
976
 
        brz mv OLDNAME NEWNAME
 
979
        bzr mv OLDNAME NEWNAME
977
980
 
978
 
        brz mv SOURCE... DESTINATION
 
981
        bzr mv SOURCE... DESTINATION
979
982
 
980
983
    If the last argument is a versioned directory, all the other names
981
984
    are moved into it.  Otherwise, there must be exactly two arguments
991
994
    """
992
995
 
993
996
    takes_args = ['names*']
994
 
    takes_options = [Option("after", help="Move only the brz identifier"
 
997
    takes_options = [Option("after", help="Move only the bzr identifier"
995
998
        " of the file, because the file has already been moved."),
996
999
        Option('auto', help='Automatically guess renames.'),
997
1000
        Option('dry-run', help='Avoid making changes when guessing renames.'),
1025
1028
        work_tree, file_list = WorkingTree.open_containing_paths(
1026
1029
            names_list, default_directory='.')
1027
1030
        self.add_cleanup(work_tree.lock_tree_write().unlock)
1028
 
        rename_map.RenameMap.guess_renames(
1029
 
                work_tree.basis_tree(), work_tree, dry_run)
 
1031
        rename_map.RenameMap.guess_renames(work_tree, dry_run)
1030
1032
 
1031
1033
    def _run(self, tree, names_list, rel_names, after):
1032
1034
        into_existing = osutils.isdir(names_list[-1])
1041
1043
                into_existing = False
1042
1044
            else:
1043
1045
                # 'fix' the case of a potential 'from'
1044
 
                from_path = tree.get_canonical_inventory_path(rel_names[0])
 
1046
                from_id = tree.path2id(
 
1047
                            tree.get_canonical_inventory_path(rel_names[0]))
1045
1048
                if (not osutils.lexists(names_list[0]) and
1046
 
                    tree.is_versioned(from_path) and
1047
 
                    tree.stored_kind(from_path) == "directory"):
 
1049
                    from_id and tree.stored_kind(from_id) == "directory"):
1048
1050
                    into_existing = False
1049
1051
        # move/rename
1050
1052
        if into_existing:
1116
1118
    commit is one that has not been merged (directly or indirectly) into the 
1117
1119
    parent.
1118
1120
 
1119
 
    If branches have diverged, you can use 'brz merge' to integrate the changes
 
1121
    If branches have diverged, you can use 'bzr merge' to integrate the changes
1120
1122
    from one into the other.  Once one branch has merged, the other should
1121
1123
    be able to pull it again.
1122
1124
 
1135
1137
 
1136
1138
    Note: The location can be specified either in the form of a branch,
1137
1139
    or in the form of a path to a file containing a merge directive generated
1138
 
    with brz send.
 
1140
    with bzr send.
1139
1141
    """
1140
1142
 
1141
1143
    _see_also = ['push', 'update', 'status-flags', 'send']
1267
1269
    considered diverged if the destination branch's most recent commit is one
1268
1270
    that has not been merged (directly or indirectly) by the source branch.
1269
1271
 
1270
 
    If branches have diverged, you can use 'brz push --overwrite' to replace
 
1272
    If branches have diverged, you can use 'bzr push --overwrite' to replace
1271
1273
    the other branch completely, discarding its unmerged changes.
1272
1274
 
1273
1275
    If you want to ensure you have the different changes in the other branch,
1274
 
    do a merge (see brz help merge) from the other branch, and commit that.
 
1276
    do a merge (see bzr help merge) from the other branch, and commit that.
1275
1277
    After that you will be able to do a push without '--overwrite'.
1276
1278
 
1277
1279
    If there is no default push location set, the first push will set it (use
1304
1306
            help='Create a stacked branch that refers to another branch '
1305
1307
                'for the commit history. Only the work not present in the '
1306
1308
                'referenced branch is included in the branch created.',
1307
 
            type=text_type),
 
1309
            type=unicode),
1308
1310
        Option('strict',
1309
1311
               help='Refuse to push if there are uncommitted changes in'
1310
1312
               ' the working tree, --no-strict disables the check.'),
1313
1315
               " that support it."),
1314
1316
        Option('overwrite-tags',
1315
1317
              help="Overwrite tags only."),
1316
 
        Option('lossy', help="Allow lossy push, i.e. dropping metadata "
1317
 
                             "that can't be represented in the target.")
1318
1318
        ]
1319
1319
    takes_args = ['location?']
1320
1320
    encoding_type = 'replace'
1323
1323
        create_prefix=False, verbose=False, revision=None,
1324
1324
        use_existing_dir=False, directory=None, stacked_on=None,
1325
1325
        stacked=False, strict=None, no_tree=False,
1326
 
        overwrite_tags=False, lossy=False):
1327
 
        from .push import _show_push_branch
 
1326
        overwrite_tags=False):
 
1327
        from bzrlib.push import _show_push_branch
1328
1328
 
1329
1329
        if overwrite:
1330
1330
            overwrite = ["history", "tags"]
1375
1375
                if parent_loc:
1376
1376
                    raise errors.BzrCommandError(gettext(
1377
1377
                        "No push location known or specified. To push to the "
1378
 
                        "parent branch (at %s), use 'brz push :parent'." %
 
1378
                        "parent branch (at %s), use 'bzr push :parent'." %
1379
1379
                        urlutils.unescape_for_display(parent_loc,
1380
1380
                            self.outf.encoding)))
1381
1381
                else:
1390
1390
        _show_push_branch(br_from, revision_id, location, self.outf,
1391
1391
            verbose=verbose, overwrite=overwrite, remember=remember,
1392
1392
            stacked_on=stacked_on, create_prefix=create_prefix,
1393
 
            use_existing_dir=use_existing_dir, no_tree=no_tree,
1394
 
            lossy=lossy)
 
1393
            use_existing_dir=use_existing_dir, no_tree=no_tree)
1395
1394
 
1396
1395
 
1397
1396
class cmd_branch(Command):
1406
1405
 
1407
1406
    To retrieve the branch as of a particular revision, supply the --revision
1408
1407
    parameter, as in "branch foo/bar -r 5".
 
1408
 
 
1409
    The synonyms 'clone' and 'get' for this command are deprecated.
1409
1410
    """
1410
1411
 
1411
1412
    _see_also = ['checkout']
1412
1413
    takes_args = ['from_location', 'to_location?']
1413
1414
    takes_options = ['revision',
1414
1415
        Option('hardlink', help='Hard-link working tree files where possible.'),
1415
 
        Option('files-from', type=text_type,
 
1416
        Option('files-from', type=str,
1416
1417
               help="Get file contents from this tree."),
1417
1418
        Option('no-tree',
1418
1419
            help="Create a branch without a working-tree."),
1433
1434
        Option('bind',
1434
1435
            help="Bind new branch to from location."),
1435
1436
        ]
 
1437
    aliases = ['get', 'clone']
1436
1438
 
1437
1439
    def run(self, from_location, to_location=None, revision=None,
1438
1440
            hardlink=False, stacked=False, standalone=False, no_tree=False,
1439
1441
            use_existing_dir=False, switch=False, bind=False,
1440
1442
            files_from=None):
1441
 
        from breezy import switch as _mod_switch
 
1443
        from bzrlib import switch as _mod_switch
 
1444
        from bzrlib.tag import _merge_tags_if_possible
 
1445
        if self.invoked_as in ['get', 'clone']:
 
1446
            ui.ui_factory.show_user_warning(
 
1447
                'deprecated_command',
 
1448
                deprecated_name=self.invoked_as,
 
1449
                recommended_name='branch',
 
1450
                deprecated_in_version='2.4')
1442
1451
        accelerator_tree, br_from = controldir.ControlDir.open_tree_or_branch(
1443
1452
            from_location)
1444
1453
        if not (hardlink or files_from):
1489
1498
        if to_dir is None:
1490
1499
            try:
1491
1500
                # preserve whatever source format we have.
1492
 
                to_dir = br_from.controldir.sprout(
1493
 
                    to_transport.base, revision_id,
1494
 
                    possible_transports=[to_transport],
1495
 
                    accelerator_tree=accelerator_tree, hardlink=hardlink,
1496
 
                    stacked=stacked, force_new_repo=standalone,
1497
 
                    create_tree_if_local=not no_tree, source_branch=br_from)
 
1501
                to_dir = br_from.bzrdir.sprout(to_transport.base, revision_id,
 
1502
                                            possible_transports=[to_transport],
 
1503
                                            accelerator_tree=accelerator_tree,
 
1504
                                            hardlink=hardlink, stacked=stacked,
 
1505
                                            force_new_repo=standalone,
 
1506
                                            create_tree_if_local=not no_tree,
 
1507
                                            source_branch=br_from)
1498
1508
                branch = to_dir.open_branch(
1499
1509
                    possible_transports=[
1500
 
                        br_from.controldir.root_transport, to_transport])
 
1510
                        br_from.bzrdir.root_transport, to_transport])
1501
1511
            except errors.NoSuchRevision:
1502
1512
                to_transport.delete_tree('.')
1503
1513
                msg = gettext("The branch {0} has no revision {1}.").format(
1510
1520
                to_repo = to_dir.create_repository()
1511
1521
            to_repo.fetch(br_from.repository, revision_id=revision_id)
1512
1522
            branch = br_from.sprout(to_dir, revision_id=revision_id)
1513
 
        br_from.tags.merge_to(branch.tags)
1514
 
 
 
1523
        _merge_tags_if_possible(br_from, branch)
1515
1524
        # If the source branch is stacked, the new branch may
1516
1525
        # be stacked whether we asked for that explicitly or not.
1517
1526
        # We therefore need a try/except here and not just 'if stacked:'
1518
1527
        try:
1519
1528
            note(gettext('Created new stacked branch referring to %s.') %
1520
1529
                branch.get_stacked_on_url())
1521
 
        except (errors.NotStacked, _mod_branch.UnstackableBranchFormat,
1522
 
            errors.UnstackableRepositoryFormat) as e:
 
1530
        except (errors.NotStacked, errors.UnstackableBranchFormat,
 
1531
            errors.UnstackableRepositoryFormat), e:
1523
1532
            note(ngettext('Branched %d revision.', 'Branched %d revisions.', branch.revno()) % branch.revno())
1524
1533
        if bind:
1525
1534
            # Bind to the parent
1529
1538
        if switch:
1530
1539
            # Switch to the new branch
1531
1540
            wt, _ = WorkingTree.open_containing('.')
1532
 
            _mod_switch.switch(wt.controldir, branch)
 
1541
            _mod_switch.switch(wt.bzrdir, branch)
1533
1542
            note(gettext('Switched to branch: %s'),
1534
1543
                urlutils.unescape_for_display(branch.base, 'utf-8'))
1535
1544
 
1568
1577
                if name == "":
1569
1578
                    continue
1570
1579
                active = (active_branch is not None and
1571
 
                          active_branch.user_url == branch.user_url)
 
1580
                          active_branch.base == branch.base)
1572
1581
                names[name] = active
1573
1582
            # Only mention the current branch explicitly if it's not
1574
1583
            # one of the colocated branches
1575
 
            if not any(viewvalues(names)) and active_branch is not None:
 
1584
            if not any(names.values()) and active_branch is not None:
1576
1585
                self.outf.write("* %s\n" % gettext("(default)"))
1577
 
            for name in sorted(names):
 
1586
            for name in sorted(names.keys()):
1578
1587
                active = names[name]
1579
1588
                if active:
1580
1589
                    prefix = "*"
1615
1624
                                 "common operations like diff and status without "
1616
1625
                                 "such access, and also support local commits."
1617
1626
                            ),
1618
 
                     Option('files-from', type=text_type,
 
1627
                     Option('files-from', type=str,
1619
1628
                            help="Get file contents from this tree."),
1620
1629
                     Option('hardlink',
1621
1630
                            help='Hard-link working tree files where possible.'
1650
1659
        if (osutils.abspath(to_location) ==
1651
1660
            osutils.abspath(branch_location)):
1652
1661
            try:
1653
 
                source.controldir.open_workingtree()
 
1662
                source.bzrdir.open_workingtree()
1654
1663
            except errors.NoWorkingTree:
1655
 
                source.controldir.create_workingtree(revision_id)
 
1664
                source.bzrdir.create_workingtree(revision_id)
1656
1665
                return
1657
1666
        source.create_checkout(to_location, revision_id, lightweight,
1658
1667
                               accelerator_tree, hardlink)
1698
1707
    
1699
1708
    If there are any uncommitted changes in the tree, they will be carried
1700
1709
    across and remain as uncommitted changes after the update.  To discard
1701
 
    these changes, use 'brz revert'.  The uncommitted changes may conflict
 
1710
    these changes, use 'bzr revert'.  The uncommitted changes may conflict
1702
1711
    with the changes brought in by the change in basis revision.
1703
1712
 
1704
 
    If the tree's branch is bound to a master branch, brz will also update
 
1713
    If the tree's branch is bound to a master branch, bzr will also update
1705
1714
    the branch from the master.
1706
1715
 
1707
1716
    You cannot update just a single file or directory, because each Bazaar
1708
1717
    working tree has just a single basis revision.  If you want to restore a
1709
 
    file that has been removed locally, use 'brz revert' instead of 'brz
 
1718
    file that has been removed locally, use 'bzr revert' instead of 'bzr
1710
1719
    update'.  If you want to restore a file to its state in a previous
1711
 
    revision, use 'brz revert' with a '-r' option, or use 'brz cat' to write
 
1720
    revision, use 'bzr revert' with a '-r' option, or use 'bzr cat' to write
1712
1721
    out the old content of that file to a new location.
1713
1722
 
1714
1723
    The 'dir' argument, if given, must be the location of the root of a
1727
1736
    def run(self, dir=None, revision=None, show_base=None):
1728
1737
        if revision is not None and len(revision) != 1:
1729
1738
            raise errors.BzrCommandError(gettext(
1730
 
                "brz update --revision takes exactly one revision"))
 
1739
                "bzr update --revision takes exactly one revision"))
1731
1740
        if dir is None:
1732
1741
            tree = WorkingTree.open_containing('.')[0]
1733
1742
        else:
1735
1744
            if relpath:
1736
1745
                # See bug 557886.
1737
1746
                raise errors.BzrCommandError(gettext(
1738
 
                    "brz update can only update a whole tree, "
 
1747
                    "bzr update can only update a whole tree, "
1739
1748
                    "not a file or subdirectory"))
1740
1749
        branch = tree.branch
1741
1750
        possible_transports = []
1780
1789
                revision=revision_id,
1781
1790
                old_tip=old_tip,
1782
1791
                show_base=show_base)
1783
 
        except errors.NoSuchRevision as e:
 
1792
        except errors.NoSuchRevision, e:
1784
1793
            raise errors.BzrCommandError(gettext(
1785
1794
                                  "branch has no revision %s\n"
1786
 
                                  "brz update --revision only works"
 
1795
                                  "bzr update --revision only works"
1787
1796
                                  " for a revision in the branch history")
1788
1797
                                  % (e.revision))
1789
1798
        revno = tree.branch.revision_id_to_dotted_revno(
1793
1802
        parent_ids = tree.get_parent_ids()
1794
1803
        if parent_ids[1:] and parent_ids[1:] != existing_pending_merges:
1795
1804
            note(gettext('Your local commits will now show as pending merges with '
1796
 
                 "'brz status', and can be committed with 'brz commit'."))
 
1805
                 "'bzr status', and can be committed with 'bzr commit'."))
1797
1806
        if conflicts != 0:
1798
1807
            return 1
1799
1808
        else:
1816
1825
 
1817
1826
      Display information on the format and related locations:
1818
1827
 
1819
 
        brz info
 
1828
        bzr info
1820
1829
 
1821
1830
      Display the above together with extended format information and
1822
1831
      basic statistics (like the number of files in the working tree and
1823
1832
      number of revisions in the branch and repository):
1824
1833
 
1825
 
        brz info -v
 
1834
        bzr info -v
1826
1835
 
1827
1836
      Display the above together with number of committers to the branch:
1828
1837
 
1829
 
        brz info -vv
 
1838
        bzr info -vv
1830
1839
    """
1831
1840
    _see_also = ['revno', 'working-trees', 'repositories']
1832
1841
    takes_args = ['location?']
1839
1848
            noise_level = get_verbosity_level()
1840
1849
        else:
1841
1850
            noise_level = 0
1842
 
        from .info import show_bzrdir_info
 
1851
        from bzrlib.info import show_bzrdir_info
1843
1852
        show_bzrdir_info(controldir.ControlDir.open_containing(location)[0],
1844
1853
                         verbose=noise_level, outfile=self.outf)
1845
1854
 
1860
1869
            'The file deletion mode to be used.',
1861
1870
            title='Deletion Strategy', value_switches=True, enum_switch=False,
1862
1871
            safe='Backup changed files (default).',
1863
 
            keep='Delete from brz but leave the working copy.',
 
1872
            keep='Delete from bzr but leave the working copy.',
1864
1873
            no_backup='Don\'t backup changed files.'),
1865
1874
        ]
1866
1875
    aliases = ['rm', 'del']
1943
1952
 
1944
1953
 
1945
1954
class cmd_reconcile(Command):
1946
 
    __doc__ = """Reconcile brz metadata in a branch.
 
1955
    __doc__ = """Reconcile bzr metadata in a branch.
1947
1956
 
1948
1957
    This can correct data mismatches that may have been caused by
1949
 
    previous ghost operations or brz upgrades. You should only
1950
 
    need to run this command if 'brz check' or a brz developer
 
1958
    previous ghost operations or bzr upgrades. You should only
 
1959
    need to run this command if 'bzr check' or a bzr developer
1951
1960
    advises you to run it.
1952
1961
 
1953
1962
    If a second branch is provided, cross-branch reconciliation is
1954
1963
    also attempted, which will check that data like the tree root
1955
 
    id which was not present in very early brz versions is represented
 
1964
    id which was not present in very early bzr versions is represented
1956
1965
    correctly in both branches.
1957
1966
 
1958
1967
    At the same time it is run it may recompress data resulting in
1971
1980
        ]
1972
1981
 
1973
1982
    def run(self, branch=".", canonicalize_chks=False):
1974
 
        from .reconcile import reconcile
 
1983
        from bzrlib.reconcile import reconcile
1975
1984
        dir = controldir.ControlDir.open(branch)
1976
1985
        reconcile(dir, canonicalize_chks=canonicalize_chks)
1977
1986
 
2037
2046
    in the .bzr directory.
2038
2047
 
2039
2048
    If there is already a branch at the location but it has no working tree,
2040
 
    the tree can be populated with 'brz checkout'.
 
2049
    the tree can be populated with 'bzr checkout'.
2041
2050
 
2042
2051
    Recipe for importing a tree of files::
2043
2052
 
2044
2053
        cd ~/project
2045
 
        brz init
2046
 
        brz add .
2047
 
        brz status
2048
 
        brz commit -m "imported project"
 
2054
        bzr init
 
2055
        bzr add .
 
2056
        bzr status
 
2057
        bzr commit -m "imported project"
2049
2058
    """
2050
2059
 
2051
2060
    _see_also = ['init-repository', 'branch', 'checkout']
2056
2065
                    'if it does not already exist.'),
2057
2066
         RegistryOption('format',
2058
2067
                help='Specify a format for this branch. '
2059
 
                'See "help formats" for a full list.',
2060
 
                lazy_registry=('breezy.controldir', 'format_registry'),
2061
 
                converter=lambda name: controldir.format_registry.make_controldir(name),
 
2068
                'See "help formats".',
 
2069
                lazy_registry=('bzrlib.controldir', 'format_registry'),
 
2070
                converter=lambda name: controldir.format_registry.make_bzrdir(name),
2062
2071
                value_switches=True,
2063
2072
                title="Branch format",
2064
2073
                ),
2071
2080
    def run(self, location=None, format=None, append_revisions_only=False,
2072
2081
            create_prefix=False, no_tree=False):
2073
2082
        if format is None:
2074
 
            format = controldir.format_registry.make_controldir('default')
 
2083
            format = controldir.format_registry.make_bzrdir('default')
2075
2084
        if location is None:
2076
2085
            location = u'.'
2077
2086
 
2094
2103
            to_transport.create_prefix()
2095
2104
 
2096
2105
        try:
2097
 
            a_controldir = controldir.ControlDir.open_from_transport(to_transport)
 
2106
            a_bzrdir = controldir.ControlDir.open_from_transport(to_transport)
2098
2107
        except errors.NotBranchError:
2099
2108
            # really a NotBzrDir error...
2100
2109
            create_branch = controldir.ControlDir.create_branch_convenience
2105
2114
            branch = create_branch(to_transport.base, format=format,
2106
2115
                                   possible_transports=[to_transport],
2107
2116
                                   force_new_tree=force_new_tree)
2108
 
            a_controldir = branch.controldir
 
2117
            a_bzrdir = branch.bzrdir
2109
2118
        else:
2110
 
            from .transport.local import LocalTransport
2111
 
            if a_controldir.has_branch():
 
2119
            from bzrlib.transport.local import LocalTransport
 
2120
            if a_bzrdir.has_branch():
2112
2121
                if (isinstance(to_transport, LocalTransport)
2113
 
                    and not a_controldir.has_workingtree()):
 
2122
                    and not a_bzrdir.has_workingtree()):
2114
2123
                        raise errors.BranchExistsWithoutWorkingTree(location)
2115
2124
                raise errors.AlreadyBranchError(location)
2116
 
            branch = a_controldir.create_branch()
2117
 
            if not no_tree and not a_controldir.has_workingtree():
2118
 
                a_controldir.create_workingtree()
 
2125
            branch = a_bzrdir.create_branch()
 
2126
            if not no_tree and not a_bzrdir.has_workingtree():
 
2127
                a_bzrdir.create_workingtree()
2119
2128
        if append_revisions_only:
2120
2129
            try:
2121
2130
                branch.set_append_revisions_only(True)
2123
2132
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
2124
2133
                    ' to append-revisions-only.  Try --default.'))
2125
2134
        if not is_quiet():
2126
 
            from .info import describe_layout, describe_format
 
2135
            from bzrlib.info import describe_layout, describe_format
2127
2136
            try:
2128
 
                tree = a_controldir.open_workingtree(recommend_upgrade=False)
 
2137
                tree = a_bzrdir.open_workingtree(recommend_upgrade=False)
2129
2138
            except (errors.NoWorkingTree, errors.NotLocalUrl):
2130
2139
                tree = None
2131
2140
            repository = branch.repository
2132
2141
            layout = describe_layout(repository, branch, tree).lower()
2133
 
            format = describe_format(a_controldir, repository, branch, tree)
 
2142
            format = describe_format(a_bzrdir, repository, branch, tree)
2134
2143
            self.outf.write(gettext("Created a {0} (format: {1})\n").format(
2135
2144
                  layout, format))
2136
2145
            if repository.is_shared():
2137
2146
                #XXX: maybe this can be refactored into transport.path_or_url()
2138
 
                url = repository.controldir.root_transport.external_url()
 
2147
                url = repository.bzrdir.root_transport.external_url()
2139
2148
                try:
2140
2149
                    url = urlutils.local_path_from_url(url)
2141
 
                except urlutils.InvalidURL:
 
2150
                except errors.InvalidURL:
2142
2151
                    pass
2143
2152
                self.outf.write(gettext("Using shared repository: %s\n") % url)
2144
2153
 
2161
2170
    :Examples:
2162
2171
        Create a shared repository holding just branches::
2163
2172
 
2164
 
            brz init-repo --no-trees repo
2165
 
            brz init repo/trunk
 
2173
            bzr init-repo --no-trees repo
 
2174
            bzr init repo/trunk
2166
2175
 
2167
2176
        Make a lightweight checkout elsewhere::
2168
2177
 
2169
 
            brz checkout --lightweight repo/trunk trunk-checkout
 
2178
            bzr checkout --lightweight repo/trunk trunk-checkout
2170
2179
            cd trunk-checkout
2171
2180
            (add files here)
2172
2181
    """
2175
2184
    takes_args = ["location"]
2176
2185
    takes_options = [RegistryOption('format',
2177
2186
                            help='Specify a format for this repository. See'
2178
 
                                 ' "brz help formats" for details.',
2179
 
                            lazy_registry=('breezy.controldir', 'format_registry'),
2180
 
                            converter=lambda name: controldir.format_registry.make_controldir(name),
 
2187
                                 ' "bzr help formats" for details.',
 
2188
                            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
2189
                            converter=lambda name: controldir.format_registry.make_bzrdir(name),
2181
2190
                            value_switches=True, title='Repository format'),
2182
2191
                     Option('no-trees',
2183
2192
                             help='Branches in the repository will default to'
2187
2196
 
2188
2197
    def run(self, location, format=None, no_trees=False):
2189
2198
        if format is None:
2190
 
            format = controldir.format_registry.make_controldir('default')
 
2199
            format = controldir.format_registry.make_bzrdir('default')
2191
2200
 
2192
2201
        if location is None:
2193
2202
            location = '.'
2194
2203
 
2195
2204
        to_transport = transport.get_transport(location)
2196
2205
 
2197
 
        if format.fixed_components:
2198
 
            repo_format_name = None
2199
 
        else:
2200
 
            repo_format_name = format.repository_format.get_format_string()
2201
 
 
2202
2206
        (repo, newdir, require_stacking, repository_policy) = (
2203
2207
            format.initialize_on_transport_ex(to_transport,
2204
2208
            create_prefix=True, make_working_trees=not no_trees,
2205
2209
            shared_repo=True, force_new_repo=True,
2206
2210
            use_existing_dir=True,
2207
 
            repo_format_name=repo_format_name))
 
2211
            repo_format_name=format.repository_format.get_format_string()))
2208
2212
        if not is_quiet():
2209
 
            from .info import show_bzrdir_info
 
2213
            from bzrlib.info import show_bzrdir_info
2210
2214
            show_bzrdir_info(newdir, verbose=0, outfile=self.outf)
2211
2215
 
2212
2216
 
2220
2224
    the first argument, if any, or the current tree if no arguments are
2221
2225
    given.
2222
2226
 
2223
 
    "brz diff -p1" is equivalent to "brz diff --prefix old/:new/", and
 
2227
    "bzr diff -p1" is equivalent to "bzr diff --prefix old/:new/", and
2224
2228
    produces patches suitable for "patch -p1".
2225
2229
 
2226
2230
    Note that when using the -r argument with a range of revisions, the
2227
2231
    differences are computed between the two specified revisions.  That
2228
2232
    is, the command does not show the changes introduced by the first 
2229
2233
    revision in the range.  This differs from the interpretation of 
2230
 
    revision ranges used by "brz log" which includes the first revision
 
2234
    revision ranges used by "bzr log" which includes the first revision
2231
2235
    in the range.
2232
2236
 
2233
2237
    :Exit values:
2239
2243
    :Examples:
2240
2244
        Shows the difference in the working tree versus the last commit::
2241
2245
 
2242
 
            brz diff
 
2246
            bzr diff
2243
2247
 
2244
2248
        Difference between the working tree and revision 1::
2245
2249
 
2246
 
            brz diff -r1
 
2250
            bzr diff -r1
2247
2251
 
2248
2252
        Difference between revision 3 and revision 1::
2249
2253
 
2250
 
            brz diff -r1..3
 
2254
            bzr diff -r1..3
2251
2255
 
2252
2256
        Difference between revision 3 and revision 1 for branch xxx::
2253
2257
 
2254
 
            brz diff -r1..3 xxx
 
2258
            bzr diff -r1..3 xxx
2255
2259
 
2256
2260
        The changes introduced by revision 2 (equivalent to -r1..2)::
2257
2261
 
2258
 
            brz diff -c2
 
2262
            bzr diff -c2
2259
2263
 
2260
2264
        To see the changes introduced by revision X::
2261
2265
        
2262
 
            brz diff -cX
 
2266
            bzr diff -cX
2263
2267
 
2264
2268
        Note that in the case of a merge, the -c option shows the changes
2265
2269
        compared to the left hand parent. To see the changes against
2266
2270
        another parent, use::
2267
2271
 
2268
 
            brz diff -r<chosen_parent>..X
 
2272
            bzr diff -r<chosen_parent>..X
2269
2273
 
2270
2274
        The changes between the current revision and the previous revision
2271
2275
        (equivalent to -c-1 and -r-2..-1)
2272
2276
 
2273
 
            brz diff -r-2..
 
2277
            bzr diff -r-2..
2274
2278
 
2275
2279
        Show just the differences for file NEWS::
2276
2280
 
2277
 
            brz diff NEWS
 
2281
            bzr diff NEWS
2278
2282
 
2279
2283
        Show the differences in working tree xxx for file NEWS::
2280
2284
 
2281
 
            brz diff xxx/NEWS
 
2285
            bzr diff xxx/NEWS
2282
2286
 
2283
2287
        Show the differences from branch xxx to this working tree:
2284
2288
 
2285
 
            brz diff --old xxx
 
2289
            bzr diff --old xxx
2286
2290
 
2287
2291
        Show the differences between two branches for file NEWS::
2288
2292
 
2289
 
            brz diff --old xxx --new yyy NEWS
2290
 
 
2291
 
        Same as 'brz diff' but prefix paths with old/ and new/::
2292
 
 
2293
 
            brz diff --prefix old/:new/
2294
 
 
 
2293
            bzr diff --old xxx --new yyy NEWS
 
2294
 
 
2295
        Same as 'bzr diff' but prefix paths with old/ and new/::
 
2296
 
 
2297
            bzr diff --prefix old/:new/
 
2298
            
2295
2299
        Show the differences using a custom diff program with options::
2296
 
 
2297
 
            brz diff --using /usr/bin/diff --diff-options -wu
 
2300
        
 
2301
            bzr diff --using /usr/bin/diff --diff-options -wu
2298
2302
    """
2299
2303
    _see_also = ['status']
2300
2304
    takes_args = ['file*']
2301
2305
    takes_options = [
2302
 
        Option('diff-options', type=text_type,
 
2306
        Option('diff-options', type=str,
2303
2307
               help='Pass these options to the external diff program.'),
2304
 
        Option('prefix', type=text_type,
 
2308
        Option('prefix', type=str,
2305
2309
               short_name='p',
2306
2310
               help='Set prefixes added to old and new filenames, as '
2307
2311
                    'two values separated by a colon. (eg "old/:new/").'),
2308
2312
        Option('old',
2309
2313
            help='Branch/tree to compare from.',
2310
 
            type=text_type,
 
2314
            type=unicode,
2311
2315
            ),
2312
2316
        Option('new',
2313
2317
            help='Branch/tree to compare to.',
2314
 
            type=text_type,
 
2318
            type=unicode,
2315
2319
            ),
2316
2320
        'revision',
2317
2321
        'change',
2318
2322
        Option('using',
2319
2323
            help='Use this command to compare files.',
2320
 
            type=text_type,
 
2324
            type=unicode,
2321
2325
            ),
2322
2326
        RegistryOption('format',
2323
2327
            short_name='F',
2324
2328
            help='Diff format to use.',
2325
 
            lazy_registry=('breezy.diff', 'format_registry'),
 
2329
            lazy_registry=('bzrlib.diff', 'format_registry'),
2326
2330
            title='Diff format'),
2327
2331
        Option('context',
2328
2332
            help='How many lines of context to show.',
2334
2338
 
2335
2339
    @display_command
2336
2340
    def run(self, revision=None, file_list=None, diff_options=None,
2337
 
            prefix=None, old=None, new=None, using=None, format=None,
 
2341
            prefix=None, old=None, new=None, using=None, format=None, 
2338
2342
            context=None):
2339
 
        from .diff import (get_trees_and_branches_to_diff_locked,
 
2343
        from bzrlib.diff import (get_trees_and_branches_to_diff_locked,
2340
2344
            show_diff_trees)
2341
2345
 
2342
 
        if prefix == u'0':
 
2346
        if (prefix is None) or (prefix == '0'):
2343
2347
            # diff -p0 format
2344
2348
            old_label = ''
2345
2349
            new_label = ''
2346
 
        elif prefix == u'1' or prefix is None:
 
2350
        elif prefix == '1':
2347
2351
            old_label = 'old/'
2348
2352
            new_label = 'new/'
2349
 
        elif u':' in prefix:
2350
 
            old_label, new_label = prefix.split(u":")
 
2353
        elif ':' in prefix:
 
2354
            old_label, new_label = prefix.split(":")
2351
2355
        else:
2352
2356
            raise errors.BzrCommandError(gettext(
2353
2357
                '--prefix expects two values separated by a colon'
2354
2358
                ' (eg "old/:new/")'))
2355
2359
 
2356
2360
        if revision and len(revision) > 2:
2357
 
            raise errors.BzrCommandError(gettext('brz diff --revision takes exactly'
 
2361
            raise errors.BzrCommandError(gettext('bzr diff --revision takes exactly'
2358
2362
                                         ' one or two revision specifiers'))
2359
2363
 
2360
2364
        if using is not None and format is not None:
2368
2372
            file_list, revision, old, new, self.add_cleanup, apply_view=True)
2369
2373
        # GNU diff on Windows uses ANSI encoding for filenames
2370
2374
        path_encoding = osutils.get_diff_header_encoding()
2371
 
        return show_diff_trees(old_tree, new_tree, self.outf,
 
2375
        return show_diff_trees(old_tree, new_tree, sys.stdout,
2372
2376
                               specific_files=specific_files,
2373
2377
                               external_diff_options=diff_options,
2374
2378
                               old_label=old_label, new_label=new_label,
2441
2445
        basis = wt.basis_tree()
2442
2446
        self.add_cleanup(basis.lock_read().unlock)
2443
2447
        root_id = wt.get_root_id()
2444
 
        for path in wt.all_versioned_paths():
2445
 
            if basis.has_filename(path):
2446
 
                continue
2447
 
            if path == u'':
2448
 
                continue
 
2448
        for file_id in wt.all_file_ids():
 
2449
            if basis.has_id(file_id):
 
2450
                continue
 
2451
            if root_id == file_id:
 
2452
                continue
 
2453
            path = wt.id2path(file_id)
2449
2454
            if not os.access(osutils.pathjoin(wt.basedir, path), os.F_OK):
2450
2455
                continue
2451
2456
            if null:
2487
2492
class cmd_log(Command):
2488
2493
    __doc__ = """Show historical log for a branch or subset of a branch.
2489
2494
 
2490
 
    log is brz's default tool for exploring the history of a branch.
 
2495
    log is bzr's default tool for exploring the history of a branch.
2491
2496
    The branch to use is taken from the first parameter. If no parameters
2492
2497
    are given, the branch containing the working directory is logged.
2493
2498
    Here are some simple examples::
2494
2499
 
2495
 
      brz log                       log the current branch
2496
 
      brz log foo.py                log a file in its branch
2497
 
      brz log http://server/branch  log a branch on a server
 
2500
      bzr log                       log the current branch
 
2501
      bzr log foo.py                log a file in its branch
 
2502
      bzr log http://server/branch  log a branch on a server
2498
2503
 
2499
2504
    The filtering, ordering and information shown for each revision can
2500
2505
    be controlled as explained below. By default, all revisions are
2507
2512
 
2508
2513
      The log format controls how information about each revision is
2509
2514
      displayed. The standard log formats are called ``long``, ``short``
2510
 
      and ``line``. The default is long. See ``brz help log-formats``
 
2515
      and ``line``. The default is long. See ``bzr help log-formats``
2511
2516
      for more details on log formats.
2512
2517
 
2513
2518
      The following options can be used to control what information is
2544
2549
        -r..Y    display up to and including revision Y
2545
2550
        -rX..Y   display from X to Y inclusive
2546
2551
 
2547
 
      See ``brz help revisionspec`` for details on how to specify X and Y.
 
2552
      See ``bzr help revisionspec`` for details on how to specify X and Y.
2548
2553
      Some common examples are given below::
2549
2554
 
2550
2555
        -r-1                show just the tip
2580
2585
 
2581
2586
      In this case:
2582
2587
 
2583
 
      * ``brz log guide.txt`` will log the file added in revision 1
2584
 
 
2585
 
      * ``brz log tutorial.txt`` will log the new file added in revision 3
2586
 
 
2587
 
      * ``brz log -r2 -p tutorial.txt`` will show the changes made to
 
2588
      * ``bzr log guide.txt`` will log the file added in revision 1
 
2589
 
 
2590
      * ``bzr log tutorial.txt`` will log the new file added in revision 3
 
2591
 
 
2592
      * ``bzr log -r2 -p tutorial.txt`` will show the changes made to
2588
2593
        the original file in revision 2.
2589
2594
 
2590
 
      * ``brz log -r2 -p guide.txt`` will display an error message as there
 
2595
      * ``bzr log -r2 -p guide.txt`` will display an error message as there
2591
2596
        was no file called guide.txt in revision 2.
2592
2597
 
2593
2598
      Renames are always followed by log. By design, there is no need to
2606
2611
 
2607
2612
      GUI tools and IDEs are often better at exploring history than command
2608
2613
      line tools: you may prefer qlog or viz from qbzr or bzr-gtk, the
2609
 
      bzr-explorer shell, or the Loggerhead web interface.  See the Bazaar
2610
 
      Plugin Guide <http://doc.bazaar.canonical.com/plugins/en/> and
 
2614
      bzr-explorer shell, or the Loggerhead web interface.  See the Plugin
 
2615
      Guide <http://doc.bazaar.canonical.com/plugins/en/> and
2611
2616
      <http://wiki.bazaar.canonical.com/IDEIntegration>.  
2612
2617
 
2613
 
      You may find it useful to add the aliases below to ``breezy.conf``::
 
2618
      You may find it useful to add the aliases below to ``bazaar.conf``::
2614
2619
 
2615
2620
        [ALIASES]
2616
2621
        tip = log -r-1
2617
2622
        top = log -l10 --line
2618
2623
        show = log -v -p
2619
2624
 
2620
 
      ``brz tip`` will then show the latest revision while ``brz top``
 
2625
      ``bzr tip`` will then show the latest revision while ``bzr top``
2621
2626
      will show the last 10 mainline revisions. To see the details of a
2622
 
      particular revision X,  ``brz show -rX``.
 
2627
      particular revision X,  ``bzr show -rX``.
2623
2628
 
2624
2629
      If you are interested in looking deeper into a particular merge X,
2625
 
      use ``brz log -n0 -rX``.
 
2630
      use ``bzr log -n0 -rX``.
2626
2631
 
2627
 
      ``brz log -v`` on a branch with lots of history is currently
 
2632
      ``bzr log -v`` on a branch with lots of history is currently
2628
2633
      very slow. A fix for this issue is currently under development.
2629
2634
      With or without that fix, it is recommended that a revision range
2630
2635
      be given when using the -v option.
2631
2636
 
2632
 
      brz has a generic full-text matching plugin, brz-search, that can be
 
2637
      bzr has a generic full-text matching plugin, bzr-search, that can be
2633
2638
      used to find revisions matching user names, commit messages, etc.
2634
2639
      Among other features, this plugin can find all revisions containing
2635
2640
      a list of words but not others.
2650
2655
            'show-ids',
2651
2656
            'revision',
2652
2657
            Option('change',
2653
 
                   type=breezy.option._parse_revision_str,
 
2658
                   type=bzrlib.option._parse_revision_str,
2654
2659
                   short_name='c',
2655
2660
                   help='Show just the specified revision.'
2656
2661
                   ' See also "help revisionspec".'),
2658
2663
            RegistryOption('authors',
2659
2664
                'What names to list as authors - first, all or committer.',
2660
2665
                title='Authors',
2661
 
                lazy_registry=('breezy.log', 'author_list_registry'),
 
2666
                lazy_registry=('bzrlib.log', 'author_list_registry'),
2662
2667
            ),
2663
2668
            Option('levels',
2664
2669
                   short_name='n',
2668
2673
            Option('message',
2669
2674
                   help='Show revisions whose message matches this '
2670
2675
                        'regular expression.',
2671
 
                   type=text_type,
 
2676
                   type=str,
2672
2677
                   hidden=True),
2673
2678
            Option('limit',
2674
2679
                   short_name='l',
2694
2699
                short_name='m',
2695
2700
                help='Show revisions whose properties match this '
2696
2701
                'expression.',
2697
 
                type=text_type),
 
2702
                type=str),
2698
2703
            ListOption('match-message',
2699
2704
                   help='Show revisions whose message matches this '
2700
2705
                   'expression.',
2701
 
                type=text_type),
 
2706
                type=str),
2702
2707
            ListOption('match-committer',
2703
2708
                   help='Show revisions whose committer matches this '
2704
2709
                   'expression.',
2705
 
                type=text_type),
 
2710
                type=str),
2706
2711
            ListOption('match-author',
2707
2712
                   help='Show revisions whose authors match this '
2708
2713
                   'expression.',
2709
 
                type=text_type),
 
2714
                type=str),
2710
2715
            ListOption('match-bugs',
2711
2716
                   help='Show revisions whose bugs match this '
2712
2717
                   'expression.',
2713
 
                type=text_type)
 
2718
                type=str)
2714
2719
            ]
2715
2720
    encoding_type = 'replace'
2716
2721
 
2736
2741
            match_author=None,
2737
2742
            match_bugs=None,
2738
2743
            omit_merges=False,
 
2744
            include_merges=symbol_versioning.DEPRECATED_PARAMETER,
2739
2745
            ):
2740
 
        from .log import (
 
2746
        from bzrlib.log import (
2741
2747
            Logger,
2742
2748
            make_log_request_dict,
2743
2749
            _get_info_for_log_files,
2744
2750
            )
2745
2751
        direction = (forward and 'forward') or 'reverse'
 
2752
        if symbol_versioning.deprecated_passed(include_merges):
 
2753
            ui.ui_factory.show_user_warning(
 
2754
                'deprecated_command_option',
 
2755
                deprecated_name='--include-merges',
 
2756
                recommended_name='--include-merged',
 
2757
                deprecated_in_version='2.5',
 
2758
                command=self.invoked_as)
 
2759
            if include_merged is None:
 
2760
                include_merged = include_merges
 
2761
            else:
 
2762
                raise errors.BzrCommandError(gettext(
 
2763
                    '{0} and {1} are mutually exclusive').format(
 
2764
                    '--include-merges', '--include-merged'))
2746
2765
        if include_merged is None:
2747
2766
            include_merged = False
2748
2767
        if (exclude_common_ancestry
2893
2912
            # show_log will use its revision_history. Having
2894
2913
            # different branches will lead to weird behaviors.
2895
2914
            raise errors.BzrCommandError(gettext(
2896
 
                "brz %s doesn't accept two revisions in different"
 
2915
                "bzr %s doesn't accept two revisions in different"
2897
2916
                " branches.") % command_name)
2898
2917
        if start_spec.spec is None:
2899
2918
            # Avoid loading all the history.
2909
2928
            rev2 = end_spec.in_history(branch)
2910
2929
    else:
2911
2930
        raise errors.BzrCommandError(gettext(
2912
 
            'brz %s --revision takes one or two values.') % command_name)
 
2931
            'bzr %s --revision takes one or two values.') % command_name)
2913
2932
    return rev1, rev2
2914
2933
 
2915
2934
 
2936
2955
class cmd_touching_revisions(Command):
2937
2956
    __doc__ = """Return revision-ids which affected a particular file.
2938
2957
 
2939
 
    A more user-friendly interface is "brz log FILE".
 
2958
    A more user-friendly interface is "bzr log FILE".
2940
2959
    """
2941
2960
 
2942
2961
    hidden = True
2945
2964
    @display_command
2946
2965
    def run(self, filename):
2947
2966
        tree, relpath = WorkingTree.open_containing(filename)
2948
 
        with tree.lock_read():
2949
 
            touching_revs = log.find_touching_revisions(
2950
 
                    tree.branch.repository, tree.branch.last_revision(), tree, relpath)
2951
 
            for revno, revision_id, what in reversed(list(touching_revs)):
2952
 
                self.outf.write("%6d %s\n" % (revno, what))
 
2967
        file_id = tree.path2id(relpath)
 
2968
        b = tree.branch
 
2969
        self.add_cleanup(b.lock_read().unlock)
 
2970
        touching_revs = log.find_touching_revisions(b, file_id)
 
2971
        for revno, revision_id, what in touching_revs:
 
2972
            self.outf.write("%6d %s\n" % (revno, what))
2953
2973
 
2954
2974
 
2955
2975
class cmd_ls(Command):
2973
2993
                help='Print ignored files.'),
2974
2994
            Option('kind', short_name='k',
2975
2995
                   help='List entries of a particular kind: file, directory, symlink.',
2976
 
                   type=text_type),
 
2996
                   type=unicode),
2977
2997
            'null',
2978
2998
            'show-ids',
2979
2999
            'directory',
2984
3004
            unknown=False, versioned=False, ignored=False,
2985
3005
            null=False, kind=None, show_ids=False, path=None, directory=None):
2986
3006
 
2987
 
        if kind and kind not in ('file', 'directory', 'symlink', 'tree-reference'):
 
3007
        if kind and kind not in ('file', 'directory', 'symlink'):
2988
3008
            raise errors.BzrCommandError(gettext('invalid kind specified'))
2989
3009
 
2990
3010
        if verbose and null:
3037
3057
                    else:
3038
3058
                        fullpath = fp
3039
3059
                    views.check_path_in_view(tree, fullpath)
3040
 
                except views.FileOutsideView:
 
3060
                except errors.FileOutsideView:
3041
3061
                    continue
3042
3062
 
3043
3063
            # Output the entry
3086
3106
class cmd_ignore(Command):
3087
3107
    __doc__ = """Ignore specified files or patterns.
3088
3108
 
3089
 
    See ``brz help patterns`` for details on the syntax of patterns.
 
3109
    See ``bzr help patterns`` for details on the syntax of patterns.
3090
3110
 
3091
3111
    If a .bzrignore file does not exist, the ignore command
3092
3112
    will create one and add the specified files or patterns to the newly
3123
3143
    :Examples:
3124
3144
        Ignore the top level Makefile::
3125
3145
 
3126
 
            brz ignore ./Makefile
 
3146
            bzr ignore ./Makefile
3127
3147
 
3128
3148
        Ignore .class files in all directories...::
3129
3149
 
3130
 
            brz ignore "*.class"
 
3150
            bzr ignore "*.class"
3131
3151
 
3132
3152
        ...but do not ignore "special.class"::
3133
3153
 
3134
 
            brz ignore "!special.class"
 
3154
            bzr ignore "!special.class"
3135
3155
 
3136
3156
        Ignore files whose name begins with the "#" character::
3137
3157
 
3138
 
            brz ignore "RE:^#"
3139
 
 
3140
 
        Ignore .o files under the lib directory::
3141
 
 
3142
 
            brz ignore "lib/**/*.o"
3143
 
 
3144
 
        Ignore .o files under the lib directory::
3145
 
 
3146
 
            brz ignore "RE:lib/.*\\.o"
 
3158
            bzr ignore "RE:^#"
 
3159
 
 
3160
        Ignore .o files under the lib directory::
 
3161
 
 
3162
            bzr ignore "lib/**/*.o"
 
3163
 
 
3164
        Ignore .o files under the lib directory::
 
3165
 
 
3166
            bzr ignore "RE:lib/.*\.o"
3147
3167
 
3148
3168
        Ignore everything but the "debian" toplevel directory::
3149
3169
 
3150
 
            brz ignore "RE:(?!debian/).*"
 
3170
            bzr ignore "RE:(?!debian/).*"
3151
3171
        
3152
3172
        Ignore everything except the "local" toplevel directory,
3153
3173
        but always ignore autosave files ending in ~, even under local/::
3154
3174
        
3155
 
            brz ignore "*"
3156
 
            brz ignore "!./local"
3157
 
            brz ignore "!!*~"
 
3175
            bzr ignore "*"
 
3176
            bzr ignore "!./local"
 
3177
            bzr ignore "!!*~"
3158
3178
    """
3159
3179
 
3160
3180
    _see_also = ['status', 'ignored', 'patterns']
3161
3181
    takes_args = ['name_pattern*']
3162
3182
    takes_options = ['directory',
3163
3183
        Option('default-rules',
3164
 
               help='Display the default ignore rules that brz uses.')
 
3184
               help='Display the default ignore rules that bzr uses.')
3165
3185
        ]
3166
3186
 
3167
3187
    def run(self, name_pattern_list=None, default_rules=None,
3168
3188
            directory=u'.'):
3169
 
        from breezy import ignores
 
3189
        from bzrlib import ignores
3170
3190
        if default_rules is not None:
3171
3191
            # dump the default rules and exit
3172
3192
            for pattern in ignores.USER_DEFAULTS:
3188
3208
                            'Invalid ignore patterns found. %s',
3189
3209
                            bad_patterns_count) % bad_patterns)
3190
3210
            ui.ui_factory.show_error(msg)
3191
 
            raise lazy_regex.InvalidPattern('')
 
3211
            raise errors.InvalidPattern('')
3192
3212
        for name_pattern in name_pattern_list:
3193
3213
            if (name_pattern[0] == '/' or
3194
3214
                (len(name_pattern) > 1 and name_pattern[1] == ':')):
3209
3229
            self.outf.write(gettext("Warning: the following files are version "
3210
3230
                  "controlled and match your ignore pattern:\n%s"
3211
3231
                  "\nThese files will continue to be version controlled"
3212
 
                  " unless you 'brz remove' them.\n") % ("\n".join(matches),))
 
3232
                  " unless you 'bzr remove' them.\n") % ("\n".join(matches),))
3213
3233
 
3214
3234
 
3215
3235
class cmd_ignored(Command):
3220
3240
 
3221
3241
    Alternatively, to list just the files::
3222
3242
 
3223
 
        brz ls --ignored
 
3243
        bzr ls --ignored
3224
3244
    """
3225
3245
 
3226
3246
    encoding_type = 'replace'
3243
3263
    __doc__ = """Lookup the revision-id from a revision-number
3244
3264
 
3245
3265
    :Examples:
3246
 
        brz lookup-revision 33
 
3266
        bzr lookup-revision 33
3247
3267
    """
3248
3268
    hidden = True
3249
3269
    takes_args = ['revno']
3293
3313
    takes_options = ['directory',
3294
3314
        Option('format',
3295
3315
               help="Type of file to export to.",
3296
 
               type=text_type),
 
3316
               type=unicode),
3297
3317
        'revision',
3298
3318
        Option('filters', help='Apply content filters to export the '
3299
3319
                'convenient form.'),
3300
3320
        Option('root',
3301
 
               type=text_type,
 
3321
               type=str,
3302
3322
               help="Name of the root directory inside the exported file."),
3303
3323
        Option('per-file-timestamps',
3304
3324
               help='Set modification time of files to that of the last '
3310
3330
    def run(self, dest, branch_or_subdir=None, revision=None, format=None,
3311
3331
        root=None, filters=False, per_file_timestamps=False, uncommitted=False,
3312
3332
        directory=u'.'):
3313
 
        from .export import export
 
3333
        from bzrlib.export import export
3314
3334
 
3315
3335
        if branch_or_subdir is None:
3316
3336
            branch_or_subdir = directory
3330
3350
        try:
3331
3351
            export(export_tree, dest, format, root, subdir, filtered=filters,
3332
3352
                   per_file_timestamps=per_file_timestamps)
3333
 
        except errors.NoSuchExportFormat as e:
 
3353
        except errors.NoSuchExportFormat, e:
3334
3354
            raise errors.BzrCommandError(
3335
3355
                gettext('Unsupported export format: %s') % e.format)
3336
3356
 
3358
3378
    def run(self, filename, revision=None, name_from_revision=False,
3359
3379
            filters=False, directory=None):
3360
3380
        if revision is not None and len(revision) != 1:
3361
 
            raise errors.BzrCommandError(gettext("brz cat --revision takes exactly"
 
3381
            raise errors.BzrCommandError(gettext("bzr cat --revision takes exactly"
3362
3382
                                         " one revision specifier"))
3363
3383
        tree, branch, relpath = \
3364
3384
            _open_directory_or_containing_tree_or_branch(filename, directory)
3397
3417
                raise errors.BzrCommandError(gettext(
3398
3418
                    "{0!r} is not present in revision {1}").format(
3399
3419
                        filename, rev_tree.get_revision_id()))
3400
 
        relpath = rev_tree.id2path(actual_file_id)
3401
3420
        if filtered:
3402
 
            from .filter_tree import ContentFilterTree
 
3421
            from bzrlib.filter_tree import ContentFilterTree
3403
3422
            filter_tree = ContentFilterTree(rev_tree,
3404
3423
                rev_tree._content_filter_stack)
3405
 
            content = filter_tree.get_file_text(relpath, actual_file_id)
 
3424
            content = filter_tree.get_file_text(actual_file_id)
3406
3425
        else:
3407
 
            content = rev_tree.get_file_text(relpath, actual_file_id)
 
3426
            content = rev_tree.get_file_text(actual_file_id)
3408
3427
        self.cleanup_now()
3409
3428
        self.outf.write(content)
3410
3429
 
3442
3461
      For example, to commit only changes within foo, but not changes
3443
3462
      within foo/bar::
3444
3463
  
3445
 
        brz commit foo -x foo/bar
 
3464
        bzr commit foo -x foo/bar
3446
3465
  
3447
3466
      A selective commit after a merge is not yet supported.
3448
3467
 
3460
3479
      A common mistake is to forget to add a new file or directory before
3461
3480
      running the commit command. The --strict option checks for unknown
3462
3481
      files and aborts the commit if any are found. More advanced pre-commit
3463
 
      checks can be implemented by defining hooks. See ``brz help hooks``
 
3482
      checks can be implemented by defining hooks. See ``bzr help hooks``
3464
3483
      for details.
3465
3484
 
3466
3485
    :Things to note:
3467
3486
 
3468
3487
      If you accidentially commit the wrong changes or make a spelling
3469
3488
      mistake in the commit message say, you can use the uncommit command
3470
 
      to undo it. See ``brz help uncommit`` for details.
 
3489
      to undo it. See ``bzr help uncommit`` for details.
3471
3490
 
3472
3491
      Hooks can also be configured to run after a commit. This allows you
3473
3492
      to trigger updates to external systems like bug trackers. The --fixes
3474
3493
      option can be used to record the association between a revision and
3475
 
      one or more bugs. See ``brz help bugs`` for details.
 
3494
      one or more bugs. See ``bzr help bugs`` for details.
3476
3495
    """
3477
3496
 
3478
3497
    _see_also = ['add', 'bugs', 'hooks', 'uncommit']
3479
3498
    takes_args = ['selected*']
3480
3499
    takes_options = [
3481
 
            ListOption('exclude', type=text_type, short_name='x',
 
3500
            ListOption('exclude', type=str, short_name='x',
3482
3501
                help="Do not consider changes made to a given path."),
3483
 
            Option('message', type=text_type,
 
3502
            Option('message', type=unicode,
3484
3503
                   short_name='m',
3485
3504
                   help="Description of the new revision."),
3486
3505
            'verbose',
3487
3506
             Option('unchanged',
3488
3507
                    help='Commit even if nothing has changed.'),
3489
 
             Option('file', type=text_type,
 
3508
             Option('file', type=str,
3490
3509
                    short_name='F',
3491
3510
                    argname='msgfile',
3492
3511
                    help='Take commit message from this file.'),
3493
3512
             Option('strict',
3494
3513
                    help="Refuse to commit if there are unknown "
3495
3514
                    "files in the working tree."),
3496
 
             Option('commit-time', type=text_type,
 
3515
             Option('commit-time', type=str,
3497
3516
                    help="Manually set a commit time using commit date "
3498
3517
                    "format, e.g. '2009-10-10 08:00:00 +0100'."),
3499
 
             ListOption('fixes', type=text_type,
 
3518
             ListOption('fixes', type=str,
3500
3519
                    help="Mark a bug as being fixed by this revision "
3501
 
                         "(see \"brz help bugs\")."),
3502
 
             ListOption('author', type=text_type,
 
3520
                         "(see \"bzr help bugs\")."),
 
3521
             ListOption('author', type=unicode,
3503
3522
                    help="Set the author's name, if it's different "
3504
3523
                         "from the committer."),
3505
3524
             Option('local',
3533
3552
                        "No tracker specified for bug %s. Use the form "
3534
3553
                        "'tracker:id' or specify a default bug tracker "
3535
3554
                        "using the `bugtracker` option.\nSee "
3536
 
                        "\"brz help bugs\" for more information on this "
 
3555
                        "\"bzr help bugs\" for more information on this "
3537
3556
                        "feature. Commit refused.") % fixed_bug)
3538
3557
                tag = default_bugtracker
3539
3558
                bug_id = tokens[0]
3540
3559
            elif len(tokens) != 2:
3541
3560
                raise errors.BzrCommandError(gettext(
3542
3561
                    "Invalid bug %s. Must be in the form of 'tracker:id'. "
3543
 
                    "See \"brz help bugs\" for more information on this "
 
3562
                    "See \"bzr help bugs\" for more information on this "
3544
3563
                    "feature.\nCommit refused.") % fixed_bug)
3545
3564
            else:
3546
3565
                tag, bug_id = tokens
3547
3566
            try:
3548
3567
                yield bugtracker.get_bug_url(tag, branch, bug_id)
3549
 
            except bugtracker.UnknownBugTrackerAbbreviation:
 
3568
            except errors.UnknownBugTrackerAbbreviation:
3550
3569
                raise errors.BzrCommandError(gettext(
3551
3570
                    'Unrecognized bug %s. Commit refused.') % fixed_bug)
3552
 
            except bugtracker.MalformedBugIdentifier as e:
 
3571
            except errors.MalformedBugIdentifier, e:
3553
3572
                raise errors.BzrCommandError(gettext(
3554
 
                    u"%s\nCommit refused.") % (e,))
 
3573
                    "%s\nCommit refused.") % (str(e),))
3555
3574
 
3556
3575
    def run(self, message=None, file=None, verbose=False, selected_list=None,
3557
3576
            unchanged=False, strict=False, local=False, fixes=None,
3558
3577
            author=None, show_diff=False, exclude=None, commit_time=None,
3559
3578
            lossy=False):
3560
 
        from .commit import (
 
3579
        from bzrlib.errors import (
3561
3580
            PointlessCommit,
3562
 
            )
3563
 
        from .errors import (
3564
3581
            ConflictsInTree,
3565
3582
            StrictCommitFailed
3566
3583
        )
3567
 
        from .msgeditor import (
 
3584
        from bzrlib.msgeditor import (
3568
3585
            edit_commit_message_encoded,
3569
3586
            generate_commit_message_template,
3570
3587
            make_commit_message_template_encoded,
3575
3592
        if commit_time is not None:
3576
3593
            try:
3577
3594
                commit_stamp, offset = timestamp.parse_patch_date(commit_time)
3578
 
            except ValueError as e:
 
3595
            except ValueError, e:
3579
3596
                raise errors.BzrCommandError(gettext(
3580
3597
                    "Could not parse --commit-time: " + str(e)))
3581
3598
 
3622
3639
        def get_message(commit_obj):
3623
3640
            """Callback to get commit message"""
3624
3641
            if file:
3625
 
                with open(file) as f:
 
3642
                f = open(file)
 
3643
                try:
3626
3644
                    my_message = f.read().decode(osutils.get_user_encoding())
 
3645
                finally:
 
3646
                    f.close()
3627
3647
            elif message is not None:
3628
3648
                my_message = message
3629
3649
            else:
3667
3687
                        lossy=lossy)
3668
3688
        except PointlessCommit:
3669
3689
            raise errors.BzrCommandError(gettext("No changes to commit."
3670
 
                " Please 'brz add' the files you want to commit, or use"
 
3690
                " Please 'bzr add' the files you want to commit, or use"
3671
3691
                " --unchanged to force an empty commit."))
3672
3692
        except ConflictsInTree:
3673
3693
            raise errors.BzrCommandError(gettext('Conflicts detected in working '
3674
 
                'tree.  Use "brz conflicts" to list, "brz resolve FILE" to'
 
3694
                'tree.  Use "bzr conflicts" to list, "bzr resolve FILE" to'
3675
3695
                ' resolve.'))
3676
3696
        except StrictCommitFailed:
3677
3697
            raise errors.BzrCommandError(gettext("Commit refused because there are"
3678
3698
                              " unknown files in the working tree."))
3679
 
        except errors.BoundBranchOutOfDate as e:
 
3699
        except errors.BoundBranchOutOfDate, e:
3680
3700
            e.extra_help = (gettext("\n"
3681
3701
                'To commit to master branch, run update and then commit.\n'
3682
3702
                'You can also pass --local to commit to continue working '
3688
3708
    __doc__ = """Validate working tree structure, branch consistency and repository history.
3689
3709
 
3690
3710
    This command checks various invariants about branch and repository storage
3691
 
    to detect data corruption or brz bugs.
 
3711
    to detect data corruption or bzr bugs.
3692
3712
 
3693
3713
    The working tree and branch checks will only give output if a problem is
3694
3714
    detected. The output fields of the repository check are:
3723
3743
 
3724
3744
        Check the tree and branch at 'foo'::
3725
3745
 
3726
 
            brz check --tree --branch foo
 
3746
            bzr check --tree --branch foo
3727
3747
 
3728
3748
        Check only the repository at 'bar'::
3729
3749
 
3730
 
            brz check --repo bar
 
3750
            bzr check --repo bar
3731
3751
 
3732
3752
        Check everything at 'baz'::
3733
3753
 
3734
 
            brz check baz
 
3754
            bzr check baz
3735
3755
    """
3736
3756
 
3737
3757
    _see_also = ['reconcile']
3746
3766
 
3747
3767
    def run(self, path=None, verbose=False, branch=False, repo=False,
3748
3768
            tree=False):
3749
 
        from .check import check_dwim
 
3769
        from bzrlib.check import check_dwim
3750
3770
        if path is None:
3751
3771
            path = '.'
3752
3772
        if not branch and not repo and not tree:
3791
3811
    takes_args = ['url?']
3792
3812
    takes_options = [
3793
3813
        RegistryOption('format',
3794
 
            help='Upgrade to a specific format.  See "brz help'
 
3814
            help='Upgrade to a specific format.  See "bzr help'
3795
3815
                 ' formats" for details.',
3796
 
            lazy_registry=('breezy.controldir', 'format_registry'),
3797
 
            converter=lambda name: controldir.format_registry.make_controldir(name),
 
3816
            lazy_registry=('bzrlib.controldir', 'format_registry'),
 
3817
            converter=lambda name: controldir.format_registry.make_bzrdir(name),
3798
3818
            value_switches=True, title='Branch format'),
3799
3819
        Option('clean',
3800
3820
            help='Remove the backup.bzr directory if successful.'),
3803
3823
    ]
3804
3824
 
3805
3825
    def run(self, url='.', format=None, clean=False, dry_run=False):
3806
 
        from .upgrade import upgrade
 
3826
        from bzrlib.upgrade import upgrade
3807
3827
        exceptions = upgrade(url, format, clean_up=clean, dry_run=dry_run)
3808
3828
        if exceptions:
3809
3829
            if len(exceptions) == 1:
3814
3834
 
3815
3835
 
3816
3836
class cmd_whoami(Command):
3817
 
    __doc__ = """Show or set brz user id.
 
3837
    __doc__ = """Show or set bzr user id.
3818
3838
 
3819
3839
    :Examples:
3820
3840
        Show the email of the current user::
3821
3841
 
3822
 
            brz whoami --email
 
3842
            bzr whoami --email
3823
3843
 
3824
3844
        Set the current user::
3825
3845
 
3826
 
            brz whoami "Frank Chu <fchu@example.com>"
 
3846
            bzr whoami "Frank Chu <fchu@example.com>"
3827
3847
    """
3828
3848
    takes_options = [ 'directory',
3829
3849
                      Option('email',
3861
3881
        # display a warning if an email address isn't included in the given name.
3862
3882
        try:
3863
3883
            _mod_config.extract_email_address(name)
3864
 
        except _mod_config.NoEmailInUsername as e:
 
3884
        except errors.NoEmailInUsername, e:
3865
3885
            warning('"%s" does not seem to contain an email address.  '
3866
3886
                    'This is allowed, but not recommended.', name)
3867
3887
 
3910
3930
    :Examples:
3911
3931
        Show the current aliases::
3912
3932
 
3913
 
            brz alias
 
3933
            bzr alias
3914
3934
 
3915
3935
        Show the alias specified for 'll'::
3916
3936
 
3917
 
            brz alias ll
 
3937
            bzr alias ll
3918
3938
 
3919
3939
        Set an alias for 'll'::
3920
3940
 
3921
 
            brz alias ll="log --line -r-10..-1"
 
3941
            bzr alias ll="log --line -r-10..-1"
3922
3942
 
3923
3943
        To remove an alias for 'll'::
3924
3944
 
3925
 
            brz alias --remove ll
 
3945
            bzr alias --remove ll
3926
3946
 
3927
3947
    """
3928
3948
    takes_args = ['name?']
3945
3965
    def remove_alias(self, alias_name):
3946
3966
        if alias_name is None:
3947
3967
            raise errors.BzrCommandError(gettext(
3948
 
                'brz alias --remove expects an alias to remove.'))
 
3968
                'bzr alias --remove expects an alias to remove.'))
3949
3969
        # If alias is not found, print something like:
3950
3970
        # unalias: foo: not found
3951
3971
        c = _mod_config.GlobalConfig()
3955
3975
    def print_aliases(self):
3956
3976
        """Print out the defined aliases in a similar format to bash."""
3957
3977
        aliases = _mod_config.GlobalConfig().get_aliases()
3958
 
        for key, value in sorted(viewitems(aliases)):
3959
 
            self.outf.write('brz alias %s="%s"\n' % (key, value))
 
3978
        for key, value in sorted(aliases.iteritems()):
 
3979
            self.outf.write('bzr alias %s="%s"\n' % (key, value))
3960
3980
 
3961
3981
    @display_command
3962
3982
    def print_alias(self, alias_name):
3963
 
        from .commands import get_alias
 
3983
        from bzrlib.commands import get_alias
3964
3984
        alias = get_alias(alias_name)
3965
3985
        if alias is None:
3966
 
            self.outf.write("brz alias: %s: not found\n" % alias_name)
 
3986
            self.outf.write("bzr alias: %s: not found\n" % alias_name)
3967
3987
        else:
3968
3988
            self.outf.write(
3969
 
                'brz alias %s="%s"\n' % (alias_name, ' '.join(alias)))
 
3989
                'bzr alias %s="%s"\n' % (alias_name, ' '.join(alias)))
3970
3990
 
3971
3991
    def set_alias(self, alias_name, alias_command):
3972
3992
        """Save the alias in the global config."""
4008
4028
    Tests that need working space on disk use a common temporary directory,
4009
4029
    typically inside $TMPDIR or /tmp.
4010
4030
 
4011
 
    If you set BRZ_TEST_PDB=1 when running selftest, failing tests will drop
 
4031
    If you set BZR_TEST_PDB=1 when running selftest, failing tests will drop
4012
4032
    into a pdb postmortem session.
4013
4033
 
4014
4034
    The --coverage=DIRNAME global option produces a report with covered code
4017
4037
    :Examples:
4018
4038
        Run only tests relating to 'ignore'::
4019
4039
 
4020
 
            brz selftest ignore
 
4040
            bzr selftest ignore
4021
4041
 
4022
4042
        Disable plugins and list tests as they're run::
4023
4043
 
4024
 
            brz --no-plugins selftest -v
 
4044
            bzr --no-plugins selftest -v
4025
4045
    """
4026
4046
    # NB: this is used from the class without creating an instance, which is
4027
4047
    # why it does not have a self parameter.
4028
4048
    def get_transport_type(typestring):
4029
4049
        """Parse and return a transport specifier."""
4030
4050
        if typestring == "sftp":
4031
 
            from .tests import stub_sftp
 
4051
            from bzrlib.tests import stub_sftp
4032
4052
            return stub_sftp.SFTPAbsoluteServer
4033
4053
        elif typestring == "memory":
4034
 
            from .tests import test_server
 
4054
            from bzrlib.tests import test_server
4035
4055
            return memory.MemoryServer
4036
4056
        elif typestring == "fakenfs":
4037
 
            from .tests import test_server
 
4057
            from bzrlib.tests import test_server
4038
4058
            return test_server.FakeNFSServer
4039
4059
        msg = "No known transport type %s. Supported types are: sftp\n" %\
4040
4060
            (typestring)
4067
4087
                            help='List the tests instead of running them.'),
4068
4088
                     RegistryOption('parallel',
4069
4089
                        help="Run the test suite in parallel.",
4070
 
                        lazy_registry=('breezy.tests', 'parallel_registry'),
 
4090
                        lazy_registry=('bzrlib.tests', 'parallel_registry'),
4071
4091
                        value_switches=False,
4072
4092
                        ),
4073
 
                     Option('randomize', type=text_type, argname="SEED",
 
4093
                     Option('randomize', type=str, argname="SEED",
4074
4094
                            help='Randomize the order of tests using the given'
4075
4095
                                 ' seed or "now" for the current time.'),
4076
 
                     ListOption('exclude', type=text_type, argname="PATTERN",
 
4096
                     ListOption('exclude', type=str, argname="PATTERN",
4077
4097
                                short_name='x',
4078
4098
                                help='Exclude tests that match this regular'
4079
4099
                                ' expression.'),
4080
 
                     Option('subunit1',
4081
 
                            help='Output test progress via subunit v1.'),
4082
 
                     Option('subunit2',
4083
 
                            help='Output test progress via subunit v2.'),
 
4100
                     Option('subunit',
 
4101
                        help='Output test progress via subunit.'),
4084
4102
                     Option('strict', help='Fail on missing dependencies or '
4085
4103
                            'known failures.'),
4086
 
                     Option('load-list', type=text_type, argname='TESTLISTFILE',
 
4104
                     Option('load-list', type=str, argname='TESTLISTFILE',
4087
4105
                            help='Load a test id list from a text file.'),
4088
 
                     ListOption('debugflag', type=text_type, short_name='E',
 
4106
                     ListOption('debugflag', type=str, short_name='E',
4089
4107
                                help='Turn on a selftest debug flag.'),
4090
 
                     ListOption('starting-with', type=text_type, argname='TESTID',
 
4108
                     ListOption('starting-with', type=str, argname='TESTID',
4091
4109
                                param_name='starting_with', short_name='s',
4092
4110
                                help=
4093
4111
                                'Load only the tests starting with TESTID.'),
4106
4124
            lsprof_timed=None,
4107
4125
            first=False, list_only=False,
4108
4126
            randomize=None, exclude=None, strict=False,
4109
 
            load_list=None, debugflag=None, starting_with=None, subunit1=False,
4110
 
            subunit2=False, parallel=None, lsprof_tests=False, sync=False):
 
4127
            load_list=None, debugflag=None, starting_with=None, subunit=False,
 
4128
            parallel=None, lsprof_tests=False,
 
4129
            sync=False):
4111
4130
 
4112
4131
        # During selftest, disallow proxying, as it can cause severe
4113
4132
        # performance penalties and is only needed for thread
4115
4134
        # too heavily. The call should be as early as possible, as
4116
4135
        # error reporting for past duplicate imports won't have useful
4117
4136
        # backtraces.
4118
 
        if sys.version_info[0] < 3:
4119
 
            # TODO(pad.lv/1696545): Allow proxying on Python 3, since
4120
 
            # disallowing it currently leads to failures in many places.
4121
 
            lazy_import.disallow_proxying()
 
4137
        lazy_import.disallow_proxying()
4122
4138
 
4123
 
        try:
4124
 
            from . import tests
4125
 
        except ImportError:
4126
 
            raise errors.BzrCommandError("tests not available. Install the "
4127
 
                "breezy tests to run the breezy testsuite.")
 
4139
        from bzrlib import tests
4128
4140
 
4129
4141
        if testspecs_list is not None:
4130
4142
            pattern = '|'.join(testspecs_list)
4131
4143
        else:
4132
4144
            pattern = ".*"
4133
 
        if subunit1:
 
4145
        if subunit:
4134
4146
            try:
4135
 
                from .tests import SubUnitBzrRunnerv1
 
4147
                from bzrlib.tests import SubUnitBzrRunner
4136
4148
            except ImportError:
4137
 
                raise errors.BzrCommandError(gettext(
4138
 
                    "subunit not available. subunit needs to be installed "
4139
 
                    "to use --subunit."))
4140
 
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv1
 
4149
                raise errors.BzrCommandError(gettext("subunit not available. subunit "
 
4150
                    "needs to be installed to use --subunit."))
 
4151
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
4141
4152
            # On Windows, disable automatic conversion of '\n' to '\r\n' in
4142
4153
            # stdout, which would corrupt the subunit stream. 
4143
4154
            # FIXME: This has been fixed in subunit trunk (>0.0.5) so the
4147
4158
                and getattr(sys.stdout, 'fileno', None) is not None):
4148
4159
                import msvcrt
4149
4160
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
4150
 
        if subunit2:
4151
 
            try:
4152
 
                from .tests import SubUnitBzrRunnerv2
4153
 
            except ImportError:
4154
 
                raise errors.BzrCommandError(gettext(
4155
 
                    "subunit not available. subunit "
4156
 
                    "needs to be installed to use --subunit2."))
4157
 
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunnerv2
4158
 
 
4159
4161
        if parallel:
4160
4162
            self.additional_selftest_args.setdefault(
4161
4163
                'suite_decorators', []).append(parallel)
4162
4164
        if benchmark:
4163
4165
            raise errors.BzrCommandError(gettext(
4164
 
                "--benchmark is no longer supported from brz 2.2; "
 
4166
                "--benchmark is no longer supported from bzr 2.2; "
4165
4167
                "use bzr-usertest instead"))
4166
4168
        test_suite_factory = None
4167
4169
        if not exclude:
4208
4210
 
4209
4211
 
4210
4212
class cmd_version(Command):
4211
 
    __doc__ = """Show version of brz."""
 
4213
    __doc__ = """Show version of bzr."""
4212
4214
 
4213
4215
    encoding_type = 'replace'
4214
4216
    takes_options = [
4217
4219
 
4218
4220
    @display_command
4219
4221
    def run(self, short=False):
4220
 
        from .version import show_version
 
4222
        from bzrlib.version import show_version
4221
4223
        if short:
4222
 
            self.outf.write(breezy.version_string + '\n')
 
4224
            self.outf.write(bzrlib.version_string + '\n')
4223
4225
        else:
4224
4226
            show_version(to_file=self.outf)
4225
4227
 
4243
4245
 
4244
4246
    @display_command
4245
4247
    def run(self, branch, other):
4246
 
        from .revision import ensure_null
 
4248
        from bzrlib.revision import ensure_null
4247
4249
 
4248
4250
        branch1 = Branch.open_containing(branch)[0]
4249
4251
        branch2 = Branch.open_containing(other)[0]
4263
4265
 
4264
4266
    The source of the merge can be specified either in the form of a branch,
4265
4267
    or in the form of a path to a file containing a merge directive generated
4266
 
    with brz send. If neither is specified, the default is the upstream branch
 
4268
    with bzr send. If neither is specified, the default is the upstream branch
4267
4269
    or the branch most recently merged using --remember.  The source of the
4268
4270
    merge may also be specified in the form of a path to a file in another
4269
4271
    branch:  in this case, only the modifications to that file are merged into
4270
4272
    the current working tree.
4271
4273
 
4272
 
    When merging from a branch, by default brz will try to merge in all new
 
4274
    When merging from a branch, by default bzr will try to merge in all new
4273
4275
    work from the other branch, automatically determining an appropriate base
4274
4276
    revision.  If this fails, you may need to give an explicit base.
4275
4277
 
4276
 
    To pick a different ending revision, pass "--revision OTHER".  brz will
 
4278
    To pick a different ending revision, pass "--revision OTHER".  bzr will
4277
4279
    try to merge in all new work up to and including revision OTHER.
4278
4280
 
4279
4281
    If you specify two values, "--revision BASE..OTHER", only revisions BASE
4291
4293
    it will mark a conflict.  A conflict means that you need to fix something,
4292
4294
    before you can commit.
4293
4295
 
4294
 
    Use brz resolve when you have fixed a problem.  See also brz conflicts.
 
4296
    Use bzr resolve when you have fixed a problem.  See also bzr conflicts.
4295
4297
 
4296
4298
    If there is no default branch set, the first merge will set it (use
4297
4299
    --no-remember to avoid setting it). After that, you can omit the branch
4299
4301
    only be saved if the remote location can be accessed.
4300
4302
 
4301
4303
    The results of the merge are placed into the destination working
4302
 
    directory, where they can be reviewed (with brz diff), tested, and then
 
4304
    directory, where they can be reviewed (with bzr diff), tested, and then
4303
4305
    committed to record the result of the merge.
4304
4306
 
4305
4307
    merge refuses to run if there are any uncommitted changes, unless
4306
 
    --force is given.  If --force is given, then the changes from the source
 
4308
    --force is given.  If --force is given, then the changes from the source 
4307
4309
    will be merged with the current working tree, including any uncommitted
4308
4310
    changes in the tree.  The --force option can also be used to create a
4309
4311
    merge revision which has more than two parents.
4316
4318
    you to apply each diff hunk and file change, similar to "shelve".
4317
4319
 
4318
4320
    :Examples:
4319
 
        To merge all new revisions from brz.dev::
4320
 
 
4321
 
            brz merge ../brz.dev
4322
 
 
4323
 
        To merge changes up to and including revision 82 from brz.dev::
4324
 
 
4325
 
            brz merge -r 82 ../brz.dev
 
4321
        To merge all new revisions from bzr.dev::
 
4322
 
 
4323
            bzr merge ../bzr.dev
 
4324
 
 
4325
        To merge changes up to and including revision 82 from bzr.dev::
 
4326
 
 
4327
            bzr merge -r 82 ../bzr.dev
4326
4328
 
4327
4329
        To merge the changes introduced by 82, without previous changes::
4328
4330
 
4329
 
            brz merge -r 81..82 ../brz.dev
 
4331
            bzr merge -r 81..82 ../bzr.dev
4330
4332
 
4331
4333
        To apply a merge directive contained in /tmp/merge::
4332
4334
 
4333
 
            brz merge /tmp/merge
 
4335
            bzr merge /tmp/merge
4334
4336
 
4335
4337
        To create a merge revision with three parents from two branches
4336
4338
        feature1a and feature1b:
4337
4339
 
4338
 
            brz merge ../feature1a
4339
 
            brz merge ../feature1b --force
4340
 
            brz commit -m 'revision with three parents'
 
4340
            bzr merge ../feature1a
 
4341
            bzr merge ../feature1b --force
 
4342
            bzr commit -m 'revision with three parents'
4341
4343
    """
4342
4344
 
4343
4345
    encoding_type = 'exact'
4420
4422
                    raise errors.BzrCommandError(gettext(
4421
4423
                        'Cannot use -r with merge directives or bundles'))
4422
4424
                merger, verified = _mod_merge.Merger.from_mergeable(tree,
4423
 
                   mergeable)
 
4425
                   mergeable, None)
4424
4426
 
4425
4427
        if merger is None and uncommitted:
4426
4428
            if revision is not None and len(revision) > 0:
4459
4461
        if merger.this_basis is None:
4460
4462
            raise errors.BzrCommandError(gettext(
4461
4463
                "This branch has no commits."
4462
 
                " (perhaps you would prefer 'brz pull')"))
 
4464
                " (perhaps you would prefer 'bzr pull')"))
4463
4465
        if preview:
4464
4466
            return self._do_preview(merger)
4465
4467
        elif interactive:
4476
4478
        return result_tree
4477
4479
 
4478
4480
    def _do_preview(self, merger):
4479
 
        from .diff import show_diff_trees
 
4481
        from bzrlib.diff import show_diff_trees
4480
4482
        result_tree = self._get_preview(merger)
4481
4483
        path_encoding = osutils.get_diff_header_encoding()
4482
4484
        show_diff_trees(merger.this_tree, result_tree, self.outf,
4502
4504
        Shelver to selectively remove the differences between the working tree
4503
4505
        and the preview tree.
4504
4506
        """
4505
 
        from . import shelf_ui
 
4507
        from bzrlib import shelf_ui
4506
4508
        result_tree = self._get_preview(merger)
4507
 
        writer = breezy.option.diff_writer_registry.get()
 
4509
        writer = bzrlib.option.diff_writer_registry.get()
4508
4510
        shelver = shelf_ui.Shelver(merger.this_tree, result_tree, destroy=True,
4509
4511
                                   reporter=shelf_ui.ApplyReporter(),
4510
 
                                   diff_writer=writer(self.outf))
 
4512
                                   diff_writer=writer(sys.stdout))
4511
4513
        try:
4512
4514
            shelver.run()
4513
4515
        finally:
4532
4534
            raise errors.BzrCommandError(gettext("Cannot do conflict reduction and"
4533
4535
                                         " show base."))
4534
4536
 
4535
 
        if (merger.merge_type.requires_file_merge_plan and
4536
 
            (not getattr(merger.this_tree, 'plan_file_merge', None) or
4537
 
             not getattr(merger.other_tree, 'plan_file_merge', None) or
4538
 
             (merger.base_tree is not None and
4539
 
                 not getattr(merger.base_tree, 'plan_file_merge', None)))):
4540
 
            raise errors.BzrCommandError(
4541
 
                 gettext('Plan file merge unsupported: '
4542
 
                         'Merge type incompatible with tree formats.'))
4543
 
 
4544
4537
    def _get_merger_from_branch(self, tree, location, revision, remember,
4545
4538
                                possible_transports, pb):
4546
4539
        """Produce a merger from a location, assuming it refers to a branch."""
 
4540
        from bzrlib.tag import _merge_tags_if_possible
4547
4541
        # find the branch locations
4548
4542
        other_loc, user_location = self._select_branch_location(tree, location,
4549
4543
            revision, -1)
4583
4577
            tree.branch.set_submit_branch(other_branch.base)
4584
4578
        # Merge tags (but don't set them in the master branch yet, the user
4585
4579
        # might revert this merge).  Commit will propagate them.
4586
 
        other_branch.tags.merge_to(tree.branch.tags, ignore_master=True)
4587
 
        merger = _mod_merge.Merger.from_revision_ids(tree,
 
4580
        _merge_tags_if_possible(other_branch, tree.branch, ignore_master=True)
 
4581
        merger = _mod_merge.Merger.from_revision_ids(pb, tree,
4588
4582
            other_revision_id, base_revision_id, other_branch, base_branch)
4589
4583
        if other_path != '':
4590
4584
            allow_pending = False
4670
4664
        Re-do the merge of all conflicted files, and show the base text in
4671
4665
        conflict regions, in addition to the usual THIS and OTHER texts::
4672
4666
 
4673
 
            brz remerge --show-base
 
4667
            bzr remerge --show-base
4674
4668
 
4675
4669
        Re-do the merge of "foobar", using the weave merge algorithm, with
4676
4670
        additional processing to reduce the size of conflict regions::
4677
4671
 
4678
 
            brz remerge --merge-type weave --reprocess foobar
 
4672
            bzr remerge --merge-type weave --reprocess foobar
4679
4673
    """
4680
4674
    takes_args = ['file*']
4681
4675
    takes_options = [
4687
4681
 
4688
4682
    def run(self, file_list=None, merge_type=None, show_base=False,
4689
4683
            reprocess=False):
4690
 
        from .conflicts import restore
 
4684
        from bzrlib.conflicts import restore
4691
4685
        if merge_type is None:
4692
4686
            merge_type = _mod_merge.Merge3Merger
4693
4687
        tree, file_list = WorkingTree.open_containing_paths(file_list)
4698
4692
                                         " merges.  Not cherrypicking or"
4699
4693
                                         " multi-merges."))
4700
4694
        repository = tree.branch.repository
4701
 
        interesting_files = None
 
4695
        interesting_ids = None
4702
4696
        new_conflicts = []
4703
4697
        conflicts = tree.conflicts()
4704
4698
        if file_list is not None:
4705
 
            interesting_files = set()
 
4699
            interesting_ids = set()
4706
4700
            for filename in file_list:
4707
 
                if not tree.is_versioned(filename):
 
4701
                file_id = tree.path2id(filename)
 
4702
                if file_id is None:
4708
4703
                    raise errors.NotVersionedError(filename)
4709
 
                interesting_files.add(filename)
4710
 
                if tree.kind(filename) != "directory":
 
4704
                interesting_ids.add(file_id)
 
4705
                if tree.kind(file_id) != "directory":
4711
4706
                    continue
4712
4707
 
4713
 
                for path, ie in tree.iter_entries_by_dir(specific_files=[filename]):
4714
 
                    interesting_files.add(path)
 
4708
                # FIXME: Support nested trees
 
4709
                for name, ie in tree.root_inventory.iter_entries(file_id):
 
4710
                    interesting_ids.add(ie.file_id)
4715
4711
            new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
4716
4712
        else:
4717
4713
            # Remerge only supports resolving contents conflicts
4718
4714
            allowed_conflicts = ('text conflict', 'contents conflict')
4719
4715
            restore_files = [c.path for c in conflicts
4720
4716
                             if c.typestring in allowed_conflicts]
4721
 
        _mod_merge.transform_tree(tree, tree.basis_tree(), interesting_files)
 
4717
        _mod_merge.transform_tree(tree, tree.basis_tree(), interesting_ids)
4722
4718
        tree.set_conflicts(ConflictList(new_conflicts))
4723
4719
        if file_list is not None:
4724
4720
            restore_files = file_list
4734
4730
        # have not yet been seen.
4735
4731
        tree.set_parent_ids(parents[:1])
4736
4732
        try:
4737
 
            merger = _mod_merge.Merger.from_revision_ids(tree, parents[1])
4738
 
            merger.interesting_files = interesting_files
 
4733
            merger = _mod_merge.Merger.from_revision_ids(None, tree, parents[1])
 
4734
            merger.interesting_ids = interesting_ids
4739
4735
            merger.merge_type = merge_type
4740
4736
            merger.show_base = show_base
4741
4737
            merger.reprocess = reprocess
4786
4782
    not yet committed. These revisions will be included as additional parents
4787
4783
    of the next commit.  Normally, using revert clears that list as well as
4788
4784
    reverting the files.  If any files are specified, revert leaves the list
4789
 
    of uncommitted merges alone and reverts only the files.  Use ``brz revert
 
4785
    of uncommitted merges alone and reverts only the files.  Use ``bzr revert
4790
4786
    .`` in the tree root to revert all files but keep the recorded merges,
4791
 
    and ``brz revert --forget-merges`` to clear the pending merge list without
 
4787
    and ``bzr revert --forget-merges`` to clear the pending merge list without
4792
4788
    reverting any files.
4793
4789
 
4794
 
    Using "brz revert --forget-merges", it is possible to apply all of the
 
4790
    Using "bzr revert --forget-merges", it is possible to apply all of the
4795
4791
    changes from a branch in a single revision.  To do this, perform the merge
4796
4792
    as desired.  Then doing revert with the "--forget-merges" option will keep
4797
4793
    the content of the tree as it was, but it will clear the list of pending
4850
4846
 
4851
4847
    @display_command
4852
4848
    def run(self, topic=None, long=False):
4853
 
        import breezy.help
 
4849
        import bzrlib.help
4854
4850
        if topic is None and long:
4855
4851
            topic = "commands"
4856
 
        breezy.help.help(topic)
 
4852
        bzrlib.help.help(topic)
4857
4853
 
4858
4854
 
4859
4855
class cmd_shell_complete(Command):
4860
4856
    __doc__ = """Show appropriate completions for context.
4861
4857
 
4862
 
    For a list of all available commands, say 'brz shell-complete'.
 
4858
    For a list of all available commands, say 'bzr shell-complete'.
4863
4859
    """
4864
4860
    takes_args = ['context?']
4865
4861
    aliases = ['s-c']
4867
4863
 
4868
4864
    @display_command
4869
4865
    def run(self, context=None):
4870
 
        from . import shellcomplete
 
4866
        from bzrlib import shellcomplete
4871
4867
        shellcomplete.shellcomplete(context)
4872
4868
 
4873
4869
 
4889
4885
        Determine the missing revisions between this and the branch at the
4890
4886
        remembered pull location::
4891
4887
 
4892
 
            brz missing
 
4888
            bzr missing
4893
4889
 
4894
4890
        Determine the missing revisions between this and another branch::
4895
4891
 
4896
 
            brz missing http://server/branch
 
4892
            bzr missing http://server/branch
4897
4893
 
4898
4894
        Determine the missing revisions up to a specific revision on the other
4899
4895
        branch::
4900
4896
 
4901
 
            brz missing -r ..-10
 
4897
            bzr missing -r ..-10
4902
4898
 
4903
4899
        Determine the missing revisions up to a specific revision on this
4904
4900
        branch::
4905
4901
 
4906
 
            brz missing --my-revision ..-10
 
4902
            bzr missing --my-revision ..-10
4907
4903
    """
4908
4904
 
4909
4905
    _see_also = ['merge', 'pull']
4913
4909
        Option('reverse', 'Reverse the order of revisions.'),
4914
4910
        Option('mine-only',
4915
4911
               'Display changes in the local branch only.'),
4916
 
        Option('this', 'Same as --mine-only.'),
 
4912
        Option('this' , 'Same as --mine-only.'),
4917
4913
        Option('theirs-only',
4918
4914
               'Display changes in the remote branch only.'),
4919
4915
        Option('other', 'Same as --theirs-only.'),
4940
4936
            log_format=None, long=False, short=False, line=False,
4941
4937
            show_ids=False, verbose=False, this=False, other=False,
4942
4938
            include_merged=None, revision=None, my_revision=None,
4943
 
            directory=u'.'):
4944
 
        from breezy.missing import find_unmerged, iter_log_revisions
 
4939
            directory=u'.',
 
4940
            include_merges=symbol_versioning.DEPRECATED_PARAMETER):
 
4941
        from bzrlib.missing import find_unmerged, iter_log_revisions
4945
4942
        def message(s):
4946
4943
            if not is_quiet():
4947
4944
                self.outf.write(s)
4948
4945
 
 
4946
        if symbol_versioning.deprecated_passed(include_merges):
 
4947
            ui.ui_factory.show_user_warning(
 
4948
                'deprecated_command_option',
 
4949
                deprecated_name='--include-merges',
 
4950
                recommended_name='--include-merged',
 
4951
                deprecated_in_version='2.5',
 
4952
                command=self.invoked_as)
 
4953
            if include_merged is None:
 
4954
                include_merged = include_merges
 
4955
            else:
 
4956
                raise errors.BzrCommandError(gettext(
 
4957
                    '{0} and {1} are mutually exclusive').format(
 
4958
                    '--include-merges', '--include-merged'))
4949
4959
        if include_merged is None:
4950
4960
            include_merged = False
4951
4961
        if this:
5116
5126
 
5117
5127
    @display_command
5118
5128
    def run(self, verbose=False):
5119
 
        from . import plugin
 
5129
        from bzrlib import plugin
5120
5130
        # Don't give writelines a generator as some codecs don't like that
5121
5131
        self.outf.writelines(
5122
5132
            list(plugin.describe_plugins(show_paths=verbose)))
5133
5143
    encoding_type = 'exact'
5134
5144
    @display_command
5135
5145
    def run(self, branch=u'.', revision=None, long=False, strict=False):
5136
 
        from .testament import Testament, StrictTestament
 
5146
        from bzrlib.testament import Testament, StrictTestament
5137
5147
        if strict is True:
5138
5148
            testament_class = StrictTestament
5139
5149
        else:
5179
5189
    @display_command
5180
5190
    def run(self, filename, all=False, long=False, revision=None,
5181
5191
            show_ids=False, directory=None):
5182
 
        from .annotate import (
 
5192
        from bzrlib.annotate import (
5183
5193
            annotate_file_tree,
5184
5194
            )
5185
5195
        wt, branch, relpath = \
5199
5209
        if wt is not None and revision is None:
5200
5210
            # If there is a tree and we're not annotating historical
5201
5211
            # versions, annotate the working tree's content.
5202
 
            annotate_file_tree(wt, relpath, self.outf, long, all,
5203
 
                show_ids=show_ids, file_id=file_id)
 
5212
            annotate_file_tree(wt, file_id, self.outf, long, all,
 
5213
                show_ids=show_ids)
5204
5214
        else:
5205
 
            annotate_file_tree(tree, relpath, self.outf, long, all,
5206
 
                show_ids=show_ids, branch=branch, file_id=file_id)
 
5215
            annotate_file_tree(tree, file_id, self.outf, long, all,
 
5216
                show_ids=show_ids, branch=branch)
5207
5217
 
5208
5218
 
5209
5219
class cmd_re_sign(Command):
5224
5234
        return self._run(b, revision_id_list, revision)
5225
5235
 
5226
5236
    def _run(self, b, revision_id_list, revision):
 
5237
        import bzrlib.gpg as gpg
5227
5238
        gpg_strategy = gpg.GPGStrategy(b.get_config_stack())
5228
5239
        if revision_id_list is not None:
5229
5240
            b.repository.start_write_group()
5230
5241
            try:
5231
5242
                for revision_id in revision_id_list:
5232
 
                    revision_id = cache_utf8.encode(revision_id)
5233
5243
                    b.repository.sign_revision(revision_id, gpg_strategy)
5234
5244
            except:
5235
5245
                b.repository.abort_write_group()
5339
5349
    remove anything.
5340
5350
 
5341
5351
    If --revision is specified, uncommit revisions to leave the branch at the
5342
 
    specified revision.  For example, "brz uncommit -r 15" will leave the
 
5352
    specified revision.  For example, "bzr uncommit -r 15" will leave the
5343
5353
    branch at revision 15.
5344
5354
 
5345
5355
    Uncommit leaves the working tree ready for a new commit.  The only change
5387
5397
 
5388
5398
    def _run(self, b, tree, dry_run, verbose, revision, force, local,
5389
5399
             keep_tags):
5390
 
        from .log import log_formatter, show_log
5391
 
        from .uncommit import uncommit
 
5400
        from bzrlib.log import log_formatter, show_log
 
5401
        from bzrlib.uncommit import uncommit
5392
5402
 
5393
5403
        last_revno, last_rev_id = b.last_revision_info()
5394
5404
 
5397
5407
            revno = last_revno
5398
5408
            rev_id = last_rev_id
5399
5409
        else:
5400
 
            # 'brz uncommit -r 10' actually means uncommit
 
5410
            # 'bzr uncommit -r 10' actually means uncommit
5401
5411
            # so that the final tree is at revno 10.
5402
 
            # but breezy.uncommit.uncommit() actually uncommits
 
5412
            # but bzrlib.uncommit.uncommit() actually uncommits
5403
5413
            # the revisions that are supplied.
5404
5414
            # So we need to offset it by one
5405
5415
            revno = revision[0].in_history(b).revno + 1
5430
5440
        if not force:
5431
5441
            if not ui.ui_factory.confirm_action(
5432
5442
                    gettext(u'Uncommit these revisions'),
5433
 
                    'breezy.builtins.uncommit',
 
5443
                    'bzrlib.builtins.uncommit',
5434
5444
                    {}):
5435
5445
                self.outf.write(gettext('Canceled\n'))
5436
5446
                return 0
5440
5450
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
5441
5451
                 revno=revno, local=local, keep_tags=keep_tags)
5442
5452
        self.outf.write(gettext('You can restore the old tip by running:\n'
5443
 
             '  brz pull . -r revid:%s\n') % last_rev_id)
 
5453
             '  bzr pull . -r revid:%s\n') % last_rev_id)
5444
5454
 
5445
5455
 
5446
5456
class cmd_break_lock(Command):
5452
5462
    CAUTION: Locks should only be broken when you are sure that the process
5453
5463
    holding the lock has been stopped.
5454
5464
 
5455
 
    You can get information on what locks are open via the 'brz info
 
5465
    You can get information on what locks are open via the 'bzr info
5456
5466
    [location]' command.
5457
5467
 
5458
5468
    :Examples:
5459
 
        brz break-lock
5460
 
        brz break-lock brz+ssh://example.com/brz/foo
5461
 
        brz break-lock --conf ~/.bazaar
 
5469
        bzr break-lock
 
5470
        bzr break-lock bzr+ssh://example.com/bzr/foo
 
5471
        bzr break-lock --conf ~/.bazaar
5462
5472
    """
5463
5473
 
5464
5474
    takes_args = ['location?']
5475
5485
        if force:
5476
5486
            ui.ui_factory = ui.ConfirmationUserInterfacePolicy(ui.ui_factory,
5477
5487
                None,
5478
 
                {'breezy.lockdir.break': True})
 
5488
                {'bzrlib.lockdir.break': True})
5479
5489
        if config:
5480
5490
            conf = _mod_config.LockableConfig(file_name=location)
5481
5491
            conf.break_lock()
5488
5498
 
5489
5499
 
5490
5500
class cmd_wait_until_signalled(Command):
5491
 
    __doc__ = """Test helper for test_start_and_stop_brz_subprocess_send_signal.
 
5501
    __doc__ = """Test helper for test_start_and_stop_bzr_subprocess_send_signal.
5492
5502
 
5493
5503
    This just prints a line to signal when it is ready, then blocks on stdin.
5494
5504
    """
5496
5506
    hidden = True
5497
5507
 
5498
5508
    def run(self):
5499
 
        self.outf.write("running\n")
5500
 
        self.outf.flush()
 
5509
        sys.stdout.write("running\n")
 
5510
        sys.stdout.flush()
5501
5511
        sys.stdin.readline()
5502
5512
 
5503
5513
 
5504
5514
class cmd_serve(Command):
5505
 
    __doc__ = """Run the brz server."""
 
5515
    __doc__ = """Run the bzr server."""
5506
5516
 
5507
5517
    aliases = ['server']
5508
5518
 
5511
5521
               help='Serve on stdin/out for use from inetd or sshd.'),
5512
5522
        RegistryOption('protocol',
5513
5523
               help="Protocol to serve.",
5514
 
               lazy_registry=('breezy.transport', 'transport_server_registry'),
 
5524
               lazy_registry=('bzrlib.transport', 'transport_server_registry'),
5515
5525
               value_switches=True),
5516
5526
        Option('listen',
5517
 
               help='Listen for connections on nominated address.', type=text_type),
 
5527
               help='Listen for connections on nominated address.', type=str),
5518
5528
        Option('port',
5519
5529
               help='Listen for connections on nominated port.  Passing 0 as '
5520
5530
                    'the port number will result in a dynamically allocated '
5525
5535
        Option('allow-writes',
5526
5536
               help='By default the server is a readonly server.  Supplying '
5527
5537
                    '--allow-writes enables write access to the contents of '
5528
 
                    'the served directory and below.  Note that ``brz serve`` '
 
5538
                    'the served directory and below.  Note that ``bzr serve`` '
5529
5539
                    'does not perform authentication, so unless some form of '
5530
5540
                    'external authentication is arranged supplying this '
5531
5541
                    'option leads to global uncontrolled write access to your '
5537
5547
 
5538
5548
    def run(self, listen=None, port=None, inet=False, directory=None,
5539
5549
            allow_writes=False, protocol=None, client_timeout=None):
5540
 
        from . import transport
 
5550
        from bzrlib import transport
5541
5551
        if directory is None:
5542
 
            directory = osutils.getcwd()
 
5552
            directory = os.getcwd()
5543
5553
        if protocol is None:
5544
5554
            protocol = transport.transport_server_registry.get()
5545
5555
        url = transport.location_to_url(directory)
5555
5565
    This command requires the target tree to be in a rich-root format.
5556
5566
 
5557
5567
    The TREE argument should be an independent tree, inside another tree, but
5558
 
    not part of it.  (Such trees can be produced by "brz split", but also by
5559
 
    running "brz branch" with the target inside a tree.)
 
5568
    not part of it.  (Such trees can be produced by "bzr split", but also by
 
5569
    running "bzr branch" with the target inside a tree.)
5560
5570
 
5561
5571
    The result is a combined tree, with the subtree no longer an independent
5562
5572
    part.  This is marked as a merge of the subtree into the containing tree,
5570
5580
            ]
5571
5581
 
5572
5582
    def run(self, tree, reference=False):
5573
 
        from breezy.mutabletree import BadReferenceTarget
5574
5583
        sub_tree = WorkingTree.open(tree)
5575
5584
        parent_dir = osutils.dirname(sub_tree.basedir)
5576
5585
        containing_tree = WorkingTree.open_containing(parent_dir)[0]
5578
5587
        if not repo.supports_rich_root():
5579
5588
            raise errors.BzrCommandError(gettext(
5580
5589
                "Can't join trees because %s doesn't support rich root data.\n"
5581
 
                "You can use brz upgrade on the repository.")
 
5590
                "You can use bzr upgrade on the repository.")
5582
5591
                % (repo,))
5583
5592
        if reference:
5584
5593
            try:
5585
5594
                containing_tree.add_reference(sub_tree)
5586
 
            except BadReferenceTarget as e:
 
5595
            except errors.BadReferenceTarget, e:
5587
5596
                # XXX: Would be better to just raise a nicely printable
5588
5597
                # exception from the real origin.  Also below.  mbp 20070306
5589
5598
                raise errors.BzrCommandError(
5591
5600
        else:
5592
5601
            try:
5593
5602
                containing_tree.subsume(sub_tree)
5594
 
            except errors.BadSubsumeSource as e:
 
5603
            except errors.BadSubsumeSource, e:
5595
5604
                raise errors.BzrCommandError(
5596
5605
                       gettext("Cannot join {0}.  {1}").format(tree, e.reason))
5597
5606
 
5617
5626
        if sub_id is None:
5618
5627
            raise errors.NotVersionedError(subdir)
5619
5628
        try:
5620
 
            containing_tree.extract(subdir, sub_id)
 
5629
            containing_tree.extract(sub_id)
5621
5630
        except errors.RootNotRich:
5622
5631
            raise errors.RichRootUpgradeRequired(containing_tree.branch.base)
5623
5632
 
5656
5665
            diff='Normal unified diff.',
5657
5666
            plain='No patch, just directive.'),
5658
5667
        Option('sign', help='GPG-sign the directive.'), 'revision',
5659
 
        Option('mail-to', type=text_type,
 
5668
        Option('mail-to', type=str,
5660
5669
            help='Instead of printing the directive, email to this address.'),
5661
 
        Option('message', type=text_type, short_name='m',
 
5670
        Option('message', type=str, short_name='m',
5662
5671
            help='Message to use when committing this merge.')
5663
5672
        ]
5664
5673
 
5667
5676
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
5668
5677
            sign=False, revision=None, mail_to=None, message=None,
5669
5678
            directory=u'.'):
5670
 
        from .revision import ensure_null, NULL_REVISION
 
5679
        from bzrlib.revision import ensure_null, NULL_REVISION
5671
5680
        include_patch, include_bundle = {
5672
5681
            'plain': (False, False),
5673
5682
            'diff': (True, False),
5697
5706
        base_revision_id = None
5698
5707
        if revision is not None:
5699
5708
            if len(revision) > 2:
5700
 
                raise errors.BzrCommandError(gettext('brz merge-directive takes '
 
5709
                raise errors.BzrCommandError(gettext('bzr merge-directive takes '
5701
5710
                    'at most two one revision identifiers'))
5702
5711
            revision_id = revision[-1].as_revision_id(branch)
5703
5712
            if len(revision) == 2:
5737
5746
      directly from the merge directive, without retrieving data from a
5738
5747
      branch.
5739
5748
 
5740
 
    `brz send` creates a compact data set that, when applied using brz
 
5749
    `bzr send` creates a compact data set that, when applied using bzr
5741
5750
    merge, has the same effect as merging from the source branch.  
5742
5751
    
5743
5752
    By default the merge directive is self-contained and can be applied to any
5762
5771
    omit the location to use the default.  To change the default, use
5763
5772
    --remember. The value will only be saved if the location can be accessed.
5764
5773
 
5765
 
    In order to calculate those changes, brz must analyse the submit branch.
 
5774
    In order to calculate those changes, bzr must analyse the submit branch.
5766
5775
    Therefore it is most efficient for the submit branch to be a local mirror.
5767
5776
    If a public location is known for the submit_branch, that location is used
5768
5777
    in the merge directive.
5792
5801
    default.  "0.9" uses revision bundle format 0.9 and merge directive
5793
5802
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
5794
5803
 
5795
 
    The merge directives created by brz send may be applied using brz merge or
5796
 
    brz pull by specifying a file containing a merge directive as the location.
 
5804
    The merge directives created by bzr send may be applied using bzr merge or
 
5805
    bzr pull by specifying a file containing a merge directive as the location.
5797
5806
 
5798
 
    brz send makes extensive use of public locations to map local locations into
5799
 
    URLs that can be used by other people.  See `brz help configuration` to
5800
 
    set them, and use `brz info` to display them.
 
5807
    bzr send makes extensive use of public locations to map local locations into
 
5808
    URLs that can be used by other people.  See `bzr help configuration` to
 
5809
    set them, and use `bzr info` to display them.
5801
5810
    """
5802
5811
 
5803
5812
    encoding_type = 'exact'
5817
5826
               help='Branch to generate the submission from, '
5818
5827
               'rather than the one containing the working directory.',
5819
5828
               short_name='f',
5820
 
               type=text_type),
 
5829
               type=unicode),
5821
5830
        Option('output', short_name='o',
5822
5831
               help='Write merge directive to this file or directory; '
5823
5832
                    'use - for stdout.',
5824
 
               type=text_type),
 
5833
               type=unicode),
5825
5834
        Option('strict',
5826
5835
               help='Refuse to send if there are uncommitted changes in'
5827
5836
               ' the working tree, --no-strict disables the check.'),
5828
5837
        Option('mail-to', help='Mail the request to this address.',
5829
 
               type=text_type),
 
5838
               type=unicode),
5830
5839
        'revision',
5831
5840
        'message',
5832
 
        Option('body', help='Body for the email.', type=text_type),
 
5841
        Option('body', help='Body for the email.', type=unicode),
5833
5842
        RegistryOption('format',
5834
5843
                       help='Use the specified output format.',
5835
 
                       lazy_registry=('breezy.send', 'format_registry')),
 
5844
                       lazy_registry=('bzrlib.send', 'format_registry')),
5836
5845
        ]
5837
5846
 
5838
5847
    def run(self, submit_branch=None, public_branch=None, no_bundle=False,
5839
5848
            no_patch=False, revision=None, remember=None, output=None,
5840
5849
            format=None, mail_to=None, message=None, body=None,
5841
5850
            strict=None, **kwargs):
5842
 
        from .send import send
 
5851
        from bzrlib.send import send
5843
5852
        return send(submit_branch, revision, public_branch, remember,
5844
5853
                    format, no_bundle, no_patch, output,
5845
5854
                    kwargs.get('from', '.'), mail_to, message, body,
5891
5900
               help='Branch to generate the submission from, '
5892
5901
               'rather than the one containing the working directory.',
5893
5902
               short_name='f',
5894
 
               type=text_type),
 
5903
               type=unicode),
5895
5904
        Option('output', short_name='o', help='Write directive to this file.',
5896
 
               type=text_type),
 
5905
               type=unicode),
5897
5906
        Option('strict',
5898
5907
               help='Refuse to bundle revisions if there are uncommitted'
5899
5908
               ' changes in the working tree, --no-strict disables the check.'),
5900
5909
        'revision',
5901
5910
        RegistryOption('format',
5902
5911
                       help='Use the specified output format.',
5903
 
                       lazy_registry=('breezy.send', 'format_registry')),
 
5912
                       lazy_registry=('bzrlib.send', 'format_registry')),
5904
5913
        ]
5905
5914
    aliases = ['bundle']
5906
5915
 
5913
5922
            format=None, strict=None, **kwargs):
5914
5923
        if output is None:
5915
5924
            output = '-'
5916
 
        from .send import send
 
5925
        from bzrlib.send import send
5917
5926
        return send(submit_branch, revision, public_branch, remember,
5918
5927
                         format, no_bundle, no_patch, output,
5919
5928
                         kwargs.get('from', '.'), None, None, None,
5933
5942
    It is an error to give a tag name that already exists unless you pass
5934
5943
    --force, in which case the tag is moved to point to the new revision.
5935
5944
 
5936
 
    To rename a tag (change the name but keep it on the same revsion), run ``brz
5937
 
    tag new-name -r tag:old-name`` and then ``brz tag --delete oldname``.
 
5945
    To rename a tag (change the name but keep it on the same revsion), run ``bzr
 
5946
    tag new-name -r tag:old-name`` and then ``bzr tag --delete oldname``.
5938
5947
 
5939
5948
    If no tag name is specified it will be determined through the 
5940
5949
    'automatic_tag_name' hook. This can e.g. be used to automatically tag
5941
 
    upstream releases by reading configure.ac. See ``brz help hooks`` for
 
5950
    upstream releases by reading configure.ac. See ``bzr help hooks`` for
5942
5951
    details.
5943
5952
    """
5944
5953
 
6011
6020
            help='Branch whose tags should be displayed.'),
6012
6021
        RegistryOption('sort',
6013
6022
            'Sort tags by different criteria.', title='Sorting',
6014
 
            lazy_registry=('breezy.tag', 'tag_sort_methods')
 
6023
            lazy_registry=('bzrlib.tag', 'tag_sort_methods')
6015
6024
            ),
6016
6025
        'show-ids',
6017
6026
        'revision',
6019
6028
 
6020
6029
    @display_command
6021
6030
    def run(self, directory='.', sort=None, show_ids=False, revision=None):
6022
 
        from .tag import tag_sort_methods
 
6031
        from bzrlib.tag import tag_sort_methods
6023
6032
        branch, relpath = Branch.open_containing(directory)
6024
6033
 
6025
 
        tags = list(viewitems(branch.tags.get_tag_dict()))
 
6034
        tags = branch.tags.get_tag_dict().items()
6026
6035
        if not tags:
6027
6036
            return
6028
6037
 
6079
6088
 
6080
6089
 
6081
6090
class cmd_reconfigure(Command):
6082
 
    __doc__ = """Reconfigure the type of a brz directory.
 
6091
    __doc__ = """Reconfigure the type of a bzr directory.
6083
6092
 
6084
6093
    A target configuration must be specified.
6085
6094
 
6125
6134
            with_no_trees='Reconfigure repository to not create '
6126
6135
                'working trees on branches by default.'
6127
6136
            ),
6128
 
        Option('bind-to', help='Branch to bind checkout to.', type=text_type),
 
6137
        Option('bind-to', help='Branch to bind checkout to.', type=str),
6129
6138
        Option('force',
6130
6139
            help='Perform reconfiguration even if local changes'
6131
6140
            ' will be lost.'),
6132
6141
        Option('stacked-on',
6133
6142
            help='Reconfigure a branch to be stacked on another branch.',
6134
 
            type=text_type,
 
6143
            type=unicode,
6135
6144
            ),
6136
6145
        Option('unstacked',
6137
6146
            help='Reconfigure a branch to be unstacked.  This '
6230
6239
 
6231
6240
    def run(self, to_location=None, force=False, create_branch=False,
6232
6241
            revision=None, directory=u'.', store=False):
6233
 
        from . import switch
 
6242
        from bzrlib import switch
6234
6243
        tree_location = directory
6235
6244
        revision = _get_one_revision('switch', revision)
6236
6245
        possible_transports = []
6254
6263
                    gettext('cannot create branch without source branch'))
6255
6264
            to_location = lookup_new_sibling_branch(control_dir, to_location,
6256
6265
                 possible_transports=possible_transports)
6257
 
            to_branch = branch.controldir.sprout(to_location,
 
6266
            to_branch = branch.bzrdir.sprout(to_location,
6258
6267
                 possible_transports=possible_transports,
6259
6268
                 source_branch=branch).open_branch()
6260
6269
        else:
6266
6275
                    possible_transports=possible_transports)
6267
6276
        if revision is not None:
6268
6277
            revision = revision.as_revision_id(to_branch)
6269
 
        try:
6270
 
            switch.switch(control_dir, to_branch, force, revision_id=revision,
6271
 
                          store_uncommitted=store)
6272
 
        except controldir.BranchReferenceLoop:
6273
 
            raise errors.BzrCommandError(
6274
 
                    gettext('switching would create a branch reference loop. '
6275
 
                            'Use the "bzr up" command to switch to a '
6276
 
                            'different revision.'))
 
6278
        switch.switch(control_dir, to_branch, force, revision_id=revision,
 
6279
                      store_uncommitted=store)
6277
6280
        if had_explicit_nick:
6278
6281
            branch = control_dir.open_branch() #get the new branch!
6279
6282
            branch.nick = to_branch.nick
6305
6308
    :Examples:
6306
6309
      To define the current view::
6307
6310
 
6308
 
        brz view file1 dir1 ...
 
6311
        bzr view file1 dir1 ...
6309
6312
 
6310
6313
      To list the current view::
6311
6314
 
6312
 
        brz view
 
6315
        bzr view
6313
6316
 
6314
6317
      To delete the current view::
6315
6318
 
6316
 
        brz view --delete
 
6319
        bzr view --delete
6317
6320
 
6318
6321
      To disable the current view without deleting it::
6319
6322
 
6320
 
        brz view --switch off
 
6323
        bzr view --switch off
6321
6324
 
6322
6325
      To define a named view and switch to it::
6323
6326
 
6324
 
        brz view --name view-name file1 dir1 ...
 
6327
        bzr view --name view-name file1 dir1 ...
6325
6328
 
6326
6329
      To list a named view::
6327
6330
 
6328
 
        brz view --name view-name
 
6331
        bzr view --name view-name
6329
6332
 
6330
6333
      To delete a named view::
6331
6334
 
6332
 
        brz view --name view-name --delete
 
6335
        bzr view --name view-name --delete
6333
6336
 
6334
6337
      To switch to a named view::
6335
6338
 
6336
 
        brz view --switch view-name
 
6339
        bzr view --switch view-name
6337
6340
 
6338
6341
      To list all views defined::
6339
6342
 
6340
 
        brz view --all
 
6343
        bzr view --all
6341
6344
 
6342
6345
      To delete all views::
6343
6346
 
6344
 
        brz view --delete --all
 
6347
        bzr view --delete --all
6345
6348
    """
6346
6349
 
6347
6350
    _see_also = []
6355
6358
            ),
6356
6359
        Option('name',
6357
6360
            help='Name of the view to define, list or delete.',
6358
 
            type=text_type,
 
6361
            type=unicode,
6359
6362
            ),
6360
6363
        Option('switch',
6361
6364
            help='Name of the view to switch to.',
6362
 
            type=text_type,
 
6365
            type=unicode,
6363
6366
            ),
6364
6367
        ]
6365
6368
 
6467
6470
 
6468
6471
      Remove the branch at repo/trunk::
6469
6472
 
6470
 
        brz remove-branch repo/trunk
 
6473
        bzr remove-branch repo/trunk
6471
6474
 
6472
6475
    """
6473
6476
 
6480
6483
 
6481
6484
    def run(self, directory=None, location=None, force=False):
6482
6485
        br = open_nearby_branch(near=directory, location=location)
6483
 
        if not force and br.controldir.has_workingtree():
 
6486
        if not force and br.bzrdir.has_workingtree():
6484
6487
            try:
6485
 
                active_branch = br.controldir.open_branch(name="")
 
6488
                active_branch = br.bzrdir.open_branch(name="")
6486
6489
            except errors.NotBranchError:
6487
6490
                active_branch = None
6488
6491
            if (active_branch is not None and
6489
6492
                br.control_url == active_branch.control_url):
6490
6493
                raise errors.BzrCommandError(
6491
6494
                    gettext("Branch is active. Use --force to remove it."))
6492
 
        br.controldir.destroy_branch(br.name)
 
6495
        br.bzrdir.destroy_branch(br.name)
6493
6496
 
6494
6497
 
6495
6498
class cmd_shelve(Command):
6537
6540
        Option('all', help='Shelve all changes.'),
6538
6541
        'message',
6539
6542
        RegistryOption('writer', 'Method to use for writing diffs.',
6540
 
                       breezy.option.diff_writer_registry,
 
6543
                       bzrlib.option.diff_writer_registry,
6541
6544
                       value_switches=True, enum_switch=False),
6542
6545
 
6543
6546
        Option('list', help='List shelved changes.'),
6550
6553
            writer=None, list=False, destroy=False, directory=None):
6551
6554
        if list:
6552
6555
            return self.run_for_list(directory=directory)
6553
 
        from .shelf_ui import Shelver
 
6556
        from bzrlib.shelf_ui import Shelver
6554
6557
        if writer is None:
6555
 
            writer = breezy.option.diff_writer_registry.get()
 
6558
            writer = bzrlib.option.diff_writer_registry.get()
6556
6559
        try:
6557
 
            shelver = Shelver.from_args(writer(self.outf), revision, all,
 
6560
            shelver = Shelver.from_args(writer(sys.stdout), revision, all,
6558
6561
                file_list, message, destroy=destroy, directory=directory)
6559
6562
            try:
6560
6563
                shelver.run()
6606
6609
    _see_also = ['shelve']
6607
6610
 
6608
6611
    def run(self, shelf_id=None, action='apply', directory=u'.'):
6609
 
        from .shelf_ui import Unshelver
 
6612
        from bzrlib.shelf_ui import Unshelver
6610
6613
        unshelver = Unshelver.from_args(shelf_id, action, directory=directory)
6611
6614
        try:
6612
6615
            unshelver.run()
6620
6623
    By default, only unknown files, not ignored files, are deleted.  Versioned
6621
6624
    files are never deleted.
6622
6625
 
6623
 
    Another class is 'detritus', which includes files emitted by brz during
 
6626
    Another class is 'detritus', which includes files emitted by bzr during
6624
6627
    normal operations and selftests.  (The value of these files decreases with
6625
6628
    time.)
6626
6629
 
6634
6637
                     Option('detritus', help='Delete conflict files, merge and revert'
6635
6638
                            ' backups, and failed selftest dirs.'),
6636
6639
                     Option('unknown',
6637
 
                            help='Delete files unknown to brz (default).'),
 
6640
                            help='Delete files unknown to bzr (default).'),
6638
6641
                     Option('dry-run', help='Show files to delete instead of'
6639
6642
                            ' deleting them.'),
6640
6643
                     Option('force', help='Do not prompt before deleting.')]
6641
6644
    def run(self, unknown=False, ignored=False, detritus=False, dry_run=False,
6642
6645
            force=False, directory=u'.'):
6643
 
        from .clean_tree import clean_tree
 
6646
        from bzrlib.clean_tree import clean_tree
6644
6647
        if not (unknown or ignored or detritus):
6645
6648
            unknown = True
6646
6649
        if dry_run:
6672
6675
        if tree is None:
6673
6676
            tree = branch.basis_tree()
6674
6677
        if path is None:
6675
 
            info = viewitems(branch._get_all_reference_info())
 
6678
            info = branch._get_all_reference_info().iteritems()
6676
6679
            self._display_reference_info(tree, branch, info)
6677
6680
        else:
6678
 
            if not tree.is_versioned(path):
 
6681
            file_id = tree.path2id(path)
 
6682
            if file_id is None:
6679
6683
                raise errors.NotVersionedError(path)
6680
6684
            if location is None:
6681
 
                info = [(path, branch.get_reference_info(path))]
 
6685
                info = [(file_id, branch.get_reference_info(file_id))]
6682
6686
                self._display_reference_info(tree, branch, info)
6683
6687
            else:
6684
 
                branch.set_reference_info(
6685
 
                    path, location, file_id=tree.path2id(path))
 
6688
                branch.set_reference_info(file_id, path, location)
6686
6689
 
6687
6690
    def _display_reference_info(self, tree, branch, info):
6688
6691
        ref_list = []
6689
 
        for path, (location, file_id) in info:
 
6692
        for file_id, (path, location) in info:
 
6693
            try:
 
6694
                path = tree.id2path(file_id)
 
6695
            except errors.NoSuchId:
 
6696
                pass
6690
6697
            ref_list.append((path, location))
6691
6698
        for path, location in sorted(ref_list):
6692
6699
            self.outf.write('%s %s\n' % (path, location))
6696
6703
    __doc__ = """Export command helps and error messages in po format."""
6697
6704
 
6698
6705
    hidden = True
6699
 
    takes_options = [Option('plugin',
 
6706
    takes_options = [Option('plugin', 
6700
6707
                            help='Export help text from named command '\
6701
6708
                                 '(defaults to all built in commands).',
6702
 
                            type=text_type),
 
6709
                            type=str),
6703
6710
                     Option('include-duplicates',
6704
6711
                            help='Output multiple copies of the same msgid '
6705
6712
                                 'string if it appears more than once.'),
6706
6713
                            ]
6707
6714
 
6708
6715
    def run(self, plugin=None, include_duplicates=False):
6709
 
        from .export_pot import export_pot
 
6716
        from bzrlib.export_pot import export_pot
6710
6717
        export_pot(self.outf, plugin, include_duplicates)
6711
6718
 
6712
6719
 
6713
 
class cmd_import(Command):
6714
 
    __doc__ = """Import sources from a directory, tarball or zip file
6715
 
 
6716
 
    This command will import a directory, tarball or zip file into a bzr
6717
 
    tree, replacing any versioned files already present.  If a directory is
6718
 
    specified, it is used as the target.  If the directory does not exist, or
6719
 
    is not versioned, it is created.
6720
 
 
6721
 
    Tarballs may be gzip or bzip2 compressed.  This is autodetected.
6722
 
 
6723
 
    If the tarball or zip has a single root directory, that directory is
6724
 
    stripped when extracting the tarball.  This is not done for directories.
6725
 
    """
6726
 
 
6727
 
    takes_args = ['source', 'tree?']
6728
 
 
6729
 
    def run(self, source, tree=None):
6730
 
        from .upstream_import import do_import
6731
 
        do_import(source, tree)
6732
 
 
6733
 
 
6734
 
class cmd_link_tree(Command):
6735
 
    __doc__ = """Hardlink matching files to another tree.
6736
 
 
6737
 
    Only files with identical content and execute bit will be linked.
6738
 
    """
6739
 
 
6740
 
    takes_args = ['location']
6741
 
 
6742
 
    def run(self, location):
6743
 
        from .transform import link_tree
6744
 
        target_tree = WorkingTree.open_containing(".")[0]
6745
 
        source_tree = WorkingTree.open(location)
6746
 
        target_tree.lock_write()
6747
 
        try:
6748
 
            source_tree.lock_read()
6749
 
            try:
6750
 
                link_tree(target_tree, source_tree)
6751
 
            finally:
6752
 
                source_tree.unlock()
6753
 
        finally:
6754
 
            target_tree.unlock()
6755
 
 
6756
 
 
6757
 
class cmd_fetch_ghosts(Command):
6758
 
    __doc__ = """Attempt to retrieve ghosts from another branch.
6759
 
 
6760
 
    If the other branch is not supplied, the last-pulled branch is used.
6761
 
    """
6762
 
 
6763
 
    hidden = True
6764
 
    aliases = ['fetch-missing']
6765
 
    takes_args = ['branch?']
6766
 
    takes_options = [Option('no-fix', help="Skip additional synchonization.")]
6767
 
 
6768
 
    def run(self, branch=None, no_fix=False):
6769
 
        from .fetch_ghosts import GhostFetcher
6770
 
        installed, failed = GhostFetcher.from_cmdline(branch).run()
6771
 
        if len(installed) > 0:
6772
 
            self.outf.write("Installed:\n")
6773
 
            for rev in installed:
6774
 
                self.outf.write(rev + "\n")
6775
 
        if len(failed) > 0:
6776
 
            self.outf.write("Still missing:\n")
6777
 
            for rev in failed:
6778
 
                self.outf.write(rev + "\n")
6779
 
        if not no_fix and len(installed) > 0:
6780
 
            cmd_reconcile().run(".")
6781
 
 
6782
 
 
6783
6720
def _register_lazy_builtins():
6784
6721
    # register lazy builtins from other modules; called at startup and should
6785
6722
    # be only called once.
6786
6723
    for (name, aliases, module_name) in [
6787
 
        ('cmd_bisect', [], 'breezy.bisect'),
6788
 
        ('cmd_bundle_info', [], 'breezy.bundle.commands'),
6789
 
        ('cmd_config', [], 'breezy.config'),
6790
 
        ('cmd_dump_btree', [], 'breezy.bzr.debug_commands'),
6791
 
        ('cmd_dpush', [], 'breezy.foreign'),
6792
 
        ('cmd_version_info', [], 'breezy.cmd_version_info'),
6793
 
        ('cmd_resolve', ['resolved'], 'breezy.conflicts'),
6794
 
        ('cmd_conflicts', [], 'breezy.conflicts'),
6795
 
        ('cmd_ping', [], 'breezy.bzr.smart.ping'),
6796
 
        ('cmd_sign_my_commits', [], 'breezy.commit_signature_commands'),
6797
 
        ('cmd_verify_signatures', [], 'breezy.commit_signature_commands'),
6798
 
        ('cmd_test_script', [], 'breezy.cmd_test_script'),
 
6724
        ('cmd_bundle_info', [], 'bzrlib.bundle.commands'),
 
6725
        ('cmd_config', [], 'bzrlib.config'),
 
6726
        ('cmd_dpush', [], 'bzrlib.foreign'),
 
6727
        ('cmd_version_info', [], 'bzrlib.cmd_version_info'),
 
6728
        ('cmd_resolve', ['resolved'], 'bzrlib.conflicts'),
 
6729
        ('cmd_conflicts', [], 'bzrlib.conflicts'),
 
6730
        ('cmd_ping', [], 'bzrlib.smart.ping'),
 
6731
        ('cmd_sign_my_commits', [], 'bzrlib.commit_signature_commands'),
 
6732
        ('cmd_verify_signatures', [], 'bzrlib.commit_signature_commands'),
 
6733
        ('cmd_test_script', [], 'bzrlib.cmd_test_script'),
6799
6734
        ]:
6800
6735
        builtin_command_registry.register_lazy(name, aliases, module_name)