~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

[merge] bzr.dev 1807

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
24
23
import sys
25
24
 
26
25
import bzrlib
27
 
import bzrlib.branch
28
 
from bzrlib.branch import Branch
29
 
import bzrlib.bzrdir as bzrdir
30
 
from bzrlib.bundle.read_bundle import BundleReader
31
 
from bzrlib.bundle.apply_bundle import merge_bundle
 
26
from bzrlib.branch import Branch, BranchReferenceFormat
 
27
from bzrlib import (bundle, branch, bzrdir, errors, osutils, ui, config,
 
28
    repository, log)
 
29
from bzrlib.bundle import read_bundle_from_url
 
30
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
32
31
from bzrlib.commands import Command, display_command
33
 
import bzrlib.errors as errors
34
32
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError, 
35
33
                           NotBranchError, DivergedBranches, NotConflicted,
36
34
                           NoSuchFile, NoWorkingTree, FileInWrongBranch,
37
35
                           NotVersionedError, NotABundle)
38
 
from bzrlib.log import show_one_log
39
36
from bzrlib.merge import Merge3Merger
40
37
from bzrlib.option import Option
41
 
import bzrlib.osutils
42
38
from bzrlib.progress import DummyProgress, ProgressPhase
43
39
from bzrlib.revision import common_ancestor
44
40
from bzrlib.revisionspec import RevisionSpec
45
 
import bzrlib.trace
46
 
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
 
41
from bzrlib.trace import mutter, note, log_error, warning, is_quiet, info
47
42
from bzrlib.transport.local import LocalTransport
48
 
import bzrlib.ui
49
43
import bzrlib.urlutils as urlutils
50
44
from bzrlib.workingtree import WorkingTree
51
45
 
94
88
        return bzrdir.BzrDirMetaFormat1()
95
89
    if typestring == "metaweave":
96
90
        format = bzrdir.BzrDirMetaFormat1()
97
 
        format.repository_format = bzrlib.repository.RepositoryFormat7()
 
91
        format.repository_format = repository.RepositoryFormat7()
98
92
        return format
99
93
    if typestring == "knit":
100
94
        format = bzrdir.BzrDirMetaFormat1()
101
 
        format.repository_format = bzrlib.repository.RepositoryFormatKnit1()
 
95
        format.repository_format = repository.RepositoryFormatKnit1()
102
96
        return format
103
97
    msg = "Unknown bzr format %s. Current formats are: default, knit,\n" \
104
98
          "metaweave and weave" % typestring
132
126
    modified
133
127
        Text has changed since the previous revision.
134
128
 
135
 
    unchanged
136
 
        Nothing about this file has changed since the previous revision.
137
 
        Only shown with --all.
138
 
 
139
129
    unknown
140
130
        Not versioned and not matching an ignore pattern.
141
131
 
154
144
    # TODO: --no-recurse, --recurse options
155
145
    
156
146
    takes_args = ['file*']
157
 
    takes_options = ['all', 'show-ids', 'revision']
 
147
    takes_options = ['show-ids', 'revision']
158
148
    aliases = ['st', 'stat']
159
149
 
160
150
    encoding_type = 'replace'
161
151
    
162
152
    @display_command
163
 
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
 
153
    def run(self, show_ids=False, file_list=None, revision=None):
164
154
        from bzrlib.status import show_tree_status
165
155
 
166
156
        tree, file_list = tree_files(file_list)
167
157
            
168
 
        show_tree_status(tree, show_unchanged=all, show_ids=show_ids,
 
158
        show_tree_status(tree, show_ids=show_ids,
169
159
                         specific_files=file_list, revision=revision,
170
160
                         to_file=self.outf)
171
161
 
419
409
 
420
410
    If there is no default location set, the first pull will set it.  After
421
411
    that, you can omit the location to use the default.  To change the
422
 
    default, use --remember.
 
412
    default, use --remember. The value will only be saved if the remote
 
413
    location can be accessed.
423
414
    """
424
415
 
425
416
    takes_options = ['remember', 'overwrite', 'revision', 'verbose']
434
425
        except NoWorkingTree:
435
426
            tree_to = None
436
427
            branch_to = Branch.open_containing(u'.')[0]
 
428
 
 
429
        reader = None
 
430
        if location is not None:
 
431
            try:
 
432
                reader = bundle.read_bundle_from_url(location)
 
433
            except NotABundle:
 
434
                pass # Continue on considering this url a Branch
 
435
 
437
436
        stored_loc = branch_to.get_parent()
438
437
        if location is None:
439
438
            if stored_loc is None:
444
443
                self.outf.write("Using saved location: %s\n" % display_url)
445
444
                location = stored_loc
446
445
 
447
 
        branch_from = Branch.open(location)
448
 
 
449
 
        if branch_to.get_parent() is None or remember:
450
 
            branch_to.set_parent(branch_from.base)
451
 
 
 
446
 
 
447
        if reader is not None:
 
448
            install_bundle(branch_to.repository, reader)
 
449
            branch_from = branch_to
 
450
        else:
 
451
            branch_from = Branch.open(location)
 
452
 
 
453
            if branch_to.get_parent() is None or remember:
 
454
                branch_to.set_parent(branch_from.base)
 
455
 
 
456
        rev_id = None
452
457
        if revision is None:
453
 
            rev_id = None
 
458
            if reader is not None:
 
459
                rev_id = reader.target
454
460
        elif len(revision) == 1:
455
461
            rev_id = revision[0].in_history(branch_from).rev_id
456
462
        else:
494
500
 
495
501
    If there is no default push location set, the first push will set it.
496
502
    After that, you can omit the location to use the default.  To change the
497
 
    default, use --remember.
 
503
    default, use --remember. The value will only be saved if the remote
 
504
    location can be accessed.
498
505
    """
499
506
 
500
507
    takes_options = ['remember', 'overwrite', 'verbose',
518
525
            else:
519
526
                display_url = urlutils.unescape_for_display(stored_loc,
520
527
                        self.outf.encoding)
521
 
                self.outf.write("Using saved location: %s" % display_url)
 
528
                self.outf.write("Using saved location: %s\n" % display_url)
522
529
                location = stored_loc
523
530
 
524
531
        transport = get_transport(location)
525
532
        location_url = transport.base
526
 
        if br_from.get_push_location() is None or remember:
527
 
            br_from.set_push_location(location_url)
528
533
 
529
534
        old_rh = []
530
535
        try:
531
 
            dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
 
536
            dir_to = bzrdir.BzrDir.open(location_url)
532
537
            br_to = dir_to.open_branch()
533
538
        except NotBranchError:
534
539
            # create a branch.
560
565
                revision_id=br_from.last_revision())
561
566
            br_to = dir_to.open_branch()
562
567
            count = len(br_to.revision_history())
 
568
            # We successfully created the target, remember it
 
569
            if br_from.get_push_location() is None or remember:
 
570
                br_from.set_push_location(br_to.base)
563
571
        else:
 
572
            # We were able to connect to the remote location, so remember it
 
573
            # we don't need to successfully push because of possible divergence.
 
574
            if br_from.get_push_location() is None or remember:
 
575
                br_from.set_push_location(br_to.base)
564
576
            old_rh = br_to.revision_history()
565
577
            try:
566
578
                try:
606
618
 
607
619
    def run(self, from_location, to_location=None, revision=None, basis=None):
608
620
        from bzrlib.transport import get_transport
609
 
        from bzrlib.osutils import rmtree
610
621
        if revision is None:
611
622
            revision = [None]
612
623
        elif len(revision) > 1:
642
653
            to_transport = get_transport(to_location)
643
654
            try:
644
655
                to_transport.mkdir('.')
645
 
            except bzrlib.errors.FileExists:
 
656
            except errors.FileExists:
646
657
                raise BzrCommandError('Target directory "%s" already'
647
658
                                      ' exists.' % to_location)
648
 
            except bzrlib.errors.NoSuchFile:
 
659
            except errors.NoSuchFile:
649
660
                raise BzrCommandError('Parent of "%s" does not exist.' %
650
661
                                      to_location)
651
662
            try:
653
664
                dir = br_from.bzrdir.sprout(to_transport.base,
654
665
                        revision_id, basis_dir)
655
666
                branch = dir.open_branch()
656
 
            except bzrlib.errors.NoSuchRevision:
 
667
            except errors.NoSuchRevision:
657
668
                to_transport.delete_tree('.')
658
669
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
659
670
                raise BzrCommandError(msg)
660
 
            except bzrlib.errors.UnlistableBranch:
661
 
                rmtree(to_location)
 
671
            except errors.UnlistableBranch:
 
672
                osutils.rmtree(to_location)
662
673
                msg = "The branch %s cannot be used as a --basis" % (basis,)
663
674
                raise BzrCommandError(msg)
664
675
            if name:
707
718
            raise BzrCommandError(
708
719
                'bzr checkout --revision takes exactly 1 revision value')
709
720
        if branch_location is None:
710
 
            branch_location = bzrlib.osutils.getcwd()
 
721
            branch_location = osutils.getcwd()
711
722
            to_location = branch_location
712
723
        source = Branch.open(branch_location)
713
724
        if len(revision) == 1 and revision[0] is not None:
719
730
        # if the source and to_location are the same, 
720
731
        # and there is no working tree,
721
732
        # then reconstitute a branch
722
 
        if (bzrlib.osutils.abspath(to_location) == 
723
 
            bzrlib.osutils.abspath(branch_location)):
 
733
        if (osutils.abspath(to_location) == 
 
734
            osutils.abspath(branch_location)):
724
735
            try:
725
736
                source.bzrdir.open_workingtree()
726
737
            except errors.NoWorkingTree:
737
748
                                      to_location)
738
749
            else:
739
750
                raise
740
 
        old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
741
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
751
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
752
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
742
753
        try:
743
754
            if lightweight:
744
755
                checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
745
 
                bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
 
756
                branch.BranchReferenceFormat().initialize(checkout, source)
746
757
            else:
747
 
                checkout_branch =  bzrlib.bzrdir.BzrDir.create_branch_convenience(
 
758
                checkout_branch =  bzrdir.BzrDir.create_branch_convenience(
748
759
                    to_location, force_new_tree=False)
749
760
                checkout = checkout_branch.bzrdir
750
761
                checkout_branch.bind(source)
753
764
                    checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
754
765
            checkout.create_workingtree(revision_id)
755
766
        finally:
756
 
            bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)
 
767
            bzrdir.BzrDirFormat.set_default_format(old_format)
757
768
 
758
769
 
759
770
class cmd_renames(Command):
766
777
 
767
778
    @display_command
768
779
    def run(self, dir=u'.'):
 
780
        from bzrlib.tree import find_renames
769
781
        tree = WorkingTree.open_containing(dir)[0]
770
782
        old_inv = tree.basis_tree().inventory
771
783
        new_inv = tree.read_working_inventory()
772
 
 
773
 
        renames = list(bzrlib.tree.find_renames(old_inv, new_inv))
 
784
        renames = list(find_renames(old_inv, new_inv))
774
785
        renames.sort()
775
786
        for old_name, new_name in renames:
776
787
            self.outf.write("%s => %s\n" % (old_name, new_name))
924
935
 
925
936
    def run(self, branch="."):
926
937
        from bzrlib.reconcile import reconcile
927
 
        dir = bzrlib.bzrdir.BzrDir.open(branch)
 
938
        dir = bzrdir.BzrDir.open(branch)
928
939
        reconcile(dir)
929
940
 
930
941
 
931
942
class cmd_revision_history(Command):
932
 
    """Display list of revision ids on this branch."""
 
943
    """Display the list of revision ids on a branch."""
 
944
    takes_args = ['location?']
 
945
 
933
946
    hidden = True
934
947
 
935
948
    @display_command
936
 
    def run(self):
937
 
        branch = WorkingTree.open_containing(u'.')[0].branch
938
 
        for patchid in branch.revision_history():
939
 
            self.outf.write(patchid)
 
949
    def run(self, location="."):
 
950
        branch = Branch.open_containing(location)[0]
 
951
        for revid in branch.revision_history():
 
952
            self.outf.write(revid)
940
953
            self.outf.write('\n')
941
954
 
942
955
 
943
956
class cmd_ancestry(Command):
944
957
    """List all revisions merged into this branch."""
 
958
    takes_args = ['location?']
 
959
 
945
960
    hidden = True
946
961
 
947
962
    @display_command
948
 
    def run(self):
949
 
        tree = WorkingTree.open_containing(u'.')[0]
950
 
        b = tree.branch
951
 
        # FIXME. should be tree.last_revision
952
 
        revision_ids = b.repository.get_ancestry(b.last_revision())
 
963
    def run(self, location="."):
 
964
        try:
 
965
            wt = WorkingTree.open_containing(location)[0]
 
966
        except errors.NoWorkingTree:
 
967
            b = Branch.open(location)
 
968
            last_revision = b.last_revision()
 
969
        else:
 
970
            b = wt.branch
 
971
            last_revision = wt.last_revision()
 
972
 
 
973
        revision_ids = b.repository.get_ancestry(last_revision)
953
974
        assert revision_ids[0] == None
954
975
        revision_ids.pop(0)
955
976
        for revision_id in revision_ids:
987
1008
                            type=get_format_type),
988
1009
                     ]
989
1010
    def run(self, location=None, format=None):
990
 
        from bzrlib.branch import Branch
991
1011
        if format is None:
992
1012
            format = get_format_type('default')
993
1013
        if location is None:
1192
1212
            if file_id in basis_inv:
1193
1213
                continue
1194
1214
            path = inv.id2path(file_id)
1195
 
            if not os.access(bzrlib.osutils.abspath(path), os.F_OK):
 
1215
            if not os.access(osutils.abspath(path), os.F_OK):
1196
1216
                continue
1197
1217
            self.outf.write(path + '\n')
1198
1218
 
1307
1327
            (rev2, rev1) = (rev1, rev2)
1308
1328
 
1309
1329
        if (log_format == None):
1310
 
            default = bzrlib.config.BranchConfig(b).log_format()
1311
 
            log_format = get_log_format(long=long, short=short, line=line, default=default)
 
1330
            default = b.get_config().log_format()
 
1331
            log_format = get_log_format(long=long, short=short, line=line, 
 
1332
                                        default=default)
1312
1333
        lf = log_formatter(log_format,
1313
1334
                           show_ids=show_ids,
1314
1335
                           to_file=self.outf,
1350
1371
        b = tree.branch
1351
1372
        inv = tree.read_working_inventory()
1352
1373
        file_id = inv.path2id(relpath)
1353
 
        for revno, revision_id, what in bzrlib.log.find_touching_revisions(b, file_id):
 
1374
        for revno, revision_id, what in log.find_touching_revisions(b, file_id):
1354
1375
            self.outf.write("%6d %s\n" % (revno, what))
1355
1376
 
1356
1377
 
1412
1433
    """List unknown files."""
1413
1434
    @display_command
1414
1435
    def run(self):
1415
 
        from bzrlib.osutils import quotefn
1416
1436
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
1417
 
            self.outf.write(quotefn(f) + '\n')
 
1437
            self.outf.write(osutils.quotefn(f) + '\n')
1418
1438
 
1419
1439
 
1420
1440
class cmd_ignore(Command):
1584
1604
    hidden = True    
1585
1605
    @display_command
1586
1606
    def run(self):
1587
 
        print bzrlib.osutils.local_time_offset()
 
1607
        print osutils.local_time_offset()
1588
1608
 
1589
1609
 
1590
1610
 
1668
1688
            message = codecs.open(file, 'rt', bzrlib.user_encoding).read()
1669
1689
 
1670
1690
        if message == "":
1671
 
                raise BzrCommandError("empty commit message specified")
 
1691
            raise BzrCommandError("empty commit message specified")
1672
1692
        
1673
1693
        if verbose:
1674
1694
            reporter = ReportCommitToLog()
1766
1786
    @display_command
1767
1787
    def run(self, email=False):
1768
1788
        try:
1769
 
            b = WorkingTree.open_containing(u'.')[0].branch
1770
 
            config = bzrlib.config.BranchConfig(b)
 
1789
            c = WorkingTree.open_containing(u'.')[0].branch.get_config()
1771
1790
        except NotBranchError:
1772
 
            config = bzrlib.config.GlobalConfig()
1773
 
        
 
1791
            c = config.GlobalConfig()
1774
1792
        if email:
1775
 
            print config.user_email()
 
1793
            print c.user_email()
1776
1794
        else:
1777
 
            print config.username()
 
1795
            print c.username()
1778
1796
 
1779
1797
 
1780
1798
class cmd_nick(Command):
1860
1878
        # we don't want progress meters from the tests to go to the
1861
1879
        # real output; and we don't want log messages cluttering up
1862
1880
        # the real logs.
1863
 
        save_ui = bzrlib.ui.ui_factory
1864
 
        print '%10s: %s' % ('bzr', bzrlib.osutils.realpath(sys.argv[0]))
 
1881
        save_ui = ui.ui_factory
 
1882
        print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
1865
1883
        print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
1866
1884
        print
1867
 
        bzrlib.trace.info('running tests...')
 
1885
        info('running tests...')
1868
1886
        try:
1869
 
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
 
1887
            ui.ui_factory = ui.SilentUIFactory()
1870
1888
            if testspecs_list is not None:
1871
1889
                pattern = '|'.join(testspecs_list)
1872
1890
            else:
1887
1905
                              test_suite_factory=test_suite_factory,
1888
1906
                              lsprof_timed=lsprof_timed)
1889
1907
            if result:
1890
 
                bzrlib.trace.info('tests passed')
 
1908
                info('tests passed')
1891
1909
            else:
1892
 
                bzrlib.trace.info('tests failed')
 
1910
                info('tests failed')
1893
1911
            return int(not result)
1894
1912
        finally:
1895
 
            bzrlib.ui.ui_factory = save_ui
 
1913
            ui.ui_factory = save_ui
1896
1914
 
1897
1915
 
1898
1916
def _get_bzr_branch():
1899
1917
    """If bzr is run from a branch, return Branch or None"""
1900
 
    import bzrlib.errors
1901
 
    from bzrlib.branch import Branch
1902
 
    from bzrlib.osutils import abspath
1903
1918
    from os.path import dirname
1904
1919
    
1905
1920
    try:
1906
 
        branch = Branch.open(dirname(abspath(dirname(__file__))))
 
1921
        branch = Branch.open(dirname(osutils.abspath(dirname(__file__))))
1907
1922
        return branch
1908
 
    except bzrlib.errors.BzrError:
 
1923
    except errors.BzrError:
1909
1924
        return None
1910
1925
    
1911
1926
 
1912
1927
def show_version():
 
1928
    import bzrlib
1913
1929
    print "bzr (bazaar-ng) %s" % bzrlib.__version__
1914
1930
    # is bzrlib itself in a branch?
1915
1931
    branch = _get_bzr_branch()
1981
1997
        base_rev_id = common_ancestor(last1, last2, source)
1982
1998
 
1983
1999
        print 'merge base is revision %s' % base_rev_id
1984
 
        
1985
 
        return
1986
 
 
1987
 
        if base_revno is None:
1988
 
            raise bzrlib.errors.UnrelatedBranches()
1989
 
 
1990
 
        print ' r%-6d in %s' % (base_revno, branch)
1991
 
 
1992
 
        other_revno = branch2.revision_id_to_revno(base_revid)
1993
 
        
1994
 
        print ' r%-6d in %s' % (other_revno, other)
1995
 
 
1996
2000
 
1997
2001
 
1998
2002
class cmd_merge(Command):
1999
2003
    """Perform a three-way merge.
2000
2004
    
2001
 
    The branch is the branch you will merge from.  By default, it will
2002
 
    merge the latest revision.  If you specify a revision, that
2003
 
    revision will be merged.  If you specify two revisions, the first
2004
 
    will be used as a BASE, and the second one as OTHER.  Revision
2005
 
    numbers are always relative to the specified branch.
 
2005
    The branch is the branch you will merge from.  By default, it will merge
 
2006
    the latest revision.  If you specify a revision, that revision will be
 
2007
    merged.  If you specify two revisions, the first will be used as a BASE,
 
2008
    and the second one as OTHER.  Revision numbers are always relative to the
 
2009
    specified branch.
2006
2010
 
2007
2011
    By default, bzr will try to merge in all new work from the other
2008
2012
    branch, automatically determining an appropriate base.  If this
2017
2021
 
2018
2022
    If there is no default branch set, the first merge will set it. After
2019
2023
    that, you can omit the branch to use the default.  To change the
2020
 
    default, use --remember.
 
2024
    default, use --remember. The value will only be saved if the remote
 
2025
    location can be accessed.
2021
2026
 
2022
2027
    Examples:
2023
2028
 
2052
2057
 
2053
2058
        tree = WorkingTree.open_containing(u'.')[0]
2054
2059
 
2055
 
        try:
2056
 
            if branch is not None:
2057
 
                reader = BundleReader(file(branch, 'rb'))
2058
 
            else:
2059
 
                reader = None
2060
 
        except IOError, e:
2061
 
            if e.errno not in (errno.ENOENT, errno.EISDIR):
2062
 
                raise
2063
 
            reader = None
2064
 
        except NotABundle:
2065
 
            reader = None
2066
 
        if reader is not None:
2067
 
            conflicts = merge_bundle(reader, tree, not force, merge_type,
2068
 
                                        reprocess, show_base)
2069
 
            if conflicts == 0:
2070
 
                return 0
2071
 
            else:
2072
 
                return 1
 
2060
        if branch is not None:
 
2061
            try:
 
2062
                reader = bundle.read_bundle_from_url(branch)
 
2063
            except NotABundle:
 
2064
                pass # Continue on considering this url a Branch
 
2065
            else:
 
2066
                conflicts = merge_bundle(reader, tree, not force, merge_type,
 
2067
                                            reprocess, show_base)
 
2068
                if conflicts == 0:
 
2069
                    return 0
 
2070
                else:
 
2071
                    return 1
2073
2072
 
2074
2073
        branch = self._get_remembered_parent(tree, branch, 'Merging from')
2075
2074
 
2100
2099
            interesting_files = [path]
2101
2100
        else:
2102
2101
            interesting_files = None
2103
 
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
2102
        pb = ui.ui_factory.nested_progress_bar()
2104
2103
        try:
2105
2104
            try:
2106
2105
                conflict_count = merge(other, base, check_clean=(not force),
2114
2113
                return 1
2115
2114
            else:
2116
2115
                return 0
2117
 
        except bzrlib.errors.AmbiguousBase, e:
 
2116
        except errors.AmbiguousBase, e:
2118
2117
            m = ("sorry, bzr can't determine the right merge base yet\n"
2119
2118
                 "candidates are:\n  "
2120
2119
                 + "\n  ".join(e.bases)
2253
2252
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
2254
2253
        else:
2255
2254
            rev_id = revision[0].in_history(tree.branch).rev_id
2256
 
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
2255
        pb = ui.ui_factory.nested_progress_bar()
2257
2256
        try:
2258
2257
            tree.revert(file_list, 
2259
2258
                        tree.branch.repository.revision_tree(rev_id),
2307
2306
    takes_args = ['from_branch', 'to_branch']
2308
2307
    def run(self, from_branch, to_branch):
2309
2308
        from bzrlib.fetch import Fetcher
2310
 
        from bzrlib.branch import Branch
2311
2309
        from_b = Branch.open(from_branch)
2312
2310
        to_b = Branch.open(to_branch)
2313
2311
        Fetcher(to_b, from_b)
2336
2334
            show_ids=False, verbose=False):
2337
2335
        from bzrlib.missing import find_unmerged, iter_log_data
2338
2336
        from bzrlib.log import log_formatter
2339
 
        local_branch = bzrlib.branch.Branch.open_containing(u".")[0]
 
2337
        local_branch = Branch.open_containing(u".")[0]
2340
2338
        parent = local_branch.get_parent()
2341
2339
        if other_branch is None:
2342
2340
            other_branch = parent
2343
2341
            if other_branch is None:
2344
2342
                raise BzrCommandError("No missing location known or specified.")
2345
2343
            print "Using last location: " + local_branch.get_parent()
2346
 
        remote_branch = bzrlib.branch.Branch.open(other_branch)
 
2344
        remote_branch = Branch.open(other_branch)
2347
2345
        if remote_branch.base == local_branch.base:
2348
2346
            remote_branch = local_branch
2349
2347
        local_branch.lock_read()
2352
2350
            try:
2353
2351
                local_extra, remote_extra = find_unmerged(local_branch, remote_branch)
2354
2352
                if (log_format == None):
2355
 
                    default = bzrlib.config.BranchConfig(local_branch).log_format()
2356
 
                    log_format = get_log_format(long=long, short=short, line=line, default=default)
 
2353
                    default = local_branch.get_config().log_format()
 
2354
                    log_format = get_log_format(long=long, short=short, 
 
2355
                                                line=line, default=default)
2357
2356
                lf = log_formatter(log_format, sys.stdout,
2358
2357
                                   show_ids=show_ids,
2359
2358
                                   show_timezone='original')
2417
2416
 
2418
2417
class cmd_testament(Command):
2419
2418
    """Show testament (signing-form) of a revision."""
2420
 
    takes_options = ['revision', 'long']
 
2419
    takes_options = ['revision', 'long', 
 
2420
                     Option('strict', help='Produce a strict-format'
 
2421
                            ' testament')]
2421
2422
    takes_args = ['branch?']
2422
2423
    @display_command
2423
 
    def run(self, branch=u'.', revision=None, long=False):
2424
 
        from bzrlib.testament import Testament
 
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
2425
2430
        b = WorkingTree.open_containing(branch)[0].branch
2426
2431
        b.lock_read()
2427
2432
        try:
2429
2434
                rev_id = b.last_revision()
2430
2435
            else:
2431
2436
                rev_id = revision[0].in_history(b).rev_id
2432
 
            t = Testament.from_revision(b.repository, rev_id)
 
2437
            t = testament_class.from_revision(b.repository, rev_id)
2433
2438
            if long:
2434
2439
                sys.stdout.writelines(t.as_text_lines())
2435
2440
            else:
2487
2492
    takes_options = ['revision']
2488
2493
    
2489
2494
    def run(self, revision_id_list=None, revision=None):
2490
 
        import bzrlib.config as config
2491
2495
        import bzrlib.gpg as gpg
2492
2496
        if revision_id_list is not None and revision is not None:
2493
2497
            raise BzrCommandError('You can only supply one of revision_id or --revision')
2494
2498
        if revision_id_list is None and revision is None:
2495
2499
            raise BzrCommandError('You must supply either --revision or a revision_id')
2496
2500
        b = WorkingTree.open_containing(u'.')[0].branch
2497
 
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
 
2501
        gpg_strategy = gpg.GPGStrategy(b.get_config())
2498
2502
        if revision_id_list is not None:
2499
2503
            for revision_id in revision_id_list:
2500
2504
                b.repository.sign_revision(revision_id, gpg_strategy)
2555
2559
            raise BzrCommandError('Local branch is not bound')
2556
2560
 
2557
2561
 
2558
 
class cmd_uncommit(bzrlib.commands.Command):
 
2562
class cmd_uncommit(Command):
2559
2563
    """Remove the last committed revision.
2560
2564
 
2561
2565
    --verbose will print out what is being removed.
2579
2583
    def run(self, location=None, 
2580
2584
            dry_run=False, verbose=False,
2581
2585
            revision=None, force=False):
2582
 
        from bzrlib.branch import Branch
2583
2586
        from bzrlib.log import log_formatter
2584
2587
        import sys
2585
2588
        from bzrlib.uncommit import uncommit