~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.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:
1039
1039
    def __init__(self, _transport, _format):
1040
1040
        """See BzrDir.__init__."""
1041
1041
        super(BzrDirPreSplitOut, self).__init__(_transport, _format)
1042
 
        assert self._format._lock_class == lockable_files.TransportLock
1043
 
        assert self._format._lock_file_name == 'branch-lock'
1044
1042
        self._control_files = lockable_files.LockableFiles(
1045
1043
                                            self.get_branch_transport(None),
1046
1044
                                            self._format._lock_file_name,
1647
1645
 
1648
1646
    @classmethod
1649
1647
    def unregister_format(klass, format):
1650
 
        assert klass._formats[format.get_format_string()] is format
1651
1648
        del klass._formats[format.get_format_string()]
1652
1649
 
1653
1650
    @classmethod
2077
2074
            self.revisions[rev_id] = rev
2078
2075
 
2079
2076
    def _load_old_inventory(self, rev_id):
2080
 
        assert rev_id not in self.converted_revs
2081
2077
        old_inv_xml = self.branch.repository.inventory_store.get(rev_id).read()
2082
2078
        inv = xml4.serializer_v4.read_inventory_from_string(old_inv_xml)
2083
2079
        inv.revision_id = rev_id
2084
2080
        rev = self.revisions[rev_id]
2085
 
        if rev.inventory_sha1:
2086
 
            assert rev.inventory_sha1 == sha_string(old_inv_xml), \
2087
 
                'inventory sha mismatch for {%s}' % rev_id
2088
2081
        return inv
2089
2082
 
2090
2083
    def _load_updated_inventory(self, rev_id):
2091
 
        assert rev_id in self.converted_revs
2092
2084
        inv_xml = self.inv_weave.get_text(rev_id)
2093
2085
        inv = xml5.serializer_v5.read_inventory_from_string(inv_xml, rev_id)
2094
2086
        return inv
2104
2096
        self.converted_revs.add(rev_id)
2105
2097
 
2106
2098
    def _store_new_inv(self, rev, inv, present_parents):
2107
 
        # the XML is now updated with text versions
2108
 
        if __debug__:
2109
 
            entries = inv.iter_entries()
2110
 
            entries.next()
2111
 
            for path, ie in entries:
2112
 
                assert getattr(ie, 'revision', None) is not None, \
2113
 
                    'no revision on {%s} in {%s}' % \
2114
 
                    (file_id, rev.revision_id)
2115
2099
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv)
2116
2100
        new_inv_sha1 = sha_string(new_inv_xml)
2117
2101
        self.inv_weave.add_lines(rev.revision_id,
2146
2130
            self.text_weaves[file_id] = w
2147
2131
        text_changed = False
2148
2132
        parent_candiate_entries = ie.parent_candidates(parent_invs)
2149
 
        for old_revision in parent_candiate_entries.keys():
2150
 
            # if this fails, its a ghost ?
2151
 
            assert old_revision in self.converted_revs, \
2152
 
                "Revision {%s} not in converted_revs" % old_revision
2153
2133
        heads = graph.Graph(self).heads(parent_candiate_entries.keys())
2154
2134
        # XXX: Note that this is unordered - and this is tolerable because 
2155
2135
        # the previous code was also unordered.
2157
2137
            in heads)
2158
2138
        self.snapshot_ie(previous_entries, ie, w, rev_id)
2159
2139
        del ie.text_id
2160
 
        assert getattr(ie, 'revision', None) is not None
2161
2140
 
2162
2141
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
2163
2142
    def get_parents(self, revision_ids):
2186
2165
        if ie.has_text():
2187
2166
            text = self.branch.repository.weave_store.get(ie.text_id)
2188
2167
            file_lines = text.readlines()
2189
 
            assert sha_strings(file_lines) == ie.text_sha1
2190
 
            assert sum(map(len, file_lines)) == ie.text_size
2191
2168
            w.add_lines(rev_id, previous_revisions, file_lines)
2192
2169
            self.text_count += 1
2193
2170
        else:
2467
2444
        client = _SmartClient(client_medium, transport.base)
2468
2445
        path = client.remote_path_from_transport(transport)
2469
2446
        response = client.call('BzrDirFormat.initialize', path)
2470
 
        assert response[0] in ('ok', ), 'unexpected response code %s' % (response,)
 
2447
        if response[0] != 'ok':
 
2448
            raise errors.SmartProtocolError('unexpected response code %s' % (response,))
2471
2449
        return remote.RemoteBzrDir(transport)
2472
2450
 
2473
2451
    def _open(self, transport):
2595
2573
            self.remove('default')
2596
2574
        self.set_default(key)
2597
2575
        format = self.get('default')()
2598
 
        assert isinstance(format, BzrDirMetaFormat1)
2599
2576
 
2600
2577
    def make_bzrdir(self, key):
2601
2578
        return self.get(key)()