~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.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:
222
222
        if not _internal:
223
223
            raise errors.BzrError("Please use bzrdir.open_workingtree or "
224
224
                "WorkingTree.open() to obtain a WorkingTree.")
225
 
        assert isinstance(basedir, basestring), \
226
 
            "base directory %r is not a string" % basedir
227
225
        basedir = safe_unicode(basedir)
228
226
        mutter("opening working tree %r", basedir)
229
227
        if deprecated_passed(branch):
237
235
            self._control_files = self.branch.control_files
238
236
        else:
239
237
            # assume all other formats have their own control files.
240
 
            assert isinstance(_control_files, LockableFiles), \
241
 
                    "_control_files must be a LockableFiles, not %r" \
242
 
                    % _control_files
243
238
            self._control_files = _control_files
244
239
        # update the whole cache up front and write to disk if anything changed;
245
240
        # in the future we might want to do this more selectively
318
313
            False then the inventory is the same as that on disk and any
319
314
            serialisation would be unneeded overhead.
320
315
        """
321
 
        assert inv.root is not None
322
316
        self._inventory = inv
323
317
        self._inventory_is_modified = dirty
324
318
 
664
658
        # function - they should be part of lock_write and unlock.
665
659
        inv = self.inventory
666
660
        for f, file_id, kind in zip(files, ids, kinds):
667
 
            assert kind is not None
668
661
            if file_id is None:
669
662
                inv.add_path(f, kind=kind)
670
663
            else:
1269
1262
                                       DeprecationWarning)
1270
1263
 
1271
1264
        # check destination directory
1272
 
        assert not isinstance(from_paths, basestring)
 
1265
        if isinstance(from_paths, basestring):
 
1266
            raise ValueError()
1273
1267
        inv = self.inventory
1274
1268
        to_abs = self.abspath(to_dir)
1275
1269
        if not isdir(to_abs):
1820
1814
 
1821
1815
    def _write_basis_inventory(self, xml):
1822
1816
        """Write the basis inventory XML to the basis-inventory file"""
1823
 
        assert isinstance(xml, str), 'serialised xml must be bytestring.'
1824
1817
        path = self._basis_inventory_name()
1825
1818
        sio = StringIO(xml)
1826
1819
        self._control_files.put(path, sio)
2739
2732
 
2740
2733
    @classmethod
2741
2734
    def unregister_format(klass, format):
2742
 
        assert klass._formats[format.get_format_string()] is format
2743
2735
        del klass._formats[format.get_format_string()]
2744
2736
 
2745
2737