~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-08-06 02:31:39 UTC
  • mfrom: (2665.1.2 stricter-run_bzr)
  • Revision ID: pqm@pqm.ubuntu.com-20070806023139-97nrt9mu4qihcdf3
(robertc) Merge Michael Hudson's run_bzr keyword usage fix. (Michael Hudson)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib import errors
23
23
from bzrlib.bundle.serializer import (BundleSerializer,
24
 
                                      BUNDLE_HEADER,
25
 
                                      format_highres_date,
26
 
                                      unpack_highres_date,
 
24
                                      _get_bundle_header,
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))
123
128
        finally:
124
129
            source.unlock()
125
130
 
 
131
    def write_bundle(self, repository, target, base, fileobj):
 
132
        return self._write_bundle(repository, target, base, fileobj)
 
133
 
126
134
    def _write_main_header(self):
127
135
        """Write the header for the changes"""
128
136
        f = self.to_file
129
 
        f.write(BUNDLE_HEADER)
130
 
        f.write('0.8\n')
 
137
        f.write(_get_bundle_header('0.8'))
131
138
        f.write('#\n')
132
139
 
133
 
    def _write(self, key, value, indent=1):
134
 
        """Write out meta information, with proper indenting, etc"""
 
140
    def _write(self, key, value, indent=1, trailing_space_when_empty=False):
 
141
        """Write out meta information, with proper indenting, etc.
 
142
 
 
143
        :param trailing_space_when_empty: To work around a bug in earlier
 
144
            bundle readers, when writing an empty property, we use "prop: \n"
 
145
            rather than writing "prop:\n".
 
146
            If this parameter is True, and value is the empty string, we will
 
147
            write an extra space.
 
148
        """
135
149
        assert indent > 0, 'indentation must be greater than 0'
136
150
        f = self.to_file
137
151
        f.write('#' + (' ' * indent))
138
152
        f.write(key.encode('utf-8'))
139
153
        if not value:
140
 
            f.write(':\n')
141
 
        elif isinstance(value, basestring):
 
154
            if trailing_space_when_empty and value == '':
 
155
                f.write(': \n')
 
156
            else:
 
157
                f.write(':\n')
 
158
        elif isinstance(value, str):
 
159
            f.write(': ')
 
160
            f.write(value)
 
161
            f.write('\n')
 
162
        elif isinstance(value, unicode):
142
163
            f.write(': ')
143
164
            f.write(value.encode('utf-8'))
144
165
            f.write('\n')
146
167
            f.write(':\n')
147
168
            for entry in value:
148
169
                f.write('#' + (' ' * (indent+2)))
149
 
                f.write(entry.encode('utf-8'))
 
170
                if isinstance(entry, str):
 
171
                    f.write(entry)
 
172
                else:
 
173
                    f.write(entry.encode('utf-8'))
150
174
                f.write('\n')
151
175
 
152
176
    def _write_revisions(self, pb):
156
180
        last_rev_id = None
157
181
        last_rev_tree = None
158
182
 
159
 
        i_max = len(self.revision_ids) 
 
183
        i_max = len(self.revision_ids)
160
184
        for i, rev_id in enumerate(self.revision_ids):
161
185
            pb.update("Generating revsion data", i, i_max)
162
186
            rev = self.source.get_revision(rev_id)
213
237
            w('base id', base_rev)
214
238
        if rev.properties:
215
239
            self._write('properties', None, indent=1)
216
 
            for name, value in rev.properties.items():
217
 
                self._write(name, value, indent=3)
 
240
            for name, value in sorted(rev.properties.items()):
 
241
                self._write(name, value, indent=3,
 
242
                            trailing_space_when_empty=True)
218
243
        
219
244
        # Add an extra blank space at the end
220
245
        self.to_file.write('\n')
265
290
                          old_path, new_path):
266
291
            entry = new_tree.inventory[file_id]
267
292
            if entry.revision != default_revision_id:
268
 
                action.add_property('last-changed', entry.revision)
 
293
                action.add_utf8_property('last-changed', entry.revision)
269
294
            if meta_modified:
270
295
                action.add_bool_property('executable', entry.executable)
271
296
            if text_modified and kind == "symlink":
308
333
            if new_rev != old_rev:
309
334
                action = Action('modified', [ie.kind, 
310
335
                                             new_tree.id2path(ie.file_id)])
311
 
                action.add_property('last-changed', ie.revision)
 
336
                action.add_utf8_property('last-changed', ie.revision)
312
337
                action.write(self.to_file)
313
338
 
314
339
 
425
450
        revision_info = self.info.revisions[-1]
426
451
        if key in revision_info.__dict__:
427
452
            if getattr(revision_info, key) is None:
 
453
                if key in ('file_id', 'revision_id', 'base_id'):
 
454
                    value = value.encode('utf8')
 
455
                elif key in ('parent_ids'):
 
456
                    value = [v.encode('utf8') for v in value]
428
457
                setattr(revision_info, key, value)
429
458
            else:
430
459
                raise errors.MalformedHeader('Duplicated Key: %s' % key)
512
541
                self._next().next()
513
542
                break
514
543
 
515
 
 
516
544
class BundleInfo08(BundleInfo):
517
545
 
518
546
    def _update_tree(self, bundle_tree, revision_id):