~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Martin Packman
  • Date: 2012-02-01 13:24:42 UTC
  • mto: (6437.23.4 2.5)
  • mto: This revision was merged to the branch mainline in revision 6462.
  • Revision ID: martin.packman@canonical.com-20120201132442-ela7jc4mxv4b058o
Treat path for .bzr.log as unicode

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
            raise ValueError('Unknown change kind: "%s"' % change[0])
126
126
 
127
127
    def shelve_all(self):
128
 
        """Shelve all changes.
129
 
 
130
 
        :return: True if changes were shelved, False if there were no changes.
131
 
        """
132
 
        change = None
 
128
        """Shelve all changes."""
133
129
        for change in self.iter_shelvable():
134
130
            self.shelve_change(change)
135
 
        return change is not None
136
131
 
137
132
    def shelve_rename(self, file_id):
138
133
        """Shelve a file rename.
260
255
        """Shelve changes from working tree."""
261
256
        self.work_transform.apply()
262
257
 
263
 
    @staticmethod
264
 
    def metadata_record(serializer, revision_id, message=None):
265
 
        metadata = {'revision_id': revision_id}
266
 
        if message is not None:
267
 
            metadata['message'] = message.encode('utf-8')
268
 
        return serializer.bytes_record(
269
 
            bencode.bencode(metadata), (('metadata',),))
270
 
 
271
258
    def write_shelf(self, shelf_file, message=None):
272
259
        """Serialize the shelved changes to a file.
273
260
 
276
263
        :return: the filename of the written file.
277
264
        """
278
265
        transform.resolve_conflicts(self.shelf_transform)
279
 
        revision_id = self.target_tree.get_revision_id()
280
 
        return self._write_shelf(shelf_file, self.shelf_transform, revision_id,
281
 
                                 message)
282
 
 
283
 
    @classmethod
284
 
    def _write_shelf(cls, shelf_file, transform, revision_id, message=None):
285
266
        serializer = pack.ContainerSerialiser()
286
267
        shelf_file.write(serializer.begin())
287
 
        metadata = cls.metadata_record(serializer, revision_id, message)
288
 
        shelf_file.write(metadata)
289
 
        for bytes in transform.serialize(serializer):
 
268
        metadata = {
 
269
            'revision_id': self.target_tree.get_revision_id(),
 
270
        }
 
271
        if message is not None:
 
272
            metadata['message'] = message.encode('utf-8')
 
273
        shelf_file.write(serializer.bytes_record(
 
274
            bencode.bencode(metadata), (('metadata',),)))
 
275
        for bytes in self.shelf_transform.serialize(serializer):
290
276
            shelf_file.write(bytes)
291
277
        shelf_file.write(serializer.end())
292
278