115
115
'text_id', 'parent_id', 'children',
116
116
'revision', 'symlink_target']
118
def _add_text_to_weave(self, new_lines, parents, weave_store):
119
weave_store.add_text(self.file_id, self.revision, new_lines, parents)
118
121
def __init__(self, file_id, name, kind, parent_id, text_id=None):
119
122
"""Create an InventoryEntry
218
221
# others are added
224
def _get_snapshot_change(self, previous_entries):
225
if len(previous_entries) > 1:
227
elif len(previous_entries) == 0:
230
return 'modified/renamed/reparented'
222
232
def __repr__(self):
223
233
return ("%s(%r, %r, kind=%r, parent_id=%r)"
240
def snapshot(self, revision, path, previous_entries, work_tree,
242
"""Make a snapshot of this entry.
244
This means that all its fields are populated, that it has its
245
text stored in the text store or weave.
247
mutter('new parents of %s are %r', path, previous_entries)
248
self._read_tree_state(path, work_tree)
249
if len(previous_entries) == 1:
250
# cannot be unchanged unless there is only one parent file rev.
251
parent_ie = previous_entries.values()[0]
252
if self._unchanged(path, parent_ie, work_tree):
253
mutter("found unchanged entry")
254
self.revision = parent_ie.revision
256
mutter('new revision for {%s}', self.file_id)
257
self.revision = revision
258
change = self._get_snapshot_change(previous_entries)
259
if self.kind != 'file':
261
self._snapshot_text(previous_entries, work_tree, weave_store)
264
def _snapshot_text(self, file_parents, work_tree, weave_store):
265
mutter('storing file {%s} in revision {%s}',
266
self.file_id, self.revision)
267
# special case to avoid diffing on renames or
269
if (len(file_parents) == 1
270
and self.text_sha1 == file_parents.values()[0].text_sha1
271
and self.text_size == file_parents.values()[0].text_size):
272
previous_ie = file_parents.values()[0]
273
weave_store.add_identical_text(
274
self.file_id, previous_ie.revision,
275
self.revision, file_parents)
277
new_lines = work_tree.get_file(self.file_id).readlines()
278
self._add_text_to_weave(new_lines, file_parents, weave_store)
279
self.text_sha1 = sha_strings(new_lines)
280
self.text_size = sum(map(len, new_lines))
230
282
def __eq__(self, other):
231
283
if not isinstance(other, InventoryEntry):
232
284
return NotImplemented
247
299
def __hash__(self):
248
300
raise ValueError('not hashable')
250
def unchanged(self, previous_ie, work_tree):
302
def _unchanged(self, path, previous_ie, work_tree):
251
303
compatible = True
252
304
# different inv parent
253
305
if previous_ie.parent_id != self.parent_id:
256
308
elif previous_ie.name != self.name:
257
309
compatible = False
258
# changed link target
259
elif (hasattr(self,'symlink_target')
260
and self.symlink_target != previous_ie.symlink_target):
262
if self.kind != 'file':
264
self.text_sha1 = work_tree.get_file_sha1(self.file_id)
265
if self.text_sha1 != previous_ie.text_sha1:
268
# FIXME: 20050930 probe for the text size when getting sha1
269
self.text_size = previous_ie.text_size
310
if self.kind == 'symlink':
311
if self.symlink_target != previous_ie.symlink_target:
313
if self.kind == 'file':
314
if self.text_sha1 != previous_ie.text_sha1:
317
# FIXME: 20050930 probe for the text size when getting sha1
318
# in _read_tree_state
319
self.text_size = previous_ie.text_size
270
320
return compatible
322
def _read_tree_state(self, path, work_tree):
323
if self.kind == 'symlink':
324
self.read_symlink_target(work_tree.abspath(path))
325
if self.kind == 'file':
326
self.text_sha1 = work_tree.get_file_sha1(self.file_id)
273
329
class RootEntry(InventoryEntry):
274
330
def __init__(self, file_id):