~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-01 23:48:08 UTC
  • mfrom: (2225.1.6 revert)
  • Revision ID: pqm@pqm.ubuntu.com-20070201234808-3b1302d73474bd8c
Display changes made by revert

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# (C) 2005 Canonical Development Ltd
 
1
# Copyright (C) 2005, 2006 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.IncompatibleBundleFormat('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()
158
163
            if rev_id == last_rev_id:
159
164
                rev_tree = last_rev_tree
160
165
            else:
161
 
                base_tree = self.source.revision_tree(rev_id)
162
 
            rev_tree = self.source.revision_tree(rev_id)
 
166
                rev_tree = self.source.revision_tree(rev_id)
163
167
            if rev_id in self.forced_bases:
164
168
                explicit_base = True
165
169
                base_id = self.forced_bases[rev_id]
183
187
            last_rev_id = base_id
184
188
            last_rev_tree = base_tree
185
189
 
 
190
    def _testament_sha1(self, revision_id):
 
191
        return StrictTestament.from_revision(self.source, 
 
192
                                             revision_id).as_sha1()
 
193
 
186
194
    def _write_revision(self, rev, rev_tree, base_rev, base_tree, 
187
195
                        explicit_base, force_binary):
188
196
        """Write out the information for a revision."""
197
205
        self._write_delta(rev_tree, base_tree, rev.revision_id, force_binary)
198
206
 
199
207
        w('revision id', rev.revision_id)
200
 
        w('sha1', StrictTestament.from_revision(self.source, 
201
 
                                                rev.revision_id).as_sha1())
 
208
        w('sha1', self._testament_sha1(rev.revision_id))
202
209
        w('inventory sha1', rev.inventory_sha1)
203
210
        if rev.parent_ids:
204
211
            w('parent ids', rev.parent_ids)
268
275
            else:
269
276
                action.write(self.to_file)
270
277
 
271
 
        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)
272
280
        for path, file_id, kind in delta.removed:
273
281
            action = Action('removed', [kind, path]).write(self.to_file)
274
282
 
317
325
        self.from_file = iter(from_file)
318
326
        self._next_line = None
319
327
        
320
 
        self.info = BundleInfo()
 
328
        self.info = self._get_info()
321
329
        # We put the actual inventory ids in the footer, so that the patch
322
330
        # is easier to read for humans.
323
331
        # Unfortunately, that means we need to read everything before we
325
333
        self._read()
326
334
        self._validate()
327
335
 
 
336
    def _get_info(self):
 
337
        return BundleInfo08()
 
338
 
328
339
    def _read(self):
329
340
        self._next().next()
330
341
        while self._next_line is not None:
412
423
            return
413
424
 
414
425
        revision_info = self.info.revisions[-1]
415
 
        if hasattr(revision_info, key):
 
426
        if key in revision_info.__dict__:
416
427
            if getattr(revision_info, key) is None:
417
428
                setattr(revision_info, key, value)
418
429
            else:
500
511
                # Consume the trailing \n and stop processing
501
512
                self._next().next()
502
513
                break
 
514
 
 
515
 
 
516
class BundleInfo08(BundleInfo):
 
517
 
 
518
    def _update_tree(self, bundle_tree, revision_id):
 
519
        bundle_tree.note_last_changed('', revision_id)
 
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()