~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Vincent Ladeuil
  • Date: 2017-01-17 13:48:10 UTC
  • mfrom: (6615.3.6 merges)
  • mto: This revision was merged to the branch mainline in revision 6620.
  • Revision ID: v.ladeuil+lp@free.fr-20170117134810-j9p3lidfy6pfyfsc
Merge 2.7, resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
20
21
 
 
22
from bzrlib.lazy_import import lazy_import
 
23
lazy_import(globals(), """
21
24
from bzrlib import (
22
25
    bencode,
23
26
    errors,
26
29
    pack,
27
30
    transform,
28
31
)
 
32
""")
29
33
 
30
34
 
31
35
class ShelfCreator(object):
62
66
        """Iterable of tuples describing shelvable changes.
63
67
 
64
68
        As well as generating the tuples, this updates several members.
65
 
        Tuples may be:
 
69
        Tuples may be::
 
70
 
66
71
           ('add file', file_id, work_kind, work_path)
67
72
           ('delete file', file_id, target_kind, target_path)
68
73
           ('rename', file_id, target_path, work_path)
78
83
            # when a tree root was deleted / renamed.
79
84
            if kind[0] is None and names[1] == '':
80
85
                continue
 
86
            # Also don't shelve deletion of tree root.
 
87
            if kind[1] is None and names[0] == '':
 
88
                continue
81
89
            if kind[0] is None or versioned[0] == False:
82
90
                self.creation[file_id] = (kind[1], names[1], parents[1],
83
91
                                          versioned)
117
125
            raise ValueError('Unknown change kind: "%s"' % change[0])
118
126
 
119
127
    def shelve_all(self):
120
 
        """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
121
133
        for change in self.iter_shelvable():
122
134
            self.shelve_change(change)
 
135
        return change is not None
123
136
 
124
137
    def shelve_rename(self, file_id):
125
138
        """Shelve a file rename.
247
260
        """Shelve changes from working tree."""
248
261
        self.work_transform.apply()
249
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
 
250
271
    def write_shelf(self, shelf_file, message=None):
251
272
        """Serialize the shelved changes to a file.
252
273
 
255
276
        :return: the filename of the written file.
256
277
        """
257
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):
258
285
        serializer = pack.ContainerSerialiser()
259
286
        shelf_file.write(serializer.begin())
260
 
        metadata = {
261
 
            'revision_id': self.target_tree.get_revision_id(),
262
 
        }
263
 
        if message is not None:
264
 
            metadata['message'] = message.encode('utf-8')
265
 
        shelf_file.write(serializer.bytes_record(
266
 
            bencode.bencode(metadata), (('metadata',),)))
267
 
        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):
268
290
            shelf_file.write(bytes)
269
291
        shelf_file.write(serializer.end())
270
292