~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Haw Loeung (hloeung)
  • Date: 2012-07-24 12:53:36 UTC
  • mfrom: (6541 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6542.
  • Revision ID: haw.loeung@canonical.com-20120724125336-r3wzxm02lyec7jm6
[hloeung] Merged with upstream resolving conflicts.

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."""
 
128
        """Shelve all changes.
 
129
 
 
130
        :return: True if changes were shelved, False if there were no changes.
 
131
        """
 
132
        change = None
129
133
        for change in self.iter_shelvable():
130
134
            self.shelve_change(change)
 
135
        return change is not None
131
136
 
132
137
    def shelve_rename(self, file_id):
133
138
        """Shelve a file rename.
255
260
        """Shelve changes from working tree."""
256
261
        self.work_transform.apply()
257
262
 
 
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
 
258
271
    def write_shelf(self, shelf_file, message=None):
259
272
        """Serialize the shelved changes to a file.
260
273
 
263
276
        :return: the filename of the written file.
264
277
        """
265
278
        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):
266
285
        serializer = pack.ContainerSerialiser()
267
286
        shelf_file.write(serializer.begin())
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):
 
287
        metadata = cls.metadata_record(serializer, revision_id, message)
 
288
        shelf_file.write(metadata)
 
289
        for bytes in transform.serialize(serializer):
276
290
            shelf_file.write(bytes)
277
291
        shelf_file.write(serializer.end())
278
292