~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by 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
22
22
from bzrlib import errors
23
23
from bzrlib.bundle.serializer import (BundleSerializer,
24
24
                                      BUNDLE_HEADER,
25
 
                                      format_highres_date,
26
 
                                      unpack_highres_date,
27
25
                                     )
28
26
from bzrlib.bundle.serializer import binary_diff
29
27
from bzrlib.bundle.bundle_data import (RevisionInfo, BundleInfo, BundleTree)
31
29
from bzrlib.osutils import pathjoin
32
30
from bzrlib.progress import DummyProgress
33
31
from bzrlib.revision import NULL_REVISION
34
 
from bzrlib.rio import RioWriter, read_stanzas
35
32
import bzrlib.ui
36
33
from bzrlib.testament import StrictTestament
 
34
from bzrlib.timestamp import (
 
35
    format_highres_date,
 
36
    unpack_highres_date,
 
37
)
37
38
from bzrlib.textfile import text_file
38
39
from bzrlib.trace import mutter
39
40
 
54
55
        else:
55
56
            self.properties = properties
56
57
 
 
58
    def add_utf8_property(self, name, value):
 
59
        """Add a property whose value is currently utf8 to the action."""
 
60
        self.properties.append((name, value.decode('utf8')))
 
61
 
57
62
    def add_property(self, name, value):
58
63
        """Add a property to the action"""
59
64
        self.properties.append((name, value))
96
101
 
97
102
    def check_compatible(self):
98
103
        if self.source.supports_rich_root():
99
 
            raise errors.IncompatibleFormat('0.8', repr(self.source))
 
104
            raise errors.IncompatibleBundleFormat('0.8', repr(self.source))
100
105
 
101
106
    def write(self, source, revision_ids, forced_bases, f):
102
107
        """Write the bundless to the supplied files.
130
135
        f.write('0.8\n')
131
136
        f.write('#\n')
132
137
 
133
 
    def _write(self, key, value, indent=1):
134
 
        """Write out meta information, with proper indenting, etc"""
 
138
    def _write(self, key, value, indent=1, trailing_space_when_empty=False):
 
139
        """Write out meta information, with proper indenting, etc.
 
140
 
 
141
        :param trailing_space_when_empty: To work around a bug in earlier
 
142
            bundle readers, when writing an empty property, we use "prop: \n"
 
143
            rather than writing "prop:\n".
 
144
            If this parameter is True, and value is the empty string, we will
 
145
            write an extra space.
 
146
        """
135
147
        assert indent > 0, 'indentation must be greater than 0'
136
148
        f = self.to_file
137
149
        f.write('#' + (' ' * indent))
138
150
        f.write(key.encode('utf-8'))
139
151
        if not value:
140
 
            f.write(':\n')
141
 
        elif isinstance(value, basestring):
 
152
            if trailing_space_when_empty and value == '':
 
153
                f.write(': \n')
 
154
            else:
 
155
                f.write(':\n')
 
156
        elif isinstance(value, str):
 
157
            f.write(': ')
 
158
            f.write(value)
 
159
            f.write('\n')
 
160
        elif isinstance(value, unicode):
142
161
            f.write(': ')
143
162
            f.write(value.encode('utf-8'))
144
163
            f.write('\n')
146
165
            f.write(':\n')
147
166
            for entry in value:
148
167
                f.write('#' + (' ' * (indent+2)))
149
 
                f.write(entry.encode('utf-8'))
 
168
                if isinstance(entry, str):
 
169
                    f.write(entry)
 
170
                else:
 
171
                    f.write(entry.encode('utf-8'))
150
172
                f.write('\n')
151
173
 
152
174
    def _write_revisions(self, pb):
156
178
        last_rev_id = None
157
179
        last_rev_tree = None
158
180
 
159
 
        i_max = len(self.revision_ids) 
 
181
        i_max = len(self.revision_ids)
160
182
        for i, rev_id in enumerate(self.revision_ids):
161
183
            pb.update("Generating revsion data", i, i_max)
162
184
            rev = self.source.get_revision(rev_id)
213
235
            w('base id', base_rev)
214
236
        if rev.properties:
215
237
            self._write('properties', None, indent=1)
216
 
            for name, value in rev.properties.items():
217
 
                self._write(name, value, indent=3)
 
238
            for name, value in sorted(rev.properties.items()):
 
239
                self._write(name, value, indent=3,
 
240
                            trailing_space_when_empty=True)
218
241
        
219
242
        # Add an extra blank space at the end
220
243
        self.to_file.write('\n')
265
288
                          old_path, new_path):
266
289
            entry = new_tree.inventory[file_id]
267
290
            if entry.revision != default_revision_id:
268
 
                action.add_property('last-changed', entry.revision)
 
291
                action.add_utf8_property('last-changed', entry.revision)
269
292
            if meta_modified:
270
293
                action.add_bool_property('executable', entry.executable)
271
294
            if text_modified and kind == "symlink":
308
331
            if new_rev != old_rev:
309
332
                action = Action('modified', [ie.kind, 
310
333
                                             new_tree.id2path(ie.file_id)])
311
 
                action.add_property('last-changed', ie.revision)
 
334
                action.add_utf8_property('last-changed', ie.revision)
312
335
                action.write(self.to_file)
313
336
 
314
337
 
425
448
        revision_info = self.info.revisions[-1]
426
449
        if key in revision_info.__dict__:
427
450
            if getattr(revision_info, key) is None:
 
451
                if key in ('file_id', 'revision_id', 'base_id'):
 
452
                    value = value.encode('utf8')
 
453
                elif key in ('parent_ids'):
 
454
                    value = [v.encode('utf8') for v in value]
428
455
                setattr(revision_info, key, value)
429
456
            else:
430
457
                raise errors.MalformedHeader('Duplicated Key: %s' % key)
512
539
                self._next().next()
513
540
                break
514
541
 
515
 
 
516
542
class BundleInfo08(BundleInfo):
517
543
 
518
544
    def _update_tree(self, bundle_tree, revision_id):