159
159
"""Return true if the object this entry represents has textual data.
161
161
Note that textual data includes binary content.
163
Also note that all entries get weave files created for them.
164
This attribute is primarily used when upgrading from old trees that
165
did not have the weave index for all inventory entries.
276
280
if len(previous_entries) == 1:
277
281
# cannot be unchanged unless there is only one parent file rev.
278
282
parent_ie = previous_entries.values()[0]
279
if self._unchanged(path, parent_ie, work_tree):
283
if self._unchanged(parent_ie):
280
284
mutter("found unchanged entry")
281
285
self.revision = parent_ie.revision
282
286
return "unchanged"
289
293
mutter('new revision for {%s}', self.file_id)
290
294
self.revision = revision
291
295
change = self._get_snapshot_change(previous_entries)
296
self._snapshot_text(previous_entries, work_tree, weave_store)
294
299
def _snapshot_text(self, file_parents, work_tree, weave_store):
300
"""Record the 'text' of this entry, whatever form that takes.
302
This default implementation simply adds an empty text.
295
304
mutter('storing file {%s} in revision {%s}',
296
305
self.file_id, self.revision)
297
# special case to avoid diffing on renames or
299
if (len(file_parents) == 1
300
and self.text_sha1 == file_parents.values()[0].text_sha1
301
and self.text_size == file_parents.values()[0].text_size):
302
previous_ie = file_parents.values()[0]
303
weave_store.add_identical_text(
304
self.file_id, previous_ie.revision,
305
self.revision, file_parents)
307
new_lines = work_tree.get_file(self.file_id).readlines()
308
self._add_text_to_weave(new_lines, file_parents, weave_store)
309
self.text_sha1 = sha_strings(new_lines)
310
self.text_size = sum(map(len, new_lines))
306
self._add_text_to_weave([], file_parents, weave_store)
312
308
def __eq__(self, other):
313
309
if not isinstance(other, InventoryEntry):
331
327
def __hash__(self):
332
328
raise ValueError('not hashable')
334
def _unchanged(self, path, previous_ie, work_tree):
330
def _unchanged(self, previous_ie):
335
331
"""Has this entry changed relative to previous_ie.
337
333
This method should be overriden in child classes.
502
498
self.text_sha1 = work_tree.get_file_sha1(self.file_id)
503
499
self.executable = work_tree.is_executable(self.file_id)
505
def snapshot_revision(self, revision, previous_entries, work_tree,
507
"""See InventoryEntry.snapshot_revision."""
508
change = super(InventoryFile, self).snapshot_revision(revision,
509
previous_entries, work_tree, weave_store)
510
self._snapshot_text(previous_entries, work_tree, weave_store)
513
def _unchanged(self, path, previous_ie, work_tree):
501
def _snapshot_text(self, file_parents, work_tree, weave_store):
502
"""See InventoryEntry._snapshot_text."""
503
mutter('storing file {%s} in revision {%s}',
504
self.file_id, self.revision)
505
# special case to avoid diffing on renames or
507
if (len(file_parents) == 1
508
and self.text_sha1 == file_parents.values()[0].text_sha1
509
and self.text_size == file_parents.values()[0].text_size):
510
previous_ie = file_parents.values()[0]
511
weave_store.add_identical_text(
512
self.file_id, previous_ie.revision,
513
self.revision, file_parents)
515
new_lines = work_tree.get_file(self.file_id).readlines()
516
self._add_text_to_weave(new_lines, file_parents, weave_store)
517
self.text_sha1 = sha_strings(new_lines)
518
self.text_size = sum(map(len, new_lines))
521
def _unchanged(self, previous_ie):
514
522
"""See InventoryEntry._unchanged."""
515
compatible = super(InventoryFile, self)._unchanged(path, previous_ie,
523
compatible = super(InventoryFile, self)._unchanged(previous_ie)
517
524
if self.text_sha1 != previous_ie.text_sha1:
518
525
compatible = False
597
604
"""See InventoryEntry._read_tree_state."""
598
605
self.symlink_target = work_tree.get_symlink_target(self.file_id)
600
def _unchanged(self, path, previous_ie, work_tree):
607
def _unchanged(self, previous_ie):
601
608
"""See InventoryEntry._unchanged."""
602
compatible = super(InventoryLink, self)._unchanged(path, previous_ie,
609
compatible = super(InventoryLink, self)._unchanged(previous_ie)
604
610
if self.symlink_target != previous_ie.symlink_target:
605
611
compatible = False
606
612
return compatible