~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

Merge up bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
            for property in self.properties:
79
79
                key_end = property.find(': ')
80
80
                if key_end == -1:
81
 
                    assert property.endswith(':')
 
81
                    if not property.endswith(':'):
 
82
                        raise ValueError(property)
82
83
                    key = str(property[:-1])
83
84
                    value = ''
84
85
                else:
196
197
    def revision_tree(self, repository, revision_id, base=None):
197
198
        revision = self.get_revision(revision_id)
198
199
        base = self.get_base(revision)
199
 
        assert base != revision_id
 
200
        if base == revision_id:
 
201
            raise AssertionError()
200
202
        if not self._validated_revisions_against_repo:
201
203
            self._validate_references_from_repository(repository)
202
204
        revision_info = self.get_revision_info(revision_id)
260
262
            elif revision_id not in checked:
261
263
                missing[revision_id] = sha1
262
264
 
263
 
        for inv_id, sha1 in inv_to_sha.iteritems():
264
 
            if repository.has_revision(inv_id):
265
 
                # Note: branch.get_inventory_sha1() just returns the value that
266
 
                # is stored in the revision text, and that value may be out
267
 
                # of date. This is bogus, because that means we aren't
268
 
                # validating the actual text, just that we wrote and read the
269
 
                # string. But for now, what the hell.
270
 
                local_sha1 = repository.get_inventory_sha1(inv_id)
271
 
                if sha1 != local_sha1:
272
 
                    raise BzrError('sha1 mismatch. For inventory id {%s}' 
273
 
                                   'local: %s, bundle: %s' % 
274
 
                                   (inv_id, local_sha1, sha1))
275
 
                else:
276
 
                    count += 1
277
 
 
278
265
        if len(missing) > 0:
279
266
            # I don't know if this is an error yet
280
267
            warning('Not all revision hashes could be validated.'
286
273
        """At this point we should have generated the BundleTree,
287
274
        so build up an inventory, and make sure the hashes match.
288
275
        """
289
 
 
290
 
        assert inv is not None
291
 
 
292
276
        # Now we should have a complete inventory entry.
293
277
        s = serializer_v5.write_inventory_to_string(inv)
294
278
        sha1 = sha_string(s)
295
279
        # Target revision is the last entry in the real_revisions list
296
280
        rev = self.get_revision(revision_id)
297
 
        assert rev.revision_id == revision_id
 
281
        if rev.revision_id != revision_id:
 
282
            raise AssertionError()
298
283
        if sha1 != rev.inventory_sha1:
299
284
            open(',,bogus-inv', 'wb').write(s)
300
285
            warning('Inventory sha hash mismatch for revision %s. %s'
308
293
        
309
294
        rev = self.get_revision(revision_id)
310
295
        rev_info = self.get_revision_info(revision_id)
311
 
        assert rev.revision_id == rev_info.revision_id
312
 
        assert rev.revision_id == revision_id
 
296
        if not (rev.revision_id == rev_info.revision_id):
 
297
            raise AssertionError()
 
298
        if not (rev.revision_id == revision_id):
 
299
            raise AssertionError()
313
300
        sha1 = self._testament_sha1(rev, inventory)
314
301
        if sha1 != rev_info.sha1:
315
302
            raise TestamentMismatch(rev.revision_id, rev_info.sha1, sha1)
347
334
                if name == 'last-changed':
348
335
                    last_changed = value
349
336
                elif name == 'executable':
350
 
                    assert value in ('yes', 'no'), value
351
337
                    val = (value == 'yes')
352
338
                    bundle_tree.note_executable(new_path, val)
353
339
                elif name == 'target':
357
343
            return last_changed, encoding
358
344
 
359
345
        def do_patch(path, lines, encoding):
360
 
            if encoding is not None:
361
 
                assert encoding == 'base64'
 
346
            if encoding == 'base64':
362
347
                patch = base64.decodestring(''.join(lines))
363
 
            else:
 
348
            elif encoding is None:
364
349
                patch =  ''.join(lines)
 
350
            else:
 
351
                raise ValueError(encoding)
365
352
            bundle_tree.note_patch(path, patch)
366
353
 
367
354
        def renamed(kind, extra, lines):
495
482
 
496
483
    def note_rename(self, old_path, new_path):
497
484
        """A file/directory has been renamed from old_path => new_path"""
498
 
        assert new_path not in self._renamed
499
 
        assert old_path not in self._renamed_r
 
485
        if new_path in self._renamed:
 
486
            raise AssertionError(new_path)
 
487
        if old_path in self._renamed_r:
 
488
            raise AssertionError(old_path)
500
489
        self._renamed[new_path] = old_path
501
490
        self._renamed_r[old_path] = new_path
502
491
 
532
521
 
533
522
    def old_path(self, new_path):
534
523
        """Get the old_path (path in the base_tree) for the file at new_path"""
535
 
        assert new_path[:1] not in ('\\', '/')
 
524
        if new_path[:1] in ('\\', '/'):
 
525
            raise ValueError(new_path)
536
526
        old_path = self._renamed.get(new_path)
537
527
        if old_path is not None:
538
528
            return old_path
558
548
        """Get the new_path (path in the target_tree) for the file at old_path
559
549
        in the base tree.
560
550
        """
561
 
        assert old_path[:1] not in ('\\', '/')
 
551
        if old_path[:1] in ('\\', '/'):
 
552
            raise ValueError(old_path)
562
553
        new_path = self._renamed_r.get(old_path)
563
554
        if new_path is not None:
564
555
            return new_path
637
628
            if (patch_original is None and 
638
629
                self.get_kind(file_id) == 'directory'):
639
630
                return StringIO()
640
 
            assert patch_original is not None, "None: %s" % file_id
 
631
            if patch_original is None:
 
632
                raise AssertionError("None: %s" % file_id)
641
633
            return patch_original
642
634
 
643
 
        assert not file_patch.startswith('\\'), \
644
 
            'Malformed patch for %s, %r' % (file_id, file_patch)
 
635
        if file_patch.startswith('\\'):
 
636
            raise ValueError(
 
637
                'Malformed patch for %s, %r' % (file_id, file_patch))
645
638
        return patched_file(file_patch, patch_original)
646
639
 
647
640
    def get_symlink_target(self, file_id):
694
687
        This need to be called before ever accessing self.inventory
695
688
        """
696
689
        from os.path import dirname, basename
697
 
 
698
 
        assert self.base_tree is not None
699
690
        base_inv = self.base_tree.inventory
700
691
        inv = Inventory(None, self.revision_id)
701
692