~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

 * The internal storage of history, and logical branch identity have now
   been split into Branch, and Repository. The common locking and file 
   management routines are now in bzrlib.lockablefiles. 
   (Aaron Bentley, Robert Collins, Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""builtin bzr commands"""
18
18
 
19
 
# DO NOT change this to cStringIO - it results in control files 
20
 
# written as UCS4
21
 
# FIXIT! (Only deal with byte streams OR unicode at any one layer.)
22
 
# RBC 20051018
23
19
 
24
 
from StringIO import StringIO
 
20
import os
25
21
import sys
26
 
import os
27
22
 
28
23
import bzrlib
29
24
from bzrlib import BZRDIR
148
143
            raise BzrCommandError('You must supply either --revision or a revision_id')
149
144
        b = WorkingTree.open_containing(u'.')[0].branch
150
145
        if revision_id is not None:
151
 
            sys.stdout.write(b.get_revision_xml(revision_id))
 
146
            sys.stdout.write(b.repository.get_revision_xml(revision_id))
152
147
        elif revision is not None:
153
148
            for rev in revision:
154
149
                if rev is None:
155
150
                    raise BzrCommandError('You cannot specify a NULL revision.')
156
151
                revno, rev_id = rev.in_history(b)
157
 
                sys.stdout.write(b.get_revision_xml(rev_id))
 
152
                sys.stdout.write(b.repository.get_revision_xml(rev_id))
158
153
    
159
154
 
160
155
class cmd_revno(Command):
298
293
            if len(revision) > 1:
299
294
                raise BzrCommandError('bzr inventory --revision takes'
300
295
                    ' exactly one revision identifier')
301
 
            inv = tree.branch.get_revision_inventory(
 
296
            inv = tree.branch.repository.get_revision_inventory(
302
297
                revision[0].in_history(tree.branch).rev_id)
303
298
 
304
299
        for path, entry in inv.entries():
548
543
    aliases = ['get', 'clone']
549
544
 
550
545
    def run(self, from_location, to_location=None, revision=None, basis=None):
551
 
        from bzrlib.clone import copy_branch
552
546
        import errno
553
547
        from shutil import rmtree
554
548
        if revision is None:
591
585
                else:
592
586
                    raise
593
587
            try:
594
 
                copy_branch(br_from, to_location, revision_id, basis_branch)
 
588
                br_from.clone(to_location, revision_id, basis_branch)
595
589
            except bzrlib.errors.NoSuchRevision:
596
590
                rmtree(to_location)
597
591
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
602
596
                raise BzrCommandError(msg)
603
597
            branch = Branch.open(to_location)
604
598
            if name:
605
 
                name = StringIO(name)
606
 
                branch.put_controlfile('branch-name', name)
 
599
                branch.control_files.put_utf8('branch-name', name)
 
600
 
607
601
            note('Branched %d revision(s).' % branch.revno())
608
602
        finally:
609
603
            br_from.unlock()
927
921
            if tree is None:
928
922
                b, fp = Branch.open_containing(filename)
929
923
                if fp != '':
930
 
                    inv = b.get_inventory(b.last_revision())
 
924
                    inv = b.repository.get_inventory(b.last_revision())
931
925
            if fp != '':
932
926
                file_id = inv.path2id(fp)
933
927
            else:
1036
1030
        elif relpath:
1037
1031
            relpath += '/'
1038
1032
        if revision is not None:
1039
 
            tree = tree.branch.revision_tree(
 
1033
            tree = tree.branch.repository.revision_tree(
1040
1034
                revision[0].in_history(tree.branch).rev_id)
1041
1035
        for fp, fc, kind, fid, entry in tree.list_files():
1042
1036
            if fp.startswith(relpath):
1194
1188
            if len(revision) != 1:
1195
1189
                raise BzrError('bzr export --revision takes exactly 1 argument')
1196
1190
            rev_id = revision[0].in_history(b).rev_id
1197
 
        t = b.revision_tree(rev_id)
 
1191
        t = b.repository.revision_tree(rev_id)
1198
1192
        try:
1199
1193
            export(t, dest, format, root)
1200
1194
        except errors.NoSuchExportFormat, e:
1651
1645
                raise BzrCommandError("Sorry, remerge only works after normal"
1652
1646
                                      + " merges.  Not cherrypicking or"
1653
1647
                                      + "multi-merges.")
 
1648
            repository = tree.branch.repository
1654
1649
            base_revision = common_ancestor(tree.branch.last_revision(), 
1655
 
                                            pending_merges[0], tree.branch)
1656
 
            base_tree = tree.branch.revision_tree(base_revision)
1657
 
            other_tree = tree.branch.revision_tree(pending_merges[0])
 
1650
                                            pending_merges[0], repository)
 
1651
            base_tree = repository.revision_tree(base_revision)
 
1652
            other_tree = repository.revision_tree(pending_merges[0])
1658
1653
            interesting_ids = None
1659
1654
            if file_list is not None:
1660
1655
                interesting_ids = set()
1718
1713
        else:
1719
1714
            tree, file_list = tree_files(file_list)
1720
1715
            rev_id = revision[0].in_history(tree.branch).rev_id
1721
 
        tree.revert(file_list, tree.branch.revision_tree(rev_id),
1722
 
                                not no_backup)
 
1716
        tree.revert(file_list, tree.branch.repository.revision_tree(rev_id),
 
1717
                    not no_backup)
1723
1718
 
1724
1719
 
1725
1720
class cmd_assert_fail(Command):
1770
1765
        from bzrlib.branch import Branch
1771
1766
        from_b = Branch.open(from_branch)
1772
1767
        to_b = Branch.open(to_branch)
1773
 
        from_b.lock_read()
1774
 
        try:
1775
 
            to_b.lock_write()
1776
 
            try:
1777
 
                Fetcher(to_b, from_b)
1778
 
            finally:
1779
 
                to_b.unlock()
1780
 
        finally:
1781
 
            from_b.unlock()
 
1768
        Fetcher(to_b, from_b)
1782
1769
 
1783
1770
 
1784
1771
class cmd_missing(Command):
1821
1808
            remote_extra.reverse()
1822
1809
        if local_extra and not theirs_only:
1823
1810
            print "You have %d extra revision(s):" % len(local_extra)
1824
 
            for data in iter_log_data(local_extra, local_branch, verbose):
 
1811
            for data in iter_log_data(local_extra, local_branch.repository,
 
1812
                                      verbose):
1825
1813
                lf.show(*data)
1826
1814
            printed_local = True
1827
1815
        else:
1830
1818
            if printed_local is True:
1831
1819
                print "\n\n"
1832
1820
            print "You are missing %d revision(s):" % len(remote_extra)
1833
 
            for data in iter_log_data(remote_extra, remote_branch, verbose):
 
1821
            for data in iter_log_data(remote_extra, remote_branch.repository, 
 
1822
                                      verbose):
1834
1823
                lf.show(*data)
1835
1824
        if not remote_extra and not local_extra:
1836
1825
            status_code = 0
1876
1865
                rev_id = b.last_revision()
1877
1866
            else:
1878
1867
                rev_id = revision[0].in_history(b).rev_id
1879
 
            t = Testament.from_revision(b, rev_id)
 
1868
            t = Testament.from_revision(b.repository, rev_id)
1880
1869
            if long:
1881
1870
                sys.stdout.writelines(t.as_text_lines())
1882
1871
            else:
1912
1901
        branch.lock_read()
1913
1902
        try:
1914
1903
            file_id = tree.inventory.path2id(relpath)
1915
 
            tree = branch.revision_tree(branch.last_revision())
 
1904
            tree = branch.repository.revision_tree(branch.last_revision())
1916
1905
            file_version = tree.inventory[file_id].revision
1917
1906
            annotate_file(branch, file_version, file_id, long, all, sys.stdout)
1918
1907
        finally:
1937
1926
        b = WorkingTree.open_containing(u'.')[0].branch
1938
1927
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1939
1928
        if revision_id is not None:
1940
 
            b.sign_revision(revision_id, gpg_strategy)
 
1929
            b.repository.sign_revision(revision_id, gpg_strategy)
1941
1930
        elif revision is not None:
1942
1931
            if len(revision) == 1:
1943
1932
                revno, rev_id = revision[0].in_history(b)
1944
 
                b.sign_revision(rev_id, gpg_strategy)
 
1933
                b.repository.sign_revision(rev_id, gpg_strategy)
1945
1934
            elif len(revision) == 2:
1946
1935
                # are they both on rh- if so we can walk between them
1947
1936
                # might be nice to have a range helper for arbitrary
1953
1942
                if from_revno is None or to_revno is None:
1954
1943
                    raise BzrCommandError('Cannot sign a range of non-revision-history revisions')
1955
1944
                for revno in range(from_revno, to_revno + 1):
1956
 
                    b.sign_revision(b.get_rev_id(revno), gpg_strategy)
 
1945
                    b.repository.sign_revision(b.get_rev_id(revno), 
 
1946
                                               gpg_strategy)
1957
1947
            else:
1958
1948
                raise BzrCommandError('Please supply either one revision, or a range.')
1959
1949
 
2006
1996
        for r in range(revno, b.revno()+1):
2007
1997
            rev_id = b.get_rev_id(r)
2008
1998
            lf = log_formatter('short', to_file=sys.stdout,show_timezone='original')
2009
 
            lf.show(r, b.get_revision(rev_id), None)
 
1999
            lf.show(r, b.repository.get_revision(rev_id), None)
2010
2000
 
2011
2001
        if dry_run:
2012
2002
            print 'Dry-run, pretending to remove the above revisions.'