~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/memorytree.py

merge only needs a lock_tree_write() on the working tree, not a full lock_write()

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
 
23
23
from copy import deepcopy
24
 
import os
25
24
 
26
 
from bzrlib import (
27
 
    errors,
28
 
    mutabletree,
29
 
    osutils,
30
 
    revision as _mod_revision,
31
 
    )
 
25
from bzrlib import errors, mutabletree
32
26
from bzrlib.decorators import needs_read_lock, needs_write_lock
33
27
from bzrlib.osutils import sha_file
34
28
from bzrlib.mutabletree import needs_tree_write_lock
69
63
    @staticmethod
70
64
    def create_on_branch(branch):
71
65
        """Create a MemoryTree for branch, using the last-revision of branch."""
72
 
        revision_id = _mod_revision.ensure_null(branch.last_revision())
73
 
        return MemoryTree(branch, revision_id)
 
66
        return MemoryTree(branch, branch.last_revision())
74
67
 
75
68
    def _gather_kinds(self, files, kinds):
76
69
        """See MutableTree._gather_kinds.
79
72
        missing files, so is a no-op.
80
73
        """
81
74
 
82
 
    def get_file(self, file_id, path=None):
 
75
    def get_file(self, file_id):
83
76
        """See Tree.get_file."""
84
 
        if path is None:
85
 
            path = self.id2path(file_id)
86
 
        return self._file_transport.get(path)
 
77
        return self._file_transport.get(self.id2path(file_id))
87
78
 
88
 
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
79
    def get_file_sha1(self, file_id, path=None):
89
80
        """See Tree.get_file_sha1()."""
90
81
        if path is None:
91
82
            path = self.id2path(file_id)
92
83
        stream = self._file_transport.get(path)
93
84
        return sha_file(stream)
94
85
 
95
 
    def get_root_id(self):
96
 
        return self.path2id('')
97
 
 
98
 
    def _comparison_data(self, entry, path):
99
 
        """See Tree._comparison_data."""
100
 
        if entry is None:
101
 
            return None, False, None
102
 
        return entry.kind, entry.executable, None
103
 
 
104
 
    @needs_tree_write_lock
105
 
    def rename_one(self, from_rel, to_rel):
106
 
        file_id = self.path2id(from_rel)
107
 
        to_dir, to_tail = os.path.split(to_rel)
108
 
        to_parent_id = self.path2id(to_dir)
109
 
        self._file_transport.move(from_rel, to_rel)
110
 
        self._inventory.rename(file_id, to_parent_id, to_tail)
111
 
 
112
 
    def path_content_summary(self, path):
113
 
        """See Tree.path_content_summary."""
114
 
        id = self.path2id(path)
115
 
        if id is None:
116
 
            return 'missing', None, None, None
117
 
        kind = self.kind(id)
118
 
        if kind == 'file':
119
 
            bytes = self._file_transport.get_bytes(path)
120
 
            size = len(bytes)
121
 
            executable = self._inventory[id].executable
122
 
            sha1 = None # no stat cache
123
 
            return (kind, size, executable, sha1)
124
 
        elif kind == 'directory':
125
 
            # memory tree does not support nested trees yet.
126
 
            return kind, None, None, None
127
 
        elif kind == 'symlink':
128
 
            raise NotImplementedError('symlink support')
129
 
        else:
130
 
            raise NotImplementedError('unknown kind')
131
 
 
132
 
    def _file_size(self, entry, stat_value):
133
 
        """See Tree._file_size."""
134
 
        if entry is None:
135
 
            return 0
136
 
        return entry.text_size
137
 
 
138
86
    @needs_read_lock
139
87
    def get_parent_ids(self):
140
88
        """See Tree.get_parent_ids.
151
99
    def is_executable(self, file_id, path=None):
152
100
        return self._inventory[file_id].executable
153
101
 
154
 
    def kind(self, file_id):
155
 
        return self._inventory[file_id].kind
156
 
 
157
102
    def mkdir(self, path, file_id=None):
158
103
        """See MutableTree.mkdir()."""
159
104
        self.add(path, file_id, 'directory')
214
159
        """Populate the in-tree state from the branch."""
215
160
        self._basis_tree = self.branch.repository.revision_tree(
216
161
            self._branch_revision_id)
217
 
        if self._branch_revision_id == _mod_revision.NULL_REVISION:
 
162
        if self._branch_revision_id is None:
218
163
            self._parent_ids = []
219
164
        else:
220
165
            self._parent_ids = [self._branch_revision_id]
274
219
            else:
275
220
                raise errors.NoSuchId(self, file_id)
276
221
 
277
 
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
278
 
        """See MutableTree.set_parent_trees()."""
279
 
        for revision_id in revision_ids:
280
 
            _mod_revision.check_not_reserved_id(revision_id)
281
 
        if len(revision_ids) == 0:
282
 
            self._parent_ids = []
283
 
            self._basis_tree = self.branch.repository.revision_tree(
284
 
                                    _mod_revision.NULL_REVISION)
285
 
        else:
286
 
            self._parent_ids = revision_ids
287
 
            self._basis_tree = self.branch.repository.revision_tree(
288
 
                                    revision_ids[0])
289
 
            self._branch_revision_id = revision_ids[0]
290
 
 
291
222
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
292
223
        """See MutableTree.set_parent_trees()."""
293
224
        if len(parents_list) == 0:
294
225
            self._parent_ids = []
295
 
            self._basis_tree = self.branch.repository.revision_tree(
296
 
                                   _mod_revision.NULL_REVISION)
 
226
            self._basis_tree = self.branch.repository.revisiontree(None)
297
227
        else:
298
228
            if parents_list[0][1] is None and not allow_leftmost_as_ghost:
299
229
                # a ghost in the left most parent
300
230
                raise errors.GhostRevisionUnusableHere(parents_list[0][0])
301
231
            self._parent_ids = [parent_id for parent_id, tree in parents_list]
302
 
            if parents_list[0][1] is None or parents_list[0][1] == 'null:':
303
 
                self._basis_tree = self.branch.repository.revision_tree(
304
 
                                       _mod_revision.NULL_REVISION)
 
232
            if parents_list[0][1] is None:
 
233
                self._basis_tree = self.branch.repository.revisiontree(None)
305
234
            else:
306
235
                self._basis_tree = parents_list[0][1]
307
236
            self._branch_revision_id = parents_list[0][0]