/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/branch.py

Merge up bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
from bzrlib.decorators import needs_read_lock, needs_write_lock
43
43
from bzrlib.hooks import Hooks
44
 
from bzrlib.symbol_versioning import (deprecated_method,
45
 
                                      zero_sixteen,
46
 
                                      )
47
44
from bzrlib.trace import mutter, mutter_callsite, note, is_quiet
48
45
 
49
46
 
317
314
        The delta is relative to its mainline predecessor, or the
318
315
        empty tree for revision 1.
319
316
        """
320
 
        assert isinstance(revno, int)
321
317
        rh = self.revision_history()
322
318
        if not (1 <= revno <= len(rh)):
323
319
            raise errors.InvalidRevisionNumber(revno)
324
320
        return self.repository.get_revision_delta(rh[revno-1])
325
321
 
326
 
    @deprecated_method(zero_sixteen)
327
 
    def get_root_id(self):
328
 
        """Return the id of this branches root
329
 
 
330
 
        Deprecated: branches don't have root ids-- trees do.
331
 
        Use basis_tree().get_root_id() instead.
332
 
        """
333
 
        raise NotImplementedError(self.get_root_id)
334
 
 
335
322
    def print_file(self, file, revision_id):
336
323
        """Print `file` to stdout."""
337
324
        raise NotImplementedError(self.print_file)
451
438
        if stop_revision is None:
452
439
            stop_revision = other_len
453
440
        else:
454
 
            assert isinstance(stop_revision, int)
455
441
            if stop_revision > other_len:
456
442
                raise errors.NoSuchRevision(self, stop_revision)
457
443
        return other_history[self_len:stop_revision]
704
690
        :return: A BranchCheckResult.
705
691
        """
706
692
        mainline_parent_id = None
707
 
        for revision_id in self.revision_history():
 
693
        last_revno, last_revision_id = self.last_revision_info()
 
694
        real_rev_history = list(self.repository.iter_reverse_revision_history(
 
695
                                last_revision_id))
 
696
        real_rev_history.reverse()
 
697
        if len(real_rev_history) != last_revno:
 
698
            raise errors.BzrCheckError('revno does not match len(mainline)'
 
699
                ' %s != %s' % (last_revno, len(real_rev_history)))
 
700
        # TODO: We should probably also check that real_rev_history actually
 
701
        #       matches self.revision_history()
 
702
        for revision_id in real_rev_history:
708
703
            try:
709
704
                revision = self.repository.get_revision(revision_id)
710
705
            except errors.NoSuchRevision, e:
783
778
            basis_tree.unlock()
784
779
        return tree
785
780
 
 
781
    @needs_write_lock
 
782
    def reconcile(self, thorough=True):
 
783
        """Make sure the data stored in this branch is consistent."""
 
784
        from bzrlib.reconcile import BranchReconciler
 
785
        reconciler = BranchReconciler(self, thorough=thorough)
 
786
        reconciler.reconcile()
 
787
        return reconciler
 
788
 
786
789
    def reference_parent(self, file_id, path):
787
790
        """Return the parent branch for a tree-reference file_id
788
791
        :param file_id: The file_id of the tree reference
939
942
 
940
943
    @classmethod
941
944
    def unregister_format(klass, format):
942
 
        assert klass._formats[format.get_format_string()] is format
943
945
        del klass._formats[format.get_format_string()]
944
946
 
945
947
    def __str__(self):
1149
1151
        """
1150
1152
        if not _found:
1151
1153
            format = BranchFormat.find_format(a_bzrdir)
1152
 
            assert format.__class__ == self.__class__
 
1154
            if format.__class__ != self.__class__:
 
1155
                raise AssertionError("wrong format %r found for %r" %
 
1156
                    (format, self))
1153
1157
        try:
1154
1158
            transport = a_bzrdir.get_branch_transport(None)
1155
1159
            control_files = lockable_files.LockableFiles(transport, 'lock',
1197
1201
        """
1198
1202
        if not _found:
1199
1203
            format = BranchFormat.find_format(a_bzrdir)
1200
 
            assert format.__class__ == self.__class__
 
1204
            if format.__class__ != self.__class__:
 
1205
                raise AssertionError("wrong format %r found for %r" %
 
1206
                    (format, self))
1201
1207
        transport = a_bzrdir.get_branch_transport(None)
1202
1208
        control_files = lockable_files.LockableFiles(transport, 'lock',
1203
1209
                                                     lockdir.LockDir)
1277
1283
        """
1278
1284
        if not _found:
1279
1285
            format = BranchFormat.find_format(a_bzrdir)
1280
 
            assert format.__class__ == self.__class__
 
1286
            if format.__class__ != self.__class__:
 
1287
                raise AssertionError("wrong format %r found for %r" %
 
1288
                    (format, self))
1281
1289
        if location is None:
1282
1290
            location = self.get_reference(a_bzrdir)
1283
1291
        real_bzrdir = bzrdir.BzrDir.open(
1348
1356
        """See Branch.abspath."""
1349
1357
        return self.control_files._transport.abspath(name)
1350
1358
 
1351
 
 
1352
 
    @deprecated_method(zero_sixteen)
1353
 
    @needs_read_lock
1354
 
    def get_root_id(self):
1355
 
        """See Branch.get_root_id."""
1356
 
        tree = self.repository.revision_tree(self.last_revision())
1357
 
        return tree.get_root_id()
1358
 
 
1359
1359
    def is_locked(self):
1360
1360
        return self.control_files.is_locked()
1361
1361
 
1444
1444
        """
1445
1445
        revision_id = _mod_revision.ensure_null(revision_id)
1446
1446
        old_revno, old_revid = self.last_revision_info()
 
1447
        # this old format stores the full history, but this api doesn't
 
1448
        # provide it, so we must generate, and might as well check it's
 
1449
        # correct
1447
1450
        history = self._lefthand_history(revision_id)
1448
 
        assert len(history) == revno, '%d != %d' % (len(history), revno)
 
1451
        if len(history) != revno:
 
1452
            raise AssertionError('%d != %d' % (len(history), revno))
1449
1453
        self.set_revision_history(history)
1450
1454
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1451
1455
 
1525
1529
                elif heads == set([stop_revision, last_rev]):
1526
1530
                    # These branches have diverged
1527
1531
                    raise errors.DivergedBranches(self, other)
1528
 
                assert heads == set([stop_revision])
 
1532
                elif heads != set([stop_revision]):
 
1533
                    raise AssertionError("invalid heads: %r" % heads)
1529
1534
            if other_last_revision == stop_revision:
1530
1535
                self.set_last_revision_info(other_last_revno,
1531
1536
                                            other_last_revision)
1677
1682
 
1678
1683
    def get_parent(self):
1679
1684
        """See Branch.get_parent."""
1680
 
 
1681
 
        assert self.base[-1] == '/'
1682
1685
        parent = self._get_parent_location()
1683
1686
        if parent is None:
1684
1687
            return parent
1703
1706
        # TODO: Maybe delete old location files?
1704
1707
        # URLs should never be unicode, even on the local fs,
1705
1708
        # FIXUP this and get_parent in a future branch format bump:
1706
 
        # read and rewrite the file, and have the new format code read
1707
 
        # using .get not .get_utf8. RBC 20060125
 
1709
        # read and rewrite the file. RBC 20060125
1708
1710
        if url is not None:
1709
1711
            if isinstance(url, unicode):
1710
1712
                try: 
1720
1722
        if url is None:
1721
1723
            self.control_files._transport.delete('parent')
1722
1724
        else:
1723
 
            assert isinstance(url, str)
1724
1725
            self.control_files.put_bytes('parent', url + '\n')
1725
1726
 
1726
1727
 
1769
1770
 
1770
1771
    def get_bound_location(self):
1771
1772
        try:
1772
 
            return self.control_files.get_utf8('bound').read()[:-1]
 
1773
            return self._transport.get_bytes('bound')[:-1]
1773
1774
        except errors.NoSuchFile:
1774
1775
            return None
1775
1776
 
1896
1897
        Intended to be called by set_last_revision_info and
1897
1898
        _write_revision_history.
1898
1899
        """
1899
 
        assert revision_id is not None, "Use NULL_REVISION, not None"
 
1900
        revision_id = _mod_revision.ensure_null(revision_id)
1900
1901
        out_string = '%d %s\n' % (revno, revision_id)
1901
1902
        self.control_files.put_bytes('last-revision', out_string)
1902
1903
 
1945
1946
            iterator = repo.iter_reverse_revision_history(start_revision)
1946
1947
            #skip the last revision in the list
1947
1948
            next_revision = iterator.next()
1948
 
            assert next_revision == start_revision
1949
1949
        for revision_id in iterator:
1950
1950
            self._partial_revision_history_cache.append(revision_id)
1951
1951
            if (stop_index is not None and
2081
2081
            raise errors.NoSuchRevision(self, revno)
2082
2082
 
2083
2083
        if history is not None:
2084
 
            assert len(history) == last_revno, 'revno/history mismatch'
2085
2084
            return history[revno - 1]
2086
2085
 
2087
2086
        index = last_revno - revno