~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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