23
23
from copy import deepcopy
25
from bzrlib import errors, mutabletree
30
revision as _mod_revision,
26
32
from bzrlib.decorators import needs_read_lock, needs_write_lock
27
33
from bzrlib.osutils import sha_file
28
34
from bzrlib.mutabletree import needs_tree_write_lock
64
70
def create_on_branch(branch):
65
71
"""Create a MemoryTree for branch, using the last-revision of branch."""
66
return MemoryTree(branch, branch.last_revision())
72
revision_id = _mod_revision.ensure_null(branch.last_revision())
73
return MemoryTree(branch, revision_id)
68
75
def _gather_kinds(self, files, kinds):
69
76
"""See MutableTree._gather_kinds.
72
79
missing files, so is a no-op.
75
def get_file(self, file_id):
82
def get_file(self, file_id, path=None):
76
83
"""See Tree.get_file."""
77
return self._file_transport.get(self.id2path(file_id))
85
path = self.id2path(file_id)
86
return self._file_transport.get(path)
79
def get_file_sha1(self, file_id, path=None):
88
def get_file_sha1(self, file_id, path=None, stat_value=None):
80
89
"""See Tree.get_file_sha1()."""
82
91
path = self.id2path(file_id)
83
92
stream = self._file_transport.get(path)
84
93
return sha_file(stream)
95
def get_root_id(self):
96
return self.path2id('')
98
def _comparison_data(self, entry, path):
99
"""See Tree._comparison_data."""
101
return None, False, None
102
return entry.kind, entry.executable, None
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)
112
def path_content_summary(self, path):
113
"""See Tree.path_content_summary."""
114
id = self.path2id(path)
116
return 'missing', None, None, None
119
bytes = self._file_transport.get_bytes(path)
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')
130
raise NotImplementedError('unknown kind')
132
def _file_size(self, entry, stat_value):
133
"""See Tree._file_size."""
136
return entry.text_size
87
139
def get_parent_ids(self):
88
140
"""See Tree.get_parent_ids.
99
151
def is_executable(self, file_id, path=None):
100
152
return self._inventory[file_id].executable
154
def kind(self, file_id):
155
return self._inventory[file_id].kind
102
157
def mkdir(self, path, file_id=None):
103
158
"""See MutableTree.mkdir()."""
104
159
self.add(path, file_id, 'directory')
220
275
raise errors.NoSuchId(self, file_id)
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)
286
self._parent_ids = revision_ids
287
self._basis_tree = self.branch.repository.revision_tree(
289
self._branch_revision_id = revision_ids[0]
222
291
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
223
292
"""See MutableTree.set_parent_trees()."""
224
293
if len(parents_list) == 0:
225
294
self._parent_ids = []
226
self._basis_tree = self.branch.repository.revisiontree(None)
295
self._basis_tree = self.branch.repository.revision_tree(
296
_mod_revision.NULL_REVISION)
228
298
if parents_list[0][1] is None and not allow_leftmost_as_ghost:
229
299
# a ghost in the left most parent
230
300
raise errors.GhostRevisionUnusableHere(parents_list[0][0])
231
301
self._parent_ids = [parent_id for parent_id, tree in parents_list]
232
if parents_list[0][1] is None:
233
self._basis_tree = self.branch.repository.revisiontree(None)
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)
235
306
self._basis_tree = parents_list[0][1]
236
307
self._branch_revision_id = parents_list[0][0]