~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
17
18
 
18
19
import errno
19
20
import re
124
125
            raise ValueError('Unknown change kind: "%s"' % change[0])
125
126
 
126
127
    def shelve_all(self):
127
 
        """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
128
133
        for change in self.iter_shelvable():
129
134
            self.shelve_change(change)
 
135
        return change is not None
130
136
 
131
137
    def shelve_rename(self, file_id):
132
138
        """Shelve a file rename.
254
260
        """Shelve changes from working tree."""
255
261
        self.work_transform.apply()
256
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
 
257
271
    def write_shelf(self, shelf_file, message=None):
258
272
        """Serialize the shelved changes to a file.
259
273
 
262
276
        :return: the filename of the written file.
263
277
        """
264
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):
265
285
        serializer = pack.ContainerSerialiser()
266
286
        shelf_file.write(serializer.begin())
267
 
        metadata = {
268
 
            'revision_id': self.target_tree.get_revision_id(),
269
 
        }
270
 
        if message is not None:
271
 
            metadata['message'] = message.encode('utf-8')
272
 
        shelf_file.write(serializer.bytes_record(
273
 
            bencode.bencode(metadata), (('metadata',),)))
274
 
        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):
275
290
            shelf_file.write(bytes)
276
291
        shelf_file.write(serializer.end())
277
292