~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-27 05:35:00 UTC
  • mfrom: (4570 +trunk)
  • mto: (4634.6.29 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090727053500-q76zsn2dx33jhmj5
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
18
import errno
19
19
import re
20
20
 
21
21
from bzrlib import (
 
22
    bencode,
22
23
    errors,
23
24
    merge,
24
25
    merge3,
28
29
    ui,
29
30
    workingtree,
30
31
)
31
 
from bzrlib.util import bencode
32
32
 
33
33
 
34
34
class ShelfCreator(object):
43
43
        """
44
44
        self.work_tree = work_tree
45
45
        self.work_transform = transform.TreeTransform(work_tree)
46
 
        self.target_tree = target_tree
47
 
        self.shelf_transform = transform.TransformPreview(self.target_tree)
48
 
        self.renames = {}
49
 
        self.creation = {}
50
 
        self.deletion = {}
51
 
        self.iter_changes = work_tree.iter_changes(self.target_tree,
52
 
                                                   specific_files=file_list)
 
46
        try:
 
47
            self.target_tree = target_tree
 
48
            self.shelf_transform = transform.TransformPreview(self.target_tree)
 
49
            try:
 
50
                self.renames = {}
 
51
                self.creation = {}
 
52
                self.deletion = {}
 
53
                self.iter_changes = work_tree.iter_changes(
 
54
                    self.target_tree, specific_files=file_list)
 
55
            except:
 
56
                self.shelf_transform.finalize()
 
57
                raise
 
58
        except:
 
59
            self.work_transform.finalize()
 
60
            raise
53
61
 
54
62
    def iter_shelvable(self):
55
63
        """Iterable of tuples describing shelvable changes.
61
69
           ('rename', file_id, target_path, work_path)
62
70
           ('change kind', file_id, target_kind, work_kind, target_path)
63
71
           ('modify text', file_id)
 
72
           ('modify target', file_id, target_target, work_target)
64
73
        """
65
74
        for (file_id, paths, changed, versioned, parents, names, kind,
66
75
             executable) in self.iter_changes:
79
88
 
80
89
                if kind[0] != kind [1]:
81
90
                    yield ('change kind', file_id, kind[0], kind[1], paths[0])
 
91
                elif kind[0] == 'symlink':
 
92
                    t_target = self.target_tree.get_symlink_target(file_id)
 
93
                    w_target = self.work_tree.get_symlink_target(file_id)
 
94
                    yield ('modify target', file_id, paths[0], t_target,
 
95
                            w_target)
82
96
                elif changed:
83
97
                    yield ('modify text', file_id)
84
98
 
 
99
    def shelve_change(self, change):
 
100
        """Shelve a change in the iter_shelvable format."""
 
101
        if change[0] == 'rename':
 
102
            self.shelve_rename(change[1])
 
103
        elif change[0] == 'delete file':
 
104
            self.shelve_deletion(change[1])
 
105
        elif change[0] == 'add file':
 
106
            self.shelve_creation(change[1])
 
107
        elif change[0] == 'change kind':
 
108
            self.shelve_content_change(change[1])
 
109
        elif change[0] == 'modify target':
 
110
            self.shelve_modify_target(change[1])
 
111
        else:
 
112
            raise ValueError('Unknown change kind: "%s"' % change[0])
 
113
 
85
114
    def shelve_rename(self, file_id):
86
115
        """Shelve a file rename.
87
116
 
96
125
        shelf_parent = self.shelf_transform.trans_id_file_id(parents[1])
97
126
        self.shelf_transform.adjust_path(names[1], shelf_parent, s_trans_id)
98
127
 
 
128
    def shelve_modify_target(self, file_id):
 
129
        """Shelve a change of symlink target.
 
130
 
 
131
        :param file_id: The file id of the symlink which changed target.
 
132
        :param new_target: The target that the symlink should have due
 
133
            to shelving.
 
134
        """
 
135
        new_target = self.target_tree.get_symlink_target(file_id)
 
136
        w_trans_id = self.work_transform.trans_id_file_id(file_id)
 
137
        self.work_transform.delete_contents(w_trans_id)
 
138
        self.work_transform.create_symlink(new_target, w_trans_id)
 
139
 
 
140
        old_target = self.work_tree.get_symlink_target(file_id)
 
141
        s_trans_id = self.shelf_transform.trans_id_file_id(file_id)
 
142
        self.shelf_transform.delete_contents(s_trans_id)
 
143
        self.shelf_transform.create_symlink(old_target, s_trans_id)
 
144
 
99
145
    def shelve_lines(self, file_id, new_lines):
100
146
        """Shelve text changes to a file, using provided lines.
101
147
 
264
310
        tt.deserialize(records)
265
311
        return klass(tree, base_tree, tt, metadata.get('message'))
266
312
 
267
 
    def make_merger(self):
 
313
    def make_merger(self, task=None):
268
314
        """Return a merger that can unshelve the changes."""
269
 
        pb = ui.ui_factory.nested_progress_bar()
270
 
        try:
271
 
            target_tree = self.transform.get_preview_tree()
272
 
            merger = merge.Merger.from_uncommitted(self.tree, target_tree, pb,
273
 
                                                   self.base_tree)
274
 
            merger.merge_type = merge.Merge3Merger
275
 
            return merger
276
 
        finally:
277
 
            pb.finished()
 
315
        target_tree = self.transform.get_preview_tree()
 
316
        merger = merge.Merger.from_uncommitted(self.tree, target_tree,
 
317
            task, self.base_tree)
 
318
        merger.merge_type = merge.Merge3Merger
 
319
        return merger
278
320
 
279
321
    def finalize(self):
280
322
        """Release all resources held by this Unshelver."""