23
23
from copy import deepcopy
28
revision as _mod_revision,
25
from bzrlib import errors, mutabletree
30
26
from bzrlib.decorators import needs_read_lock, needs_write_lock
31
27
from bzrlib.osutils import sha_file
32
28
from bzrlib.mutabletree import needs_tree_write_lock
68
64
def create_on_branch(branch):
69
65
"""Create a MemoryTree for branch, using the last-revision of branch."""
70
revision_id = _mod_revision.ensure_null(branch.last_revision())
71
if _mod_revision.is_null(revision_id):
73
return MemoryTree(branch, revision_id)
66
return MemoryTree(branch, branch.last_revision())
75
68
def _gather_kinds(self, files, kinds):
76
69
"""See MutableTree._gather_kinds.
79
72
missing files, so is a no-op.
82
def get_file(self, file_id, path=None):
75
def get_file(self, file_id):
83
76
"""See Tree.get_file."""
85
path = self.id2path(file_id)
86
return self._file_transport.get(path)
77
return self._file_transport.get(self.id2path(file_id))
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()."""
91
82
path = self.id2path(file_id)
92
83
stream = self._file_transport.get(path)
93
84
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
def path_content_summary(self, path):
105
"""See Tree.path_content_summary."""
106
id = self.path2id(path)
108
return 'missing', None, None, None
111
bytes = self._file_transport.get_bytes(path)
113
executable = self._inventory[id].executable
114
sha1 = None # no stat cache
115
return (kind, size, executable, sha1)
116
elif kind == 'directory':
117
# memory tree does not support nested trees yet.
118
return kind, None, None, None
119
elif kind == 'symlink':
120
raise NotImplementedError('symlink support')
122
raise NotImplementedError('unknown kind')
124
def _file_size(self, entry, stat_value):
125
"""See Tree._file_size."""
128
return entry.text_size
131
87
def get_parent_ids(self):
132
88
"""See Tree.get_parent_ids.
269
225
def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
270
226
"""See MutableTree.set_parent_trees()."""
271
for revision_id in revision_ids:
272
_mod_revision.check_not_reserved_id(revision_id)
273
227
if len(revision_ids) == 0:
274
228
self._parent_ids = []
275
229
self._basis_tree = self.branch.repository.revision_tree(None)
289
243
# a ghost in the left most parent
290
244
raise errors.GhostRevisionUnusableHere(parents_list[0][0])
291
245
self._parent_ids = [parent_id for parent_id, tree in parents_list]
292
if parents_list[0][1] is None or parents_list[0][1] == 'null:':
293
import pdb; pdb.set_trace()
246
if parents_list[0][1] is None:
294
247
self._basis_tree = self.branch.repository.revision_tree(None)
296
249
self._basis_tree = parents_list[0][1]