~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge from unique-root

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)
227
235
        old_label = ''
228
236
        new_label = ''
229
237
 
230
 
        def bundle_path(path):
231
 
            if path != '':
232
 
                return path
233
 
            else:
234
 
                return '.'
235
 
 
236
238
        def do_diff(file_id, old_path, new_path, action, force_binary):
237
239
            def tree_lines(tree, require_text=False):
238
240
                if file_id in tree:
262
264
        def finish_action(action, file_id, kind, meta_modified, text_modified,
263
265
                          old_path, new_path):
264
266
            entry = new_tree.inventory[file_id]
265
 
            if (entry.revision != default_revision_id and 
266
 
                entry.revision is not None):
 
267
            if entry.revision != default_revision_id:
267
268
                action.add_property('last-changed', entry.revision)
268
269
            if meta_modified:
269
270
                action.add_bool_property('executable', entry.executable)
274
275
            else:
275
276
                action.write(self.to_file)
276
277
 
277
 
        delta = new_tree.changes_from(old_tree, want_unchanged=True, 
 
278
        delta = new_tree.changes_from(old_tree, want_unchanged=True,
278
279
                                      include_root=True)
279
280
        for path, file_id, kind in delta.removed:
280
281
            action = Action('removed', [kind, path]).write(self.to_file)
281
282
 
282
283
        for path, file_id, kind in delta.added:
283
 
            action = Action('added', [kind, bundle_path(path)], 
284
 
                            [('file-id', file_id)])
 
284
            action = Action('added', [kind, path], [('file-id', file_id)])
285
285
            meta_modified = (kind=='file' and 
286
286
                             new_tree.is_executable(file_id))
287
287
            finish_action(action, file_id, kind, meta_modified, True,
289
289
 
290
290
        for (old_path, new_path, file_id, kind,
291
291
             text_modified, meta_modified) in delta.renamed:
292
 
            action = Action('renamed', [kind, bundle_path(old_path)], 
293
 
                            [(bundle_path(new_path),)])
 
292
            action = Action('renamed', [kind, old_path], [(new_path,)])
294
293
            finish_action(action, file_id, kind, meta_modified, text_modified,
295
294
                          old_path, new_path)
296
295
 
297
296
        for (path, file_id, kind,
298
297
             text_modified, meta_modified) in delta.modified:
299
 
            action = Action('modified', [kind, bundle_path(path)])
 
298
            action = Action('modified', [kind, path])
300
299
            finish_action(action, file_id, kind, meta_modified, text_modified,
301
300
                          path, path)
302
301
 
307
306
                continue
308
307
            old_rev = getattr(old_tree.inventory[ie.file_id], 'revision', None)
309
308
            if new_rev != old_rev:
310
 
                action = Action('modified', 
311
 
                    [ie.kind, bundle_path(new_tree.id2path(ie.file_id))])
312
 
                if ie.revision is not None:
313
 
                    action.add_property('last-changed', ie.revision)
 
309
                action = Action('modified', [ie.kind, 
 
310
                                             new_tree.id2path(ie.file_id)])
 
311
                action.add_property('last-changed', ie.revision)
314
312
                action.write(self.to_file)
315
313
 
316
314
 
327
325
        self.from_file = iter(from_file)
328
326
        self._next_line = None
329
327
        
330
 
        self.info = BundleInfo08()
 
328
        self.info = self._get_info()
331
329
        # We put the actual inventory ids in the footer, so that the patch
332
330
        # is easier to read for humans.
333
331
        # Unfortunately, that means we need to read everything before we
335
333
        self._read()
336
334
        self._validate()
337
335
 
 
336
    def _get_info(self):
 
337
        return BundleInfo08()
 
338
 
338
339
    def _read(self):
339
340
        self._next().next()
340
341
        while self._next_line is not None:
513
514
 
514
515
 
515
516
class BundleInfo08(BundleInfo):
 
517
 
516
518
    def _update_tree(self, bundle_tree, revision_id):
517
519
        bundle_tree.note_last_changed('', revision_id)
518
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()