~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/serializer/v08.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical Development Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
94
94
        """
95
95
        return BundleReader(f).info
96
96
 
 
97
    def check_compatible(self):
 
98
        if self.source.supports_rich_root():
 
99
            raise errors.IncompatibleFormat('0.8', repr(self.source))
 
100
 
97
101
    def write(self, source, revision_ids, forced_bases, f):
98
102
        """Write the bundless to the supplied files.
99
103
 
106
110
        self.revision_ids = revision_ids
107
111
        self.forced_bases = forced_bases
108
112
        self.to_file = f
 
113
        self.check_compatible()
109
114
        source.lock_read()
110
115
        try:
111
116
            self._write_main_header()
182
187
            last_rev_id = base_id
183
188
            last_rev_tree = base_tree
184
189
 
 
190
    def _testament_sha1(self, revision_id):
 
191
        return StrictTestament.from_revision(self.source, 
 
192
                                             revision_id).as_sha1()
 
193
 
185
194
    def _write_revision(self, rev, rev_tree, base_rev, base_tree, 
186
195
                        explicit_base, force_binary):
187
196
        """Write out the information for a revision."""
196
205
        self._write_delta(rev_tree, base_tree, rev.revision_id, force_binary)
197
206
 
198
207
        w('revision id', rev.revision_id)
199
 
        w('sha1', StrictTestament.from_revision(self.source, 
200
 
                                                rev.revision_id).as_sha1())
 
208
        w('sha1', self._testament_sha1(rev.revision_id))
201
209
        w('inventory sha1', rev.inventory_sha1)
202
210
        if rev.parent_ids:
203
211
            w('parent ids', rev.parent_ids)
267
275
            else:
268
276
                action.write(self.to_file)
269
277
 
270
 
        delta = new_tree.changes_from(old_tree, want_unchanged=True)
 
278
        delta = new_tree.changes_from(old_tree, want_unchanged=True,
 
279
                                      include_root=True)
271
280
        for path, file_id, kind in delta.removed:
272
281
            action = Action('removed', [kind, path]).write(self.to_file)
273
282
 
316
325
        self.from_file = iter(from_file)
317
326
        self._next_line = None
318
327
        
319
 
        self.info = BundleInfo08()
 
328
        self.info = self._get_info()
320
329
        # We put the actual inventory ids in the footer, so that the patch
321
330
        # is easier to read for humans.
322
331
        # Unfortunately, that means we need to read everything before we
324
333
        self._read()
325
334
        self._validate()
326
335
 
 
336
    def _get_info(self):
 
337
        return BundleInfo08()
 
338
 
327
339
    def _read(self):
328
340
        self._next().next()
329
341
        while self._next_line is not None:
411
423
            return
412
424
 
413
425
        revision_info = self.info.revisions[-1]
414
 
        if hasattr(revision_info, key):
 
426
        if key in revision_info.__dict__:
415
427
            if getattr(revision_info, key) is None:
416
428
                setattr(revision_info, key, value)
417
429
            else:
502
514
 
503
515
 
504
516
class BundleInfo08(BundleInfo):
 
517
 
505
518
    def _update_tree(self, bundle_tree, revision_id):
506
519
        bundle_tree.note_last_changed('', revision_id)
507
520
        BundleInfo._update_tree(self, bundle_tree, revision_id)
 
521
 
 
522
    def _testament_sha1_from_revision(self, repository, revision_id):
 
523
        testament = StrictTestament.from_revision(repository, revision_id)
 
524
        return testament.as_sha1()
 
525
 
 
526
    def _testament_sha1(self, revision, inventory):
 
527
        return StrictTestament(revision, inventory).as_sha1()