~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.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:
95
95
        if committer is None:
96
96
            self._committer = self._config.username()
97
97
        else:
98
 
            assert isinstance(committer, basestring), type(committer)
99
98
            self._committer = committer
100
99
 
101
100
        self.new_inventory = Inventory(None)
328
327
            if kind != parent_entry.kind:
329
328
                store = True
330
329
        if kind == 'file':
331
 
            assert content_summary[2] is not None, \
332
 
                "Files must not have executable = None"
 
330
            if content_summary[2] is None:
 
331
                raise ValueError("Files must not have executable = None")
333
332
            if not store:
334
333
                if (# if the file length changed we have to store:
335
334
                    parent_entry.text_size != content_summary[1] or
501
500
        :returns: The validator(which is a sha1 digest, though what is sha'd is
502
501
            repository format specific) of the serialized inventory.
503
502
        """
504
 
        assert self.is_in_write_group()
 
503
        if not self.is_in_write_group():
 
504
            raise AssertionError("%r not in write group" % (self,))
505
505
        _mod_revision.check_not_reserved_id(revision_id)
506
 
        assert inv.revision_id is None or inv.revision_id == revision_id, \
507
 
            "Mismatch between inventory revision" \
508
 
            " id and insertion revid (%r, %r)" % (inv.revision_id, revision_id)
509
 
        assert inv.root is not None
 
506
        if not (inv.revision_id is None or inv.revision_id == revision_id):
 
507
            raise AssertionError(
 
508
                "Mismatch between inventory revision"
 
509
                " id and insertion revid (%r, %r)"
 
510
                % (inv.revision_id, revision_id))
 
511
        if inv.root is None:
 
512
            raise AssertionError()
510
513
        inv_lines = self._serialise_inventory_to_lines(inv)
511
514
        inv_vf = self.get_inventory_weave()
512
515
        return self._inventory_add_lines(inv_vf, revision_id, parents,
1092
1095
                raise errors.InvalidRevisionId(revision_id=rev_id, branch=self)
1093
1096
        revs = self._revision_store.get_revisions(revision_ids,
1094
1097
                                                  self.get_transaction())
1095
 
        for rev in revs:
1096
 
            assert not isinstance(rev.revision_id, unicode)
1097
 
            for parent_id in rev.parent_ids:
1098
 
                assert not isinstance(parent_id, unicode)
1099
1098
        return revs
1100
1099
 
1101
1100
    @needs_read_lock
1501
1500
 
1502
1501
        :return: An iterator of inventories.
1503
1502
        """
1504
 
        assert None not in revision_ids
1505
 
        assert _mod_revision.NULL_REVISION not in revision_ids
 
1503
        if ((None in revision_ids)
 
1504
            or (_mod_revision.NULL_REVISION in revision_ids)):
 
1505
            raise ValueError('cannot get null revision inventory')
1506
1506
        return self._iter_inventories(revision_ids)
1507
1507
 
1508
1508
    def _iter_inventories(self, revision_ids):
1536
1536
    def get_inventory_xml(self, revision_id):
1537
1537
        """Get inventory XML as a file object."""
1538
1538
        try:
1539
 
            assert isinstance(revision_id, str), type(revision_id)
1540
1539
            iw = self.get_inventory_weave()
1541
1540
            return iw.get_text(revision_id)
1542
1541
        except IndexError:
2444
2443
        target_ids = set(self.target.all_revision_ids())
2445
2444
        if revision_id is not None:
2446
2445
            source_ids = self.source.get_ancestry(revision_id)
2447
 
            assert source_ids[0] is None
 
2446
            if source_ids[0] is not None:
 
2447
                raise AssertionError()
2448
2448
            source_ids.pop(0)
2449
2449
        else:
2450
2450
            source_ids = self.source.all_revision_ids()
2611
2611
        # - RBC 20060209
2612
2612
        if revision_id is not None:
2613
2613
            source_ids = self.source.get_ancestry(revision_id)
2614
 
            assert source_ids[0] is None
 
2614
            if source_ids[0] is not None:
 
2615
                raise AssertionError()
2615
2616
            source_ids.pop(0)
2616
2617
        else:
2617
2618
            source_ids = self.source._all_possible_ids()
2680
2681
        """See InterRepository.missing_revision_ids()."""
2681
2682
        if revision_id is not None:
2682
2683
            source_ids = self.source.get_ancestry(revision_id)
2683
 
            assert source_ids[0] is None
 
2684
            if source_ids[0] is not None:
 
2685
                raise AssertionError()
2684
2686
            source_ids.pop(0)
2685
2687
        else:
2686
2688
            source_ids = self.source.all_revision_ids()
2786
2788
            return self._walk_to_common_revisions([revision_id])
2787
2789
        elif revision_id is not None:
2788
2790
            source_ids = self.source.get_ancestry(revision_id)
2789
 
            assert source_ids[0] is None
 
2791
            if source_ids[0] is not None:
 
2792
                raise AssertionError()
2790
2793
            source_ids.pop(0)
2791
2794
        else:
2792
2795
            source_ids = self.source.all_revision_ids()
2953
2956
        # Is source's model compatible with target's model?
2954
2957
        source._ensure_real()
2955
2958
        real_source = source._real_repository
2956
 
        assert not isinstance(real_source, remote.RemoteRepository), (
2957
 
            "We don't support remote repos backed by remote repos yet.")
 
2959
        if isinstance(real_source, remote.RemoteRepository):
 
2960
            raise NotImplementedError(
 
2961
                "We don't support remote repos backed by remote repos yet.")
2958
2962
        return InterRepository._same_model(real_source, target)
2959
2963
 
2960
2964
    @needs_write_lock