~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2007-08-13 14:33:10 UTC
  • mto: (2733.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2734.
  • Revision ID: ian.clatworthy@internode.on.net-20070813143310-twhj4la0qnupvze8
Added Quick Start Summary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2009 Canonical 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Serializer factory for reading and writing bundles.
18
18
"""
19
19
 
20
20
import os
21
21
 
22
 
from bzrlib import (
23
 
    errors,
24
 
    ui,
25
 
    )
 
22
from bzrlib import errors
26
23
from bzrlib.bundle.serializer import (BundleSerializer,
27
24
                                      _get_bundle_header,
28
25
                                     )
30
27
from bzrlib.bundle.bundle_data import (RevisionInfo, BundleInfo, BundleTree)
31
28
from bzrlib.diff import internal_diff
32
29
from bzrlib.osutils import pathjoin
 
30
from bzrlib.progress import DummyProgress
33
31
from bzrlib.revision import NULL_REVISION
 
32
import bzrlib.ui
34
33
from bzrlib.testament import StrictTestament
35
34
from bzrlib.timestamp import (
36
35
    format_highres_date,
120
119
        source.lock_read()
121
120
        try:
122
121
            self._write_main_header()
123
 
            pb = ui.ui_factory.nested_progress_bar()
 
122
            pb = DummyProgress()
124
123
            try:
125
124
                self._write_revisions(pb)
126
125
            finally:
127
 
                pb.finished()
 
126
                pass
 
127
                #pb.finished()
128
128
        finally:
129
129
            source.unlock()
130
130
 
146
146
            If this parameter is True, and value is the empty string, we will
147
147
            write an extra space.
148
148
        """
149
 
        if indent < 1:
150
 
            raise ValueError('indentation must be greater than 0')
 
149
        assert indent > 0, 'indentation must be greater than 0'
151
150
        f = self.to_file
152
151
        f.write('#' + (' ' * indent))
153
152
        f.write(key.encode('utf-8'))
183
182
 
184
183
        i_max = len(self.revision_ids)
185
184
        for i, rev_id in enumerate(self.revision_ids):
186
 
            pb.update("Generating revision data", i, i_max)
 
185
            pb.update("Generating revsion data", i, i_max)
187
186
            rev = self.source.get_revision(rev_id)
188
187
            if rev_id == last_rev_id:
189
188
                rev_tree = last_rev_tree
206
205
            else:
207
206
                base_tree = self.source.revision_tree(base_id)
208
207
            force_binary = (i != 0)
209
 
            self._write_revision(rev, rev_tree, base_id, base_tree,
 
208
            self._write_revision(rev, rev_tree, base_id, base_tree, 
210
209
                                 explicit_base, force_binary)
211
210
 
212
211
            last_rev_id = base_id
213
212
            last_rev_tree = base_tree
214
213
 
215
214
    def _testament_sha1(self, revision_id):
216
 
        return StrictTestament.from_revision(self.source,
 
215
        return StrictTestament.from_revision(self.source, 
217
216
                                             revision_id).as_sha1()
218
217
 
219
 
    def _write_revision(self, rev, rev_tree, base_rev, base_tree,
 
218
    def _write_revision(self, rev, rev_tree, base_rev, base_tree, 
220
219
                        explicit_base, force_binary):
221
220
        """Write out the information for a revision."""
222
221
        def w(key, value):
241
240
            for name, value in sorted(rev.properties.items()):
242
241
                self._write(name, value, indent=3,
243
242
                            trailing_space_when_empty=True)
244
 
 
 
243
        
245
244
        # Add an extra blank space at the end
246
245
        self.to_file.write('\n')
247
246
 
254
253
        self.to_file.write(' // '.join(p_texts).encode('utf-8'))
255
254
        self.to_file.write('\n')
256
255
 
257
 
    def _write_delta(self, new_tree, old_tree, default_revision_id,
 
256
    def _write_delta(self, new_tree, old_tree, default_revision_id, 
258
257
                     force_binary):
259
258
        """Write out the changes between the trees."""
260
259
        DEVNULL = '/dev/null'
263
262
 
264
263
        def do_diff(file_id, old_path, new_path, action, force_binary):
265
264
            def tree_lines(tree, require_text=False):
266
 
                if tree.has_id(file_id):
 
265
                if file_id in tree:
267
266
                    tree_file = tree.get_file(file_id)
268
267
                    if require_text is True:
269
268
                        tree_file = text_file(tree_file)
277
276
                old_lines = tree_lines(old_tree, require_text=True)
278
277
                new_lines = tree_lines(new_tree, require_text=True)
279
278
                action.write(self.to_file)
280
 
                internal_diff(old_path, old_lines, new_path, new_lines,
 
279
                internal_diff(old_path, old_lines, new_path, new_lines, 
281
280
                              self.to_file)
282
281
            except errors.BinaryFile:
283
282
                old_lines = tree_lines(old_tree, require_text=False)
284
283
                new_lines = tree_lines(new_tree, require_text=False)
285
284
                action.add_property('encoding', 'base64')
286
285
                action.write(self.to_file)
287
 
                binary_diff(old_path, old_lines, new_path, new_lines,
 
286
                binary_diff(old_path, old_lines, new_path, new_lines, 
288
287
                            self.to_file)
289
288
 
290
289
        def finish_action(action, file_id, kind, meta_modified, text_modified,
308
307
 
309
308
        for path, file_id, kind in delta.added:
310
309
            action = Action('added', [kind, path], [('file-id', file_id)])
311
 
            meta_modified = (kind=='file' and
 
310
            meta_modified = (kind=='file' and 
312
311
                             new_tree.is_executable(file_id))
313
312
            finish_action(action, file_id, kind, meta_modified, True,
314
313
                          DEVNULL, path)
332
331
                continue
333
332
            old_rev = getattr(old_tree.inventory[ie.file_id], 'revision', None)
334
333
            if new_rev != old_rev:
335
 
                action = Action('modified', [ie.kind,
 
334
                action = Action('modified', [ie.kind, 
336
335
                                             new_tree.id2path(ie.file_id)])
337
336
                action.add_utf8_property('last-changed', ie.revision)
338
337
                action.write(self.to_file)
350
349
        object.__init__(self)
351
350
        self.from_file = iter(from_file)
352
351
        self._next_line = None
353
 
 
 
352
        
354
353
        self.info = self._get_info()
355
354
        # We put the actual inventory ids in the footer, so that the patch
356
355
        # is easier to read for humans.
461
460
        else:
462
461
            # What do we do with a key we don't recognize
463
462
            raise errors.MalformedHeader('Unknown Key: "%s"' % key)
464
 
 
 
463
    
465
464
    def _read_many(self, indent):
466
465
        """If a line ends with no entry, that means that it should be
467
466
        followed with multiple lines of values.
504
503
            elif line.startswith('... '):
505
504
                action += line[len('... '):-1].decode('utf-8')
506
505
 
507
 
            if (self._next_line is not None and
 
506
            if (self._next_line is not None and 
508
507
                self._next_line.startswith('===')):
509
508
                return action, lines, True
510
509
            elif self._next_line is None or self._next_line.startswith('#'):
516
515
                lines.append(line)
517
516
 
518
517
        return action, lines, False
519
 
 
 
518
            
520
519
    def _read_patches(self):
521
520
        do_continue = True
522
521
        revision_actions = []
524
523
            action, lines, do_continue = self._read_one_patch()
525
524
            if action is not None:
526
525
                revision_actions.append((action, lines))
527
 
        if self.info.revisions[-1].tree_actions is not None:
528
 
            raise AssertionError()
 
526
        assert self.info.revisions[-1].tree_actions is None
529
527
        self.info.revisions[-1].tree_actions = revision_actions
530
528
 
531
529
    def _read_footer(self):
553
551
        testament = StrictTestament.from_revision(repository, revision_id)
554
552
        return testament.as_sha1()
555
553
 
556
 
    def _testament_sha1(self, revision, tree):
557
 
        return StrictTestament(revision, tree).as_sha1()
 
554
    def _testament_sha1(self, revision, inventory):
 
555
        return StrictTestament(revision, inventory).as_sha1()