/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

  • Committer: Martin Pool
  • Date: 2008-04-24 07:22:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080424072253-opmjij7xfy38w27f
Remove every assert statement from bzrlib!

Depending on the context they are:

 * turned into an explicit if/raise of either AssertionError 
   or something more specific -- particularly where they protect
   programming interfaces, complex invariants, or data file integrity
 * removed, if they're redundant with a later check, not protecting
   a meaningful invariant
 * turned into a selftest method on tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
317
317
        The delta is relative to its mainline predecessor, or the
318
318
        empty tree for revision 1.
319
319
        """
320
 
        assert isinstance(revno, int)
321
320
        rh = self.revision_history()
322
321
        if not (1 <= revno <= len(rh)):
323
322
            raise errors.InvalidRevisionNumber(revno)
451
450
        if stop_revision is None:
452
451
            stop_revision = other_len
453
452
        else:
454
 
            assert isinstance(stop_revision, int)
455
453
            if stop_revision > other_len:
456
454
                raise errors.NoSuchRevision(self, stop_revision)
457
455
        return other_history[self_len:stop_revision]
939
937
 
940
938
    @classmethod
941
939
    def unregister_format(klass, format):
942
 
        assert klass._formats[format.get_format_string()] is format
943
940
        del klass._formats[format.get_format_string()]
944
941
 
945
942
    def __str__(self):
1149
1146
        """
1150
1147
        if not _found:
1151
1148
            format = BranchFormat.find_format(a_bzrdir)
1152
 
            assert format.__class__ == self.__class__
 
1149
            if format.__class__ != self.__class__:
 
1150
                raise AssertionError("wrong format %r found for %r" %
 
1151
                    (format, self))
1153
1152
        try:
1154
1153
            transport = a_bzrdir.get_branch_transport(None)
1155
1154
            control_files = lockable_files.LockableFiles(transport, 'lock',
1197
1196
        """
1198
1197
        if not _found:
1199
1198
            format = BranchFormat.find_format(a_bzrdir)
1200
 
            assert format.__class__ == self.__class__
 
1199
            if format.__class__ != self.__class__:
 
1200
                raise AssertionError("wrong format %r found for %r" %
 
1201
                    (format, self))
1201
1202
        transport = a_bzrdir.get_branch_transport(None)
1202
1203
        control_files = lockable_files.LockableFiles(transport, 'lock',
1203
1204
                                                     lockdir.LockDir)
1277
1278
        """
1278
1279
        if not _found:
1279
1280
            format = BranchFormat.find_format(a_bzrdir)
1280
 
            assert format.__class__ == self.__class__
 
1281
            if format.__class__ != self.__class__:
 
1282
                raise AssertionError("wrong format %r found for %r" %
 
1283
                    (format, self))
1281
1284
        if location is None:
1282
1285
            location = self.get_reference(a_bzrdir)
1283
1286
        real_bzrdir = bzrdir.BzrDir.open(
1444
1447
        """
1445
1448
        revision_id = _mod_revision.ensure_null(revision_id)
1446
1449
        old_revno, old_revid = self.last_revision_info()
 
1450
        # this old format stores the full history, but this api doesn't
 
1451
        # provide it, so we must generate, and might as well check it's
 
1452
        # correct
1447
1453
        history = self._lefthand_history(revision_id)
1448
 
        assert len(history) == revno, '%d != %d' % (len(history), revno)
 
1454
        if len(history) != revno:
 
1455
            raise AssertionError('%d != %d' % (len(history), revno))
1449
1456
        self.set_revision_history(history)
1450
1457
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1451
1458
 
1525
1532
                elif heads == set([stop_revision, last_rev]):
1526
1533
                    # These branches have diverged
1527
1534
                    raise errors.DivergedBranches(self, other)
1528
 
                assert heads == set([stop_revision])
 
1535
                elif heads != set([stop_revision]):
 
1536
                    raise AssertionError("invalid heads: %r" % heads)
1529
1537
            if other_last_revision == stop_revision:
1530
1538
                self.set_last_revision_info(other_last_revno,
1531
1539
                                            other_last_revision)
1677
1685
 
1678
1686
    def get_parent(self):
1679
1687
        """See Branch.get_parent."""
1680
 
 
1681
 
        assert self.base[-1] == '/'
1682
1688
        parent = self._get_parent_location()
1683
1689
        if parent is None:
1684
1690
            return parent
1720
1726
        if url is None:
1721
1727
            self.control_files._transport.delete('parent')
1722
1728
        else:
1723
 
            assert isinstance(url, str)
1724
1729
            self.control_files.put_bytes('parent', url + '\n')
1725
1730
 
1726
1731
 
1896
1901
        Intended to be called by set_last_revision_info and
1897
1902
        _write_revision_history.
1898
1903
        """
1899
 
        assert revision_id is not None, "Use NULL_REVISION, not None"
 
1904
        revision_id = _mod_revision.ensure_null(revision_id)
1900
1905
        out_string = '%d %s\n' % (revno, revision_id)
1901
1906
        self.control_files.put_bytes('last-revision', out_string)
1902
1907
 
1945
1950
            iterator = repo.iter_reverse_revision_history(start_revision)
1946
1951
            #skip the last revision in the list
1947
1952
            next_revision = iterator.next()
1948
 
            assert next_revision == start_revision
1949
1953
        for revision_id in iterator:
1950
1954
            self._partial_revision_history_cache.append(revision_id)
1951
1955
            if (stop_index is not None and
2081
2085
            raise errors.NoSuchRevision(self, revno)
2082
2086
 
2083
2087
        if history is not None:
2084
 
            assert len(history) == last_revno, 'revno/history mismatch'
2085
2088
            return history[revno - 1]
2086
2089
 
2087
2090
        index = last_revno - revno