~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/shelf.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-06 20:42:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4088.
  • Revision ID: john@arbash-meinel.com-20090306204240-mzjavv31z3gu1x7i
Fix a small bug in setup.py when an extension fails to build

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
import errno
19
19
import re
20
20
 
21
21
from bzrlib import (
22
 
    bencode,
23
22
    errors,
24
23
    merge,
25
24
    merge3,
29
28
    ui,
30
29
    workingtree,
31
30
)
 
31
from bzrlib.util import bencode
32
32
 
33
33
 
34
34
class ShelfCreator(object):
37
37
    def __init__(self, work_tree, target_tree, file_list=None):
38
38
        """Constructor.
39
39
 
40
 
        :param work_tree: The working tree to apply changes to. This is not
41
 
            required to be locked - a tree_write lock will be taken out.
 
40
        :param work_tree: The working tree to apply changes to
42
41
        :param target_tree: The tree to make the working tree more similar to.
43
 
            This is not required to be locked - a read_lock will be taken out.
44
42
        :param file_list: The files to make more similar to the target.
45
43
        """
46
44
        self.work_tree = work_tree
47
45
        self.work_transform = transform.TreeTransform(work_tree)
48
 
        try:
49
 
            self.target_tree = target_tree
50
 
            self.shelf_transform = transform.TransformPreview(self.target_tree)
51
 
            try:
52
 
                self.renames = {}
53
 
                self.creation = {}
54
 
                self.deletion = {}
55
 
                self.iter_changes = work_tree.iter_changes(
56
 
                    self.target_tree, specific_files=file_list)
57
 
            except:
58
 
                self.shelf_transform.finalize()
59
 
                raise
60
 
        except:
61
 
            self.work_transform.finalize()
62
 
            raise
 
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)
63
53
 
64
54
    def iter_shelvable(self):
65
55
        """Iterable of tuples describing shelvable changes.
71
61
           ('rename', file_id, target_path, work_path)
72
62
           ('change kind', file_id, target_kind, work_kind, target_path)
73
63
           ('modify text', file_id)
74
 
           ('modify target', file_id, target_target, work_target)
75
64
        """
76
65
        for (file_id, paths, changed, versioned, parents, names, kind,
77
66
             executable) in self.iter_changes:
78
 
            # don't shelve add of tree root.  Working tree should never
79
 
            # lack roots, and bzr misbehaves when they do.
80
 
            # FIXME ADHB (2009-08-09): should still shelve adds of tree roots
81
 
            # when a tree root was deleted / renamed.
82
 
            if kind[0] is None and names[1] == '':
83
 
                continue
84
67
            if kind[0] is None or versioned[0] == False:
85
68
                self.creation[file_id] = (kind[1], names[1], parents[1],
86
69
                                          versioned)
96
79
 
97
80
                if kind[0] != kind [1]:
98
81
                    yield ('change kind', file_id, kind[0], kind[1], paths[0])
99
 
                elif kind[0] == 'symlink':
100
 
                    t_target = self.target_tree.get_symlink_target(file_id)
101
 
                    w_target = self.work_tree.get_symlink_target(file_id)
102
 
                    yield ('modify target', file_id, paths[0], t_target,
103
 
                            w_target)
104
82
                elif changed:
105
83
                    yield ('modify text', file_id)
106
84
 
107
 
    def shelve_change(self, change):
108
 
        """Shelve a change in the iter_shelvable format."""
109
 
        if change[0] == 'rename':
110
 
            self.shelve_rename(change[1])
111
 
        elif change[0] == 'delete file':
112
 
            self.shelve_deletion(change[1])
113
 
        elif change[0] == 'add file':
114
 
            self.shelve_creation(change[1])
115
 
        elif change[0] in ('change kind', 'modify text'):
116
 
            self.shelve_content_change(change[1])
117
 
        elif change[0] == 'modify target':
118
 
            self.shelve_modify_target(change[1])
119
 
        else:
120
 
            raise ValueError('Unknown change kind: "%s"' % change[0])
121
 
 
122
 
    def shelve_all(self):
123
 
        """Shelve all changes."""
124
 
        for change in self.iter_shelvable():
125
 
            self.shelve_change(change)
126
 
 
127
85
    def shelve_rename(self, file_id):
128
86
        """Shelve a file rename.
129
87
 
138
96
        shelf_parent = self.shelf_transform.trans_id_file_id(parents[1])
139
97
        self.shelf_transform.adjust_path(names[1], shelf_parent, s_trans_id)
140
98
 
141
 
    def shelve_modify_target(self, file_id):
142
 
        """Shelve a change of symlink target.
143
 
 
144
 
        :param file_id: The file id of the symlink which changed target.
145
 
        :param new_target: The target that the symlink should have due
146
 
            to shelving.
147
 
        """
148
 
        new_target = self.target_tree.get_symlink_target(file_id)
149
 
        w_trans_id = self.work_transform.trans_id_file_id(file_id)
150
 
        self.work_transform.delete_contents(w_trans_id)
151
 
        self.work_transform.create_symlink(new_target, w_trans_id)
152
 
 
153
 
        old_target = self.work_tree.get_symlink_target(file_id)
154
 
        s_trans_id = self.shelf_transform.trans_id_file_id(file_id)
155
 
        self.shelf_transform.delete_contents(s_trans_id)
156
 
        self.shelf_transform.create_symlink(old_target, s_trans_id)
157
 
 
158
99
    def shelve_lines(self, file_id, new_lines):
159
100
        """Shelve text changes to a file, using provided lines.
160
101
 
323
264
        tt.deserialize(records)
324
265
        return klass(tree, base_tree, tt, metadata.get('message'))
325
266
 
326
 
    def make_merger(self, task=None):
 
267
    def make_merger(self):
327
268
        """Return a merger that can unshelve the changes."""
328
 
        target_tree = self.transform.get_preview_tree()
329
 
        merger = merge.Merger.from_uncommitted(self.tree, target_tree,
330
 
            task, self.base_tree)
331
 
        merger.merge_type = merge.Merge3Merger
332
 
        return merger
 
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()
333
278
 
334
279
    def finalize(self):
335
280
        """Release all resources held by this Unshelver."""