~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.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:
112
112
    InventoryFile('2326', 'wibble.c', parent_id='2325', sha1=None, len=None)
113
113
    >>> for path, entry in i.iter_entries():
114
114
    ...     print path
115
 
    ...     assert i.path2id(path)
116
115
    ... 
117
116
    <BLANKLINE>
118
117
    src
142
141
        """
143
142
        return False, False
144
143
 
145
 
    @deprecated_method(symbol_versioning.one_zero)
146
 
    def diff(self, text_diff, from_label, tree, to_label, to_entry, to_tree,
147
 
             output_to, reverse=False):
148
 
        """Perform a diff from this to to_entry.
149
 
 
150
 
        text_diff will be used for textual difference calculation.
151
 
        This is a template method, override _diff in child classes.
152
 
        """
153
 
        self._read_tree_state(tree.id2path(self.file_id), tree)
154
 
        if to_entry:
155
 
            # cannot diff from one kind to another - you must do a removal
156
 
            # and an addif they do not match.
157
 
            assert self.kind == to_entry.kind
158
 
            to_entry._read_tree_state(to_tree.id2path(to_entry.file_id),
159
 
                                      to_tree)
160
 
        self._diff(text_diff, from_label, tree, to_label, to_entry, to_tree,
161
 
                   output_to, reverse)
162
 
 
163
144
    def _diff(self, text_diff, from_label, tree, to_label, to_entry, to_tree,
164
145
             output_to, reverse=False):
165
146
        """Perform a diff between two entries of the same kind."""
179
160
        for inv in previous_inventories:
180
161
            if self.file_id in inv:
181
162
                ie = inv[self.file_id]
182
 
                assert ie.file_id == self.file_id
183
163
                if ie.revision in candidates:
184
164
                    # same revision value in two different inventories:
185
165
                    # correct possible inconsistencies:
191
171
                            ie.executable = False
192
172
                    except AttributeError:
193
173
                        pass
194
 
                    # must now be the same.
195
 
                    assert candidates[ie.revision] == ie
196
174
                else:
197
175
                    # add this revision as a candidate.
198
176
                    candidates[ie.revision] = ie
303
281
        Traceback (most recent call last):
304
282
        InvalidEntryName: Invalid entry name: src/hello.c
305
283
        """
306
 
        assert isinstance(name, basestring), name
307
284
        if '/' in name or '\\' in name:
308
285
            raise errors.InvalidEntryName(name=name)
309
286
        self.executable = False
311
288
        self.text_sha1 = None
312
289
        self.text_size = None
313
290
        self.file_id = file_id
314
 
        assert isinstance(file_id, (str, None.__class__)), \
315
 
            'bad type %r for %r' % (type(file_id), file_id)
316
291
        self.name = name
317
292
        self.text_id = text_id
318
293
        self.parent_id = parent_id
611
586
 
612
587
    def detect_changes(self, old_entry):
613
588
        """See InventoryEntry.detect_changes."""
614
 
        assert self.text_sha1 is not None
615
 
        assert old_entry.text_sha1 is not None
616
589
        text_modified = (self.text_sha1 != old_entry.text_sha1)
617
590
        meta_modified = (self.executable != old_entry.executable)
618
591
        return text_modified, meta_modified
868
841
        an id of None.
869
842
        """
870
843
        if root_id is not None:
871
 
            assert root_id.__class__ == str
872
844
            self._set_root(InventoryDirectory(root_id, u'', None))
873
845
        else:
874
846
            self.root = None
1173
1145
                                         self._byid[entry.file_id])
1174
1146
 
1175
1147
        if entry.parent_id is None:
1176
 
            assert self.root is None and len(self._byid) == 0
1177
1148
            self.root = entry
1178
1149
        else:
1179
1150
            try:
1225
1196
        False
1226
1197
        """
1227
1198
        ie = self[file_id]
1228
 
 
1229
 
        assert ie.parent_id is None or \
1230
 
            self[ie.parent_id].children[ie.name] == ie
1231
 
        
1232
1199
        del self._byid[file_id]
1233
1200
        if ie.parent_id is not None:
1234
1201
            del self[ie.parent_id].children[ie.name]
1322
1289
                if children is None:
1323
1290
                    return None
1324
1291
                cie = children[f]
1325
 
                assert cie.name == f
1326
 
                assert cie.parent_id == parent.file_id
1327
1292
                parent = cie
1328
1293
            except KeyError:
1329
1294
                # or raise an error?