/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/bundle/bundle_data.py

  • Committer: Andrew Bennetts
  • Date: 2008-09-08 12:59:00 UTC
  • mfrom: (3695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080908125900-8ywtsr7jqyyatjz0
Merge from 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:
158
159
    def get_base(self, revision):
159
160
        revision_info = self.get_revision_info(revision.revision_id)
160
161
        if revision_info.base_id is not None:
161
 
            if revision_info.base_id == NULL_REVISION:
162
 
                return None
163
 
            else:
164
 
                return revision_info.base_id
 
162
            return revision_info.base_id
165
163
        if len(revision.parent_ids) == 0:
166
164
            # There is no base listed, and
167
165
            # the lowest revision doesn't have a parent
168
166
            # so this is probably against the empty tree
169
 
            # and thus base truly is None
170
 
            return None
 
167
            # and thus base truly is NULL_REVISION
 
168
            return NULL_REVISION
171
169
        else:
172
170
            return revision.parent_ids[-1]
173
171
 
196
194
    def revision_tree(self, repository, revision_id, base=None):
197
195
        revision = self.get_revision(revision_id)
198
196
        base = self.get_base(revision)
199
 
        assert base != revision_id
 
197
        if base == revision_id:
 
198
            raise AssertionError()
200
199
        if not self._validated_revisions_against_repo:
201
200
            self._validate_references_from_repository(repository)
202
201
        revision_info = self.get_revision_info(revision_id)
260
259
            elif revision_id not in checked:
261
260
                missing[revision_id] = sha1
262
261
 
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
262
        if len(missing) > 0:
279
263
            # I don't know if this is an error yet
280
264
            warning('Not all revision hashes could be validated.'
286
270
        """At this point we should have generated the BundleTree,
287
271
        so build up an inventory, and make sure the hashes match.
288
272
        """
289
 
 
290
 
        assert inv is not None
291
 
 
292
273
        # Now we should have a complete inventory entry.
293
274
        s = serializer_v5.write_inventory_to_string(inv)
294
275
        sha1 = sha_string(s)
295
276
        # Target revision is the last entry in the real_revisions list
296
277
        rev = self.get_revision(revision_id)
297
 
        assert rev.revision_id == revision_id
 
278
        if rev.revision_id != revision_id:
 
279
            raise AssertionError()
298
280
        if sha1 != rev.inventory_sha1:
299
281
            open(',,bogus-inv', 'wb').write(s)
300
282
            warning('Inventory sha hash mismatch for revision %s. %s'
308
290
        
309
291
        rev = self.get_revision(revision_id)
310
292
        rev_info = self.get_revision_info(revision_id)
311
 
        assert rev.revision_id == rev_info.revision_id
312
 
        assert rev.revision_id == revision_id
 
293
        if not (rev.revision_id == rev_info.revision_id):
 
294
            raise AssertionError()
 
295
        if not (rev.revision_id == revision_id):
 
296
            raise AssertionError()
313
297
        sha1 = self._testament_sha1(rev, inventory)
314
298
        if sha1 != rev_info.sha1:
315
299
            raise TestamentMismatch(rev.revision_id, rev_info.sha1, sha1)
347
331
                if name == 'last-changed':
348
332
                    last_changed = value
349
333
                elif name == 'executable':
350
 
                    assert value in ('yes', 'no'), value
351
334
                    val = (value == 'yes')
352
335
                    bundle_tree.note_executable(new_path, val)
353
336
                elif name == 'target':
357
340
            return last_changed, encoding
358
341
 
359
342
        def do_patch(path, lines, encoding):
360
 
            if encoding is not None:
361
 
                assert encoding == 'base64'
 
343
            if encoding == 'base64':
362
344
                patch = base64.decodestring(''.join(lines))
363
 
            else:
 
345
            elif encoding is None:
364
346
                patch =  ''.join(lines)
 
347
            else:
 
348
                raise ValueError(encoding)
365
349
            bundle_tree.note_patch(path, patch)
366
350
 
367
351
        def renamed(kind, extra, lines):
495
479
 
496
480
    def note_rename(self, old_path, new_path):
497
481
        """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
 
482
        if new_path in self._renamed:
 
483
            raise AssertionError(new_path)
 
484
        if old_path in self._renamed_r:
 
485
            raise AssertionError(old_path)
500
486
        self._renamed[new_path] = old_path
501
487
        self._renamed_r[old_path] = new_path
502
488
 
532
518
 
533
519
    def old_path(self, new_path):
534
520
        """Get the old_path (path in the base_tree) for the file at new_path"""
535
 
        assert new_path[:1] not in ('\\', '/')
 
521
        if new_path[:1] in ('\\', '/'):
 
522
            raise ValueError(new_path)
536
523
        old_path = self._renamed.get(new_path)
537
524
        if old_path is not None:
538
525
            return old_path
558
545
        """Get the new_path (path in the target_tree) for the file at old_path
559
546
        in the base tree.
560
547
        """
561
 
        assert old_path[:1] not in ('\\', '/')
 
548
        if old_path[:1] in ('\\', '/'):
 
549
            raise ValueError(old_path)
562
550
        new_path = self._renamed_r.get(old_path)
563
551
        if new_path is not None:
564
552
            return new_path
637
625
            if (patch_original is None and 
638
626
                self.get_kind(file_id) == 'directory'):
639
627
                return StringIO()
640
 
            assert patch_original is not None, "None: %s" % file_id
 
628
            if patch_original is None:
 
629
                raise AssertionError("None: %s" % file_id)
641
630
            return patch_original
642
631
 
643
 
        assert not file_patch.startswith('\\'), \
644
 
            'Malformed patch for %s, %r' % (file_id, file_patch)
 
632
        if file_patch.startswith('\\'):
 
633
            raise ValueError(
 
634
                'Malformed patch for %s, %r' % (file_id, file_patch))
645
635
        return patched_file(file_patch, patch_original)
646
636
 
647
637
    def get_symlink_target(self, file_id):
694
684
        This need to be called before ever accessing self.inventory
695
685
        """
696
686
        from os.path import dirname, basename
697
 
 
698
 
        assert self.base_tree is not None
699
687
        base_inv = self.base_tree.inventory
700
688
        inv = Inventory(None, self.revision_id)
701
689