~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 15:06:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110420150617-i41caxgemg32tq1r
Start adding tests that _worth_saving_limit works as expected.

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
18
17
 
19
18
import errno
20
19
import re
66
65
        """Iterable of tuples describing shelvable changes.
67
66
 
68
67
        As well as generating the tuples, this updates several members.
69
 
        Tuples may be::
70
 
 
 
68
        Tuples may be:
71
69
           ('add file', file_id, work_kind, work_path)
72
70
           ('delete file', file_id, target_kind, target_path)
73
71
           ('rename', file_id, target_path, work_path)
83
81
            # when a tree root was deleted / renamed.
84
82
            if kind[0] is None and names[1] == '':
85
83
                continue
86
 
            # Also don't shelve deletion of tree root.
87
 
            if kind[1] is None and names[0] == '':
88
 
                continue
89
84
            if kind[0] is None or versioned[0] == False:
90
85
                self.creation[file_id] = (kind[1], names[1], parents[1],
91
86
                                          versioned)
125
120
            raise ValueError('Unknown change kind: "%s"' % change[0])
126
121
 
127
122
    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
 
123
        """Shelve all changes."""
133
124
        for change in self.iter_shelvable():
134
125
            self.shelve_change(change)
135
 
        return change is not None
136
126
 
137
127
    def shelve_rename(self, file_id):
138
128
        """Shelve a file rename.
260
250
        """Shelve changes from working tree."""
261
251
        self.work_transform.apply()
262
252
 
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
253
    def write_shelf(self, shelf_file, message=None):
272
254
        """Serialize the shelved changes to a file.
273
255
 
276
258
        :return: the filename of the written file.
277
259
        """
278
260
        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
261
        serializer = pack.ContainerSerialiser()
286
262
        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):
 
263
        metadata = {
 
264
            'revision_id': self.target_tree.get_revision_id(),
 
265
        }
 
266
        if message is not None:
 
267
            metadata['message'] = message.encode('utf-8')
 
268
        shelf_file.write(serializer.bytes_record(
 
269
            bencode.bencode(metadata), (('metadata',),)))
 
270
        for bytes in self.shelf_transform.serialize(serializer):
290
271
            shelf_file.write(bytes)
291
272
        shelf_file.write(serializer.end())
292
273