~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Move doctest import to increase speed

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import codecs
21
21
import errno
22
22
import os
 
23
from shutil import rmtree
23
24
import sys
24
25
 
25
26
import bzrlib
26
 
from bzrlib.branch import Branch, BranchReferenceFormat
27
 
from bzrlib import (bundle, branch, bzrdir, errors, osutils, ui, config,
28
 
    repository, log)
 
27
import bzrlib.branch
 
28
from bzrlib.branch import Branch
 
29
import bzrlib.bzrdir as bzrdir
29
30
from bzrlib.bundle import read_bundle_from_url
 
31
from bzrlib.bundle.read_bundle import BundleReader
30
32
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
31
33
from bzrlib.commands import Command, display_command
 
34
import bzrlib.errors as errors
32
35
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError, 
33
36
                           NotBranchError, DivergedBranches, NotConflicted,
34
37
                           NoSuchFile, NoWorkingTree, FileInWrongBranch,
35
38
                           NotVersionedError, NotABundle)
 
39
from bzrlib.log import show_one_log
36
40
from bzrlib.merge import Merge3Merger
37
41
from bzrlib.option import Option
 
42
import bzrlib.osutils
38
43
from bzrlib.progress import DummyProgress, ProgressPhase
39
44
from bzrlib.revision import common_ancestor
40
45
from bzrlib.revisionspec import RevisionSpec
41
 
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
 
46
import bzrlib.trace
 
47
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
42
48
from bzrlib.transport.local import LocalTransport
 
49
import bzrlib.ui
43
50
import bzrlib.urlutils as urlutils
44
51
from bzrlib.workingtree import WorkingTree
45
52
 
88
95
        return bzrdir.BzrDirMetaFormat1()
89
96
    if typestring == "metaweave":
90
97
        format = bzrdir.BzrDirMetaFormat1()
91
 
        format.repository_format = repository.RepositoryFormat7()
 
98
        format.repository_format = bzrlib.repository.RepositoryFormat7()
92
99
        return format
93
100
    if typestring == "knit":
94
101
        format = bzrdir.BzrDirMetaFormat1()
95
 
        format.repository_format = repository.RepositoryFormatKnit1()
 
102
        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
96
103
        return format
97
104
    msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
98
105
          "metaweave and weave" % typestring
400
407
    from one into the other.  Once one branch has merged, the other should
401
408
    be able to pull it again.
402
409
 
 
410
    If branches have diverged, you can use 'bzr merge' to pull the text changes
 
411
    from one into the other.  Once one branch has merged, the other should
 
412
    be able to pull it again.
 
413
 
403
414
    If you want to forget your local changes and just update your branch to
404
415
    match the remote one, use pull --overwrite.
405
416
 
406
417
    If there is no default location set, the first pull will set it.  After
407
418
    that, you can omit the location to use the default.  To change the
408
 
    default, use --remember. The value will only be saved if the remote
409
 
    location can be accessed.
 
419
    default, use --remember.
410
420
    """
411
421
 
412
422
    takes_options = ['remember', 'overwrite', 'revision', 'verbose']
425
435
        reader = None
426
436
        if location is not None:
427
437
            try:
428
 
                reader = bundle.read_bundle_from_url(location)
 
438
                reader = read_bundle_from_url(location)
429
439
            except NotABundle:
430
440
                pass # Continue on considering this url a Branch
431
441
 
452
462
        rev_id = None
453
463
        if revision is None:
454
464
            if reader is not None:
455
 
                rev_id = reader.target
 
465
                rev_id = reader.info.target
456
466
        elif len(revision) == 1:
457
467
            rev_id = revision[0].in_history(branch_from).rev_id
458
468
        else:
496
506
 
497
507
    If there is no default push location set, the first push will set it.
498
508
    After that, you can omit the location to use the default.  To change the
499
 
    default, use --remember. The value will only be saved if the remote
500
 
    location can be accessed.
 
509
    default, use --remember.
501
510
    """
502
511
 
503
512
    takes_options = ['remember', 'overwrite', 'verbose',
521
530
            else:
522
531
                display_url = urlutils.unescape_for_display(stored_loc,
523
532
                        self.outf.encoding)
524
 
                self.outf.write("Using saved location: %s\n" % display_url)
 
533
                self.outf.write("Using saved location: %s" % display_url)
525
534
                location = stored_loc
526
535
 
527
536
        transport = get_transport(location)
528
537
        location_url = transport.base
 
538
        if br_from.get_push_location() is None or remember:
 
539
            br_from.set_push_location(location_url)
529
540
 
530
541
        old_rh = []
531
542
        try:
532
 
            dir_to = bzrdir.BzrDir.open(location_url)
 
543
            dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
533
544
            br_to = dir_to.open_branch()
534
545
        except NotBranchError:
535
546
            # create a branch.
561
572
                revision_id=br_from.last_revision())
562
573
            br_to = dir_to.open_branch()
563
574
            count = len(br_to.revision_history())
564
 
            # We successfully created the target, remember it
565
 
            if br_from.get_push_location() is None or remember:
566
 
                br_from.set_push_location(br_to.base)
567
575
        else:
568
 
            # We were able to connect to the remote location, so remember it
569
 
            # we don't need to successfully push because of possible divergence.
570
 
            if br_from.get_push_location() is None or remember:
571
 
                br_from.set_push_location(br_to.base)
572
576
            old_rh = br_to.revision_history()
573
577
            try:
574
578
                try:
614
618
 
615
619
    def run(self, from_location, to_location=None, revision=None, basis=None):
616
620
        from bzrlib.transport import get_transport
 
621
        from bzrlib.osutils import rmtree
617
622
        if revision is None:
618
623
            revision = [None]
619
624
        elif len(revision) > 1:
649
654
            to_transport = get_transport(to_location)
650
655
            try:
651
656
                to_transport.mkdir('.')
652
 
            except errors.FileExists:
 
657
            except bzrlib.errors.FileExists:
653
658
                raise BzrCommandError('Target directory "%s" already'
654
659
                                      ' exists.' % to_location)
655
 
            except errors.NoSuchFile:
 
660
            except bzrlib.errors.NoSuchFile:
656
661
                raise BzrCommandError('Parent of "%s" does not exist.' %
657
662
                                      to_location)
658
663
            try:
660
665
                dir = br_from.bzrdir.sprout(to_transport.base,
661
666
                        revision_id, basis_dir)
662
667
                branch = dir.open_branch()
663
 
            except errors.NoSuchRevision:
 
668
            except bzrlib.errors.NoSuchRevision:
664
669
                to_transport.delete_tree('.')
665
670
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
666
671
                raise BzrCommandError(msg)
667
 
            except errors.UnlistableBranch:
668
 
                osutils.rmtree(to_location)
 
672
            except bzrlib.errors.UnlistableBranch:
 
673
                rmtree(to_location)
669
674
                msg = "The branch %s cannot be used as a --basis" % (basis,)
670
675
                raise BzrCommandError(msg)
671
676
            if name:
705
710
                                 "such access, and also support local commits."
706
711
                            ),
707
712
                     ]
708
 
    aliases = ['co']
709
713
 
710
714
    def run(self, branch_location=None, to_location=None, revision=None, basis=None,
711
715
            lightweight=False):
715
719
            raise BzrCommandError(
716
720
                'bzr checkout --revision takes exactly 1 revision value')
717
721
        if branch_location is None:
718
 
            branch_location = osutils.getcwd()
 
722
            branch_location = bzrlib.osutils.getcwd()
719
723
            to_location = branch_location
720
724
        source = Branch.open(branch_location)
721
725
        if len(revision) == 1 and revision[0] is not None:
727
731
        # if the source and to_location are the same, 
728
732
        # and there is no working tree,
729
733
        # then reconstitute a branch
730
 
        if (osutils.abspath(to_location) == 
731
 
            osutils.abspath(branch_location)):
 
734
        if (bzrlib.osutils.abspath(to_location) == 
 
735
            bzrlib.osutils.abspath(branch_location)):
732
736
            try:
733
737
                source.bzrdir.open_workingtree()
734
738
            except errors.NoWorkingTree:
745
749
                                      to_location)
746
750
            else:
747
751
                raise
748
 
        old_format = bzrdir.BzrDirFormat.get_default_format()
749
 
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
752
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
 
753
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
750
754
        try:
751
755
            if lightweight:
752
756
                checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
753
 
                branch.BranchReferenceFormat().initialize(checkout, source)
 
757
                bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
754
758
            else:
755
 
                checkout_branch =  bzrdir.BzrDir.create_branch_convenience(
 
759
                checkout_branch =  bzrlib.bzrdir.BzrDir.create_branch_convenience(
756
760
                    to_location, force_new_tree=False)
757
761
                checkout = checkout_branch.bzrdir
758
762
                checkout_branch.bind(source)
761
765
                    checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
762
766
            checkout.create_workingtree(revision_id)
763
767
        finally:
764
 
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
768
            bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
765
769
 
766
770
 
767
771
class cmd_renames(Command):
774
778
 
775
779
    @display_command
776
780
    def run(self, dir=u'.'):
777
 
        from bzrlib.tree import find_renames
778
781
        tree = WorkingTree.open_containing(dir)[0]
779
782
        old_inv = tree.basis_tree().inventory
780
783
        new_inv = tree.read_working_inventory()
781
 
        renames = list(find_renames(old_inv, new_inv))
 
784
 
 
785
        renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
782
786
        renames.sort()
783
787
        for old_name, new_name in renames:
784
788
            self.outf.write("%s => %s\n" % (old_name, new_name))
932
936
 
933
937
    def run(self, branch="."):
934
938
        from bzrlib.reconcile import reconcile
935
 
        dir = bzrdir.BzrDir.open(branch)
 
939
        dir = bzrlib.bzrdir.BzrDir.open(branch)
936
940
        reconcile(dir)
937
941
 
938
942
 
939
943
class cmd_revision_history(Command):
940
 
    """Display the list of revision ids on a branch."""
941
 
    takes_args = ['location?']
942
 
 
 
944
    """Display list of revision ids on this branch."""
943
945
    hidden = True
944
946
 
945
947
    @display_command
946
 
    def run(self, location="."):
947
 
        branch = Branch.open_containing(location)[0]
948
 
        for revid in branch.revision_history():
949
 
            self.outf.write(revid)
 
948
    def run(self):
 
949
        branch = WorkingTree.open_containing(u'.')[0].branch
 
950
        for patchid in branch.revision_history():
 
951
            self.outf.write(patchid)
950
952
            self.outf.write('\n')
951
953
 
952
954
 
953
955
class cmd_ancestry(Command):
954
956
    """List all revisions merged into this branch."""
955
 
    takes_args = ['location?']
956
 
 
957
957
    hidden = True
958
958
 
959
959
    @display_command
960
 
    def run(self, location="."):
961
 
        try:
962
 
            wt = WorkingTree.open_containing(location)[0]
963
 
        except errors.NoWorkingTree:
964
 
            b = Branch.open(location)
965
 
            last_revision = b.last_revision()
966
 
        else:
967
 
            b = wt.branch
968
 
            last_revision = wt.last_revision()
969
 
 
970
 
        revision_ids = b.repository.get_ancestry(last_revision)
 
960
    def run(self):
 
961
        tree = WorkingTree.open_containing(u'.')[0]
 
962
        b = tree.branch
 
963
        # FIXME. should be tree.last_revision
 
964
        revision_ids = b.repository.get_ancestry(b.last_revision())
971
965
        assert revision_ids[0] == None
972
966
        revision_ids.pop(0)
973
967
        for revision_id in revision_ids:
1005
999
                            type=get_format_type),
1006
1000
                     ]
1007
1001
    def run(self, location=None, format=None):
 
1002
        from bzrlib.branch import Branch
1008
1003
        if format is None:
1009
1004
            format = get_format_type('default')
1010
1005
        if location is None:
1209
1204
            if file_id in basis_inv:
1210
1205
                continue
1211
1206
            path = inv.id2path(file_id)
1212
 
            if not os.access(osutils.abspath(path), os.F_OK):
 
1207
            if not os.access(bzrlib.osutils.abspath(path), os.F_OK):
1213
1208
                continue
1214
1209
            self.outf.write(path + '\n')
1215
1210
 
1324
1319
            (rev2, rev1) = (rev1, rev2)
1325
1320
 
1326
1321
        if (log_format == None):
1327
 
            default = b.get_config().log_format()
1328
 
            log_format = get_log_format(long=long, short=short, line=line, 
1329
 
                                        default=default)
 
1322
            default = bzrlib.config.BranchConfig(b).log_format()
 
1323
            log_format = get_log_format(long=long, short=short, line=line, default=default)
1330
1324
        lf = log_formatter(log_format,
1331
1325
                           show_ids=show_ids,
1332
1326
                           to_file=self.outf,
1368
1362
        b = tree.branch
1369
1363
        inv = tree.read_working_inventory()
1370
1364
        file_id = inv.path2id(relpath)
1371
 
        for revno, revision_id, what in log.find_touching_revisions(b, file_id):
 
1365
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
1372
1366
            self.outf.write("%6d %s\n" % (revno, what))
1373
1367
 
1374
1368
 
1430
1424
    """List unknown files."""
1431
1425
    @display_command
1432
1426
    def run(self):
 
1427
        from bzrlib.osutils import quotefn
1433
1428
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
1434
 
            self.outf.write(osutils.quotefn(f) + '\n')
 
1429
            self.outf.write(quotefn(f) + '\n')
1435
1430
 
1436
1431
 
1437
1432
class cmd_ignore(Command):
1601
1596
    hidden = True    
1602
1597
    @display_command
1603
1598
    def run(self):
1604
 
        print osutils.local_time_offset()
 
1599
        print bzrlib.osutils.local_time_offset()
1605
1600
 
1606
1601
 
1607
1602
 
1685
1680
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1686
1681
 
1687
1682
        if message == "":
1688
 
            raise BzrCommandError("empty commit message specified")
 
1683
                raise BzrCommandError("empty commit message specified")
1689
1684
        
1690
1685
        if verbose:
1691
1686
            reporter = ReportCommitToLog()
1699
1694
        except PointlessCommit:
1700
1695
            # FIXME: This should really happen before the file is read in;
1701
1696
            # perhaps prepare the commit; get the message; then actually commit
1702
 
            raise BzrCommandError("no changes to commit."
1703
 
                                  " use --unchanged to commit anyhow")
 
1697
            raise BzrCommandError("no changes to commit",
 
1698
                                  ["use --unchanged to commit anyhow"])
1704
1699
        except ConflictsInTree:
1705
1700
            raise BzrCommandError("Conflicts detected in working tree.  "
1706
1701
                'Use "bzr conflicts" to list, "bzr resolve FILE" to resolve.')
1783
1778
    @display_command
1784
1779
    def run(self, email=False):
1785
1780
        try:
1786
 
            c = WorkingTree.open_containing(u'.')[0].branch.get_config()
 
1781
            b = WorkingTree.open_containing(u'.')[0].branch
 
1782
            config = bzrlib.config.BranchConfig(b)
1787
1783
        except NotBranchError:
1788
 
            c = config.GlobalConfig()
 
1784
            config = bzrlib.config.GlobalConfig()
 
1785
        
1789
1786
        if email:
1790
 
            print c.user_email()
 
1787
            print config.user_email()
1791
1788
        else:
1792
 
            print c.username()
 
1789
            print config.username()
1793
1790
 
1794
1791
 
1795
1792
class cmd_nick(Command):
1875
1872
        # we don't want progress meters from the tests to go to the
1876
1873
        # real output; and we don't want log messages cluttering up
1877
1874
        # the real logs.
1878
 
        save_ui = ui.ui_factory
1879
 
        print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
 
1875
        save_ui = bzrlib.ui.ui_factory
 
1876
        print '%10s: %s' % ('bzr', bzrlib.osutils.realpath(sys.argv[0]))
1880
1877
        print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
1881
1878
        print
1882
 
        info('running tests...')
 
1879
        bzrlib.trace.info('running tests...')
1883
1880
        try:
1884
 
            ui.ui_factory = ui.SilentUIFactory()
 
1881
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1885
1882
            if testspecs_list is not None:
1886
1883
                pattern = '|'.join(testspecs_list)
1887
1884
            else:
1902
1899
                              test_suite_factory=test_suite_factory,
1903
1900
                              lsprof_timed=lsprof_timed)
1904
1901
            if result:
1905
 
                info('tests passed')
 
1902
                bzrlib.trace.info('tests passed')
1906
1903
            else:
1907
 
                info('tests failed')
 
1904
                bzrlib.trace.info('tests failed')
1908
1905
            return int(not result)
1909
1906
        finally:
1910
 
            ui.ui_factory = save_ui
 
1907
            bzrlib.ui.ui_factory = save_ui
1911
1908
 
1912
1909
 
1913
1910
def _get_bzr_branch():
1914
1911
    """If bzr is run from a branch, return Branch or None"""
 
1912
    import bzrlib.errors
 
1913
    from bzrlib.branch import Branch
 
1914
    from bzrlib.osutils import abspath
1915
1915
    from os.path import dirname
1916
1916
    
1917
1917
    try:
1918
 
        branch = Branch.open(dirname(osutils.abspath(dirname(__file__))))
 
1918
        branch = Branch.open(dirname(abspath(dirname(__file__))))
1919
1919
        return branch
1920
 
    except errors.BzrError:
 
1920
    except bzrlib.errors.BzrError:
1921
1921
        return None
1922
1922
    
1923
1923
 
1924
1924
def show_version():
1925
 
    import bzrlib
1926
1925
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
1927
1926
    # is bzrlib itself in a branch?
1928
1927
    branch = _get_bzr_branch()
1994
1993
        base_rev_id = common_ancestor(last1, last2, source)
1995
1994
 
1996
1995
        print 'merge base is revision %s' % base_rev_id
 
1996
        
 
1997
        return
 
1998
 
 
1999
        if base_revno is None:
 
2000
            raise bzrlib.errors.UnrelatedBranches()
 
2001
 
 
2002
        print ' r%-6d in %s' % (base_revno, branch)
 
2003
 
 
2004
        other_revno = branch2.revision_id_to_revno(base_revid)
 
2005
        
 
2006
        print ' r%-6d in %s' % (other_revno, other)
 
2007
 
1997
2008
 
1998
2009
 
1999
2010
class cmd_merge(Command):
2000
2011
    """Perform a three-way merge.
2001
2012
    
2002
 
    The branch is the branch you will merge from.  By default, it will merge
2003
 
    the latest revision.  If you specify a revision, that revision will be
2004
 
    merged.  If you specify two revisions, the first will be used as a BASE,
2005
 
    and the second one as OTHER.  Revision numbers are always relative to the
2006
 
    specified branch.
 
2013
    The branch is the branch you will merge from.  By default, it will
 
2014
    merge the latest revision.  If you specify a revision, that
 
2015
    revision will be merged.  If you specify two revisions, the first
 
2016
    will be used as a BASE, and the second one as OTHER.  Revision
 
2017
    numbers are always relative to the specified branch.
2007
2018
 
2008
2019
    By default, bzr will try to merge in all new work from the other
2009
2020
    branch, automatically determining an appropriate base.  If this
2018
2029
 
2019
2030
    If there is no default branch set, the first merge will set it. After
2020
2031
    that, you can omit the branch to use the default.  To change the
2021
 
    default, use --remember. The value will only be saved if the remote
2022
 
    location can be accessed.
 
2032
    default, use --remember.
2023
2033
 
2024
2034
    Examples:
2025
2035
 
2056
2066
 
2057
2067
        if branch is not None:
2058
2068
            try:
2059
 
                reader = bundle.read_bundle_from_url(branch)
 
2069
                reader = read_bundle_from_url(branch)
2060
2070
            except NotABundle:
2061
2071
                pass # Continue on considering this url a Branch
2062
2072
            else:
2096
2106
            interesting_files = [path]
2097
2107
        else:
2098
2108
            interesting_files = None
2099
 
        pb = ui.ui_factory.nested_progress_bar()
 
2109
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
2100
2110
        try:
2101
2111
            try:
2102
2112
                conflict_count = merge(other, base, check_clean=(not force),
2110
2120
                return 1
2111
2121
            else:
2112
2122
                return 0
2113
 
        except errors.AmbiguousBase, e:
 
2123
        except bzrlib.errors.AmbiguousBase, e:
2114
2124
            m = ("sorry, bzr can't determine the right merge base yet\n"
2115
2125
                 "candidates are:\n  "
2116
2126
                 + "\n  ".join(e.bases)
2178
2188
            pending_merges = tree.pending_merges() 
2179
2189
            if len(pending_merges) != 1:
2180
2190
                raise BzrCommandError("Sorry, remerge only works after normal"
2181
 
                                      " merges.  Not cherrypicking or"
2182
 
                                      " multi-merges.")
 
2191
                                      + " merges.  Not cherrypicking or"
 
2192
                                      + "multi-merges.")
2183
2193
            repository = tree.branch.repository
2184
2194
            base_revision = common_ancestor(tree.branch.last_revision(), 
2185
2195
                                            pending_merges[0], repository)
2249
2259
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2250
2260
        else:
2251
2261
            rev_id = revision[0].in_history(tree.branch).rev_id
2252
 
        pb = ui.ui_factory.nested_progress_bar()
 
2262
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
2253
2263
        try:
2254
2264
            tree.revert(file_list, 
2255
2265
                        tree.branch.repository.revision_tree(rev_id),
2303
2313
    takes_args = ['from_branch', 'to_branch']
2304
2314
    def run(self, from_branch, to_branch):
2305
2315
        from bzrlib.fetch import Fetcher
 
2316
        from bzrlib.branch import Branch
2306
2317
        from_b = Branch.open(from_branch)
2307
2318
        to_b = Branch.open(to_branch)
2308
2319
        Fetcher(to_b, from_b)
2325
2336
                     'show-ids',
2326
2337
                     'verbose'
2327
2338
                     ]
2328
 
    encoding_type = 'replace'
2329
2339
 
2330
 
    @display_command
2331
2340
    def run(self, other_branch=None, reverse=False, mine_only=False,
2332
2341
            theirs_only=False, log_format=None, long=False, short=False, line=False, 
2333
2342
            show_ids=False, verbose=False):
2334
2343
        from bzrlib.missing import find_unmerged, iter_log_data
2335
2344
        from bzrlib.log import log_formatter
2336
 
        local_branch = Branch.open_containing(u".")[0]
 
2345
        local_branch = bzrlib.branch.Branch.open_containing(u".")[0]
2337
2346
        parent = local_branch.get_parent()
2338
2347
        if other_branch is None:
2339
2348
            other_branch = parent
2340
2349
            if other_branch is None:
2341
2350
                raise BzrCommandError("No missing location known or specified.")
2342
2351
            print "Using last location: " + local_branch.get_parent()
2343
 
        remote_branch = Branch.open(other_branch)
 
2352
        remote_branch = bzrlib.branch.Branch.open(other_branch)
2344
2353
        if remote_branch.base == local_branch.base:
2345
2354
            remote_branch = local_branch
2346
2355
        local_branch.lock_read()
2349
2358
            try:
2350
2359
                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2351
2360
                if (log_format == None):
2352
 
                    default = local_branch.get_config().log_format()
2353
 
                    log_format = get_log_format(long=long, short=short, 
2354
 
                                                line=line, default=default)
2355
 
                lf = log_formatter(log_format,
2356
 
                                   to_file=self.outf,
 
2361
                    default = bzrlib.config.BranchConfig(local_branch).log_format()
 
2362
                    log_format = get_log_format(long=long, short=short, line=line, default=default)
 
2363
                lf = log_formatter(log_format, sys.stdout,
2357
2364
                                   show_ids=show_ids,
2358
2365
                                   show_timezone='original')
2359
2366
                if reverse is False:
2416
2423
 
2417
2424
class cmd_testament(Command):
2418
2425
    """Show testament (signing-form) of a revision."""
2419
 
    takes_options = ['revision', 'long', 
2420
 
                     Option('strict', help='Produce a strict-format'
2421
 
                            ' testament')]
 
2426
    takes_options = ['revision', 'long']
2422
2427
    takes_args = ['branch?']
2423
2428
    @display_command
2424
 
    def run(self, branch=u'.', revision=None, long=False, strict=False):
2425
 
        from bzrlib.testament import Testament, StrictTestament
2426
 
        if strict is True:
2427
 
            testament_class = StrictTestament
2428
 
        else:
2429
 
            testament_class = Testament
 
2429
    def run(self, branch=u'.', revision=None, long=False):
 
2430
        from bzrlib.testament import Testament
2430
2431
        b = WorkingTree.open_containing(branch)[0].branch
2431
2432
        b.lock_read()
2432
2433
        try:
2434
2435
                rev_id = b.last_revision()
2435
2436
            else:
2436
2437
                rev_id = revision[0].in_history(b).rev_id
2437
 
            t = testament_class.from_revision(b.repository, rev_id)
 
2438
            t = Testament.from_revision(b.repository, rev_id)
2438
2439
            if long:
2439
2440
                sys.stdout.writelines(t.as_text_lines())
2440
2441
            else:
2455
2456
    # TODO: annotate directories; showing when each file was last changed
2456
2457
    # TODO: if the working copy is modified, show annotations on that 
2457
2458
    #       with new uncommitted lines marked
2458
 
    aliases = ['ann', 'blame', 'praise']
 
2459
    aliases = ['blame', 'praise']
2459
2460
    takes_args = ['filename']
2460
2461
    takes_options = [Option('all', help='show annotations on all lines'),
2461
2462
                     Option('long', help='show date in annotations'),
2492
2493
    takes_options = ['revision']
2493
2494
    
2494
2495
    def run(self, revision_id_list=None, revision=None):
 
2496
        import bzrlib.config as config
2495
2497
        import bzrlib.gpg as gpg
2496
2498
        if revision_id_list is not None and revision is not None:
2497
2499
            raise BzrCommandError('You can only supply one of revision_id or --revision')
2498
2500
        if revision_id_list is None and revision is None:
2499
2501
            raise BzrCommandError('You must supply either --revision or a revision_id')
2500
2502
        b = WorkingTree.open_containing(u'.')[0].branch
2501
 
        gpg_strategy = gpg.GPGStrategy(b.get_config())
 
2503
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
2502
2504
        if revision_id_list is not None:
2503
2505
            for revision_id in revision_id_list:
2504
2506
                b.repository.sign_revision(revision_id, gpg_strategy)
2559
2561
            raise BzrCommandError('Local branch is not bound')
2560
2562
 
2561
2563
 
2562
 
class cmd_uncommit(Command):
 
2564
class cmd_uncommit(bzrlib.commands.Command):
2563
2565
    """Remove the last committed revision.
2564
2566
 
2565
2567
    --verbose will print out what is being removed.
2583
2585
    def run(self, location=None, 
2584
2586
            dry_run=False, verbose=False,
2585
2587
            revision=None, force=False):
 
2588
        from bzrlib.branch import Branch
2586
2589
        from bzrlib.log import log_formatter
2587
2590
        import sys
2588
2591
        from bzrlib.uncommit import uncommit