~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-12-11 07:57:53 UTC
  • mfrom: (0.16.119 ls-shelf)
  • Revision ID: pqm@pqm.ubuntu.com-20081211075753-m1ktaz1at8oxlp00
Add --list option to shelve (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
228
228
        self.transform = transform
229
229
        self.message = message
230
230
 
 
231
    @staticmethod
 
232
    def iter_records(shelf_file):
 
233
        parser = pack.ContainerPushParser()
 
234
        parser.accept_bytes(shelf_file.read())
 
235
        return iter(parser.read_pending_records())
 
236
 
 
237
    @staticmethod
 
238
    def parse_metadata(records):
 
239
        names, metadata_bytes = records.next()
 
240
        if names[0] != ('metadata',):
 
241
            raise errors.ShelfCorrupt
 
242
        metadata = bencode.bdecode(metadata_bytes)
 
243
        message = metadata.get('message')
 
244
        if message is not None:
 
245
            metadata['message'] = message.decode('utf-8')
 
246
        return metadata
 
247
 
231
248
    @classmethod
232
249
    def from_tree_and_shelf(klass, tree, shelf_file):
233
250
        """Create an Unshelver from a tree and a shelf file.
236
253
        :param shelf_file: A file-like object containing shelved changes.
237
254
        :return: The Unshelver.
238
255
        """
239
 
        parser = pack.ContainerPushParser()
240
 
        parser.accept_bytes(shelf_file.read())
241
 
        records = iter(parser.read_pending_records())
242
 
        names, metadata_bytes = records.next()
243
 
        if names[0] != ('metadata',):
244
 
            raise errors.ShelfCorrupt
245
 
        metadata = bencode.bdecode(metadata_bytes)
 
256
        records = klass.iter_records(shelf_file)
 
257
        metadata = klass.parse_metadata(records)
246
258
        base_revision_id = metadata['revision_id']
247
 
        message = metadata.get('message')
248
 
        if message is not None:
249
 
            message = message.decode('utf-8')
250
259
        try:
251
260
            base_tree = tree.revision_tree(base_revision_id)
252
261
        except errors.NoSuchRevisionInTree:
253
262
            base_tree = tree.branch.repository.revision_tree(base_revision_id)
254
263
        tt = transform.TransformPreview(base_tree)
255
264
        tt.deserialize(records)
256
 
        return klass(tree, base_tree, tt, message)
 
265
        return klass(tree, base_tree, tt, metadata.get('message'))
 
266
 
257
267
 
258
268
    def make_merger(self):
259
269
        """Return a merger that can unshelve the changes."""
338
348
        finally:
339
349
            shelf_file.close()
340
350
 
 
351
    def get_metadata(self, shelf_id):
 
352
        """Return the metadata associated with a given shelf_id."""
 
353
        shelf_file = self.read_shelf(shelf_id)
 
354
        try:
 
355
            records = Unshelver.iter_records(shelf_file)
 
356
        finally:
 
357
            shelf_file.close()
 
358
        return Unshelver.parse_metadata(records)
 
359
 
341
360
    def delete_shelf(self, shelf_id):
342
361
        """Delete the shelved changes for a given id.
343
362