62
59
# Memory tree doesn't have any control filenames
62
@needs_tree_write_lock
65
63
def _add(self, files, ids, kinds):
66
64
"""See MutableTree._add."""
67
with self.lock_tree_write():
68
for f, file_id, kind in zip(files, ids, kinds):
70
st_mode = self._file_transport.stat(f).st_mode
71
if stat.S_ISREG(st_mode):
73
elif stat.S_ISLNK(st_mode):
75
elif stat.S_ISDIR(st_mode):
78
raise AssertionError('Unknown file kind')
80
self._inventory.add_path(f, kind=kind)
82
self._inventory.add_path(f, kind=kind, file_id=file_id)
65
for f, file_id, kind in zip(files, ids, kinds):
69
self._inventory.add_path(f, kind=kind)
71
self._inventory.add_path(f, kind=kind, file_id=file_id)
84
73
def basis_tree(self):
85
74
"""See Tree.basis_tree()."""
98
87
missing files, so is a no-op.
101
def get_file(self, path):
90
def get_file(self, file_id, path=None):
102
91
"""See Tree.get_file."""
93
path = self.id2path(file_id)
103
94
return self._file_transport.get(path)
105
def get_file_sha1(self, path, stat_value=None):
96
def get_file_sha1(self, file_id, path=None, stat_value=None):
106
97
"""See Tree.get_file_sha1()."""
99
path = self.id2path(file_id)
107
100
stream = self._file_transport.get(path)
108
101
return sha_file(stream)
103
def get_root_id(self):
104
return self.path2id('')
110
106
def _comparison_data(self, entry, path):
111
107
"""See Tree._comparison_data."""
112
108
if entry is None:
113
109
return None, False, None
114
110
return entry.kind, entry.executable, None
112
@needs_tree_write_lock
116
113
def rename_one(self, from_rel, to_rel):
117
with self.lock_tree_write():
118
file_id = self.path2id(from_rel)
119
to_dir, to_tail = os.path.split(to_rel)
120
to_parent_id = self.path2id(to_dir)
121
self._file_transport.move(from_rel, to_rel)
122
self._inventory.rename(file_id, to_parent_id, to_tail)
114
file_id = self.path2id(from_rel)
115
to_dir, to_tail = os.path.split(to_rel)
116
to_parent_id = self.path2id(to_dir)
117
self._file_transport.move(from_rel, to_rel)
118
self._inventory.rename(file_id, to_parent_id, to_tail)
124
120
def path_content_summary(self, path):
125
121
"""See Tree.path_content_summary."""
126
122
id = self.path2id(path)
128
124
return 'missing', None, None, None
129
kind = self.kind(path, id)
130
126
if kind == 'file':
131
127
bytes = self._file_transport.get_bytes(path)
132
128
size = len(bytes)
133
129
executable = self._inventory[id].executable
134
sha1 = None # no stat cache
130
sha1 = None # no stat cache
135
131
return (kind, size, executable, sha1)
136
132
elif kind == 'directory':
137
133
# memory tree does not support nested trees yet.
138
134
return kind, None, None, None
139
135
elif kind == 'symlink':
140
return kind, None, None, self._inventory[id].symlink_target
136
raise NotImplementedError('symlink support')
142
138
raise NotImplementedError('unknown kind')
140
def _file_size(self, entry, stat_value):
141
"""See Tree._file_size."""
144
return entry.text_size
144
147
def get_parent_ids(self):
145
148
"""See Tree.get_parent_ids.
147
150
This implementation returns the current cached value from
148
151
self._parent_ids.
150
with self.lock_read():
151
return list(self._parent_ids)
153
return list(self._parent_ids)
153
155
def has_filename(self, filename):
154
156
"""See Tree.has_filename()."""
155
157
return self._file_transport.has(filename)
157
def is_executable(self, path):
158
return self._inventory.get_entry_by_path(path).executable
159
def is_executable(self, file_id, path=None):
160
return self._inventory[file_id].executable
160
def kind(self, path):
161
return self._inventory.get_entry_by_path(path).kind
162
def kind(self, file_id):
163
return self._inventory[file_id].kind
163
165
def mkdir(self, path, file_id=None):
164
166
"""See MutableTree.mkdir()."""
237
236
if entry.kind == 'directory':
238
237
self._file_transport.mkdir(path)
239
elif entry.kind == 'symlink':
240
self._file_transport.symlink(entry.symlink_target, path)
241
238
elif entry.kind == 'file':
242
self._file_transport.put_file(
243
path, self._basis_tree.get_file(path))
239
self._file_transport.put_file(path,
240
self._basis_tree.get_file(entry.file_id))
245
242
raise NotImplementedError(self._populate_from_branch)
247
def put_file_bytes_non_atomic(self, path, bytes):
244
def put_file_bytes_non_atomic(self, file_id, bytes):
248
245
"""See MutableTree.put_file_bytes_non_atomic."""
249
self._file_transport.put_bytes(path, bytes)
246
self._file_transport.put_bytes(self.id2path(file_id), bytes)
251
248
def unlock(self):
252
249
"""Release a lock.
269
def unversion(self, paths):
270
"""Remove the paths from the current versioned set.
266
@needs_tree_write_lock
267
def unversion(self, file_ids):
268
"""Remove the file ids in file_ids from the current versioned set.
272
270
When a file_id is unversioned, all of its children are automatically
275
:param paths: The paths to stop versioning.
273
:param file_ids: The file ids to stop versioning.
276
274
:raises: NoSuchId if any fileid is not currently versioned.
278
with self.lock_tree_write():
279
# XXX: This should be in mutabletree, but the inventory-save action
280
# is not relevant to memory tree. Until that is done in unlock by
281
# working tree, we cannot share the implementation.
284
file_id = self.path2id(path)
286
raise errors.NoSuchFile(path)
287
file_ids.add(file_id)
288
for file_id in file_ids:
289
if self._inventory.has_id(file_id):
290
self._inventory.remove_recursive_id(file_id)
276
# XXX: This should be in mutabletree, but the inventory-save action
277
# is not relevant to memory tree. Until that is done in unlock by
278
# working tree, we cannot share the implementation.
279
for file_id in file_ids:
280
if self._inventory.has_id(file_id):
281
self._inventory.remove_recursive_id(file_id)
283
raise errors.NoSuchId(self, file_id)
292
285
def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
293
286
"""See MutableTree.set_parent_trees()."""
316
def get_symlink_target(self, path):
317
with self.lock_read():
318
return self._file_transport.readlink(path)
320
309
def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
321
310
"""See MutableTree.set_parent_trees()."""
322
311
if len(parents_list) == 0:
323
312
self._parent_ids = []
324
313
self._basis_tree = self.branch.repository.revision_tree(
325
_mod_revision.NULL_REVISION)
314
_mod_revision.NULL_REVISION)
327
316
if parents_list[0][1] is None and not allow_leftmost_as_ghost:
328
317
# a ghost in the left most parent
329
318
raise errors.GhostRevisionUnusableHere(parents_list[0][0])
330
319
self._parent_ids = [parent_id for parent_id, tree in parents_list]
331
if parents_list[0][1] is None or parents_list[0][1] == b'null:':
320
if parents_list[0][1] is None or parents_list[0][1] == 'null:':
332
321
self._basis_tree = self.branch.repository.revision_tree(
333
_mod_revision.NULL_REVISION)
322
_mod_revision.NULL_REVISION)
335
324
self._basis_tree = parents_list[0][1]
336
325
self._branch_revision_id = parents_list[0][0]