127
127
'text_id', 'parent_id', 'children', 'executable',
130
def _add_text_to_weave(self, new_lines, parents, weave_store, transaction):
131
versionedfile = weave_store.get_weave_or_empty(self.file_id,
133
versionedfile.add_lines(self.revision, parents, new_lines)
134
versionedfile.clear_cache()
136
130
def detect_changes(self, old_entry):
137
131
"""Return a (text_modified, meta_modified) from this to old_entry.
412
406
def snapshot(self, revision, path, previous_entries,
413
work_tree, weave_store, transaction):
407
work_tree, commit_builder):
414
408
"""Make a snapshot of this entry which may or may not have changed.
416
410
This means that all its fields are populated, that it has its
419
413
mutter('new parents of %s are %r', path, previous_entries)
420
414
self._read_tree_state(path, work_tree)
415
# TODO: Where should we determine whether to reuse a
416
# previous revision id or create a new revision? 20060606
421
417
if len(previous_entries) == 1:
422
418
# cannot be unchanged unless there is only one parent file rev.
423
419
parent_ie = previous_entries.values()[0]
426
422
self.revision = parent_ie.revision
427
423
return "unchanged"
428
424
return self._snapshot_into_revision(revision, previous_entries,
429
work_tree, weave_store, transaction)
425
work_tree, commit_builder)
431
427
def _snapshot_into_revision(self, revision, previous_entries, work_tree,
432
weave_store, transaction):
433
429
"""Record this revision unconditionally into a store.
435
431
The entry's last-changed revision property (`revision`) is updated to
442
438
mutter('new revision {%s} for {%s}', revision, self.file_id)
443
439
self.revision = revision
444
self._snapshot_text(previous_entries, work_tree, weave_store,
440
self._snapshot_text(previous_entries, work_tree, commit_builder)
447
def _snapshot_text(self, file_parents, work_tree, weave_store, transaction):
442
def _snapshot_text(self, file_parents, work_tree, commit_builder):
448
443
"""Record the 'text' of this entry, whatever form that takes.
450
445
This default implementation simply adds an empty text.
452
mutter('storing file {%s} in revision {%s}',
453
self.file_id, self.revision)
454
self._add_text_to_weave([], file_parents.keys(), weave_store, transaction)
447
raise NotImplementedError(self._snapshot_text)
456
449
def __eq__(self, other):
457
450
if not isinstance(other, InventoryEntry):
562
555
"""See InventoryEntry._put_on_disk."""
563
556
os.mkdir(fullpath)
558
def _snapshot_text(self, file_parents, work_tree, commit_builder):
559
"""See InventoryEntry._snapshot_text."""
560
commit_builder.modified_directory(self.file_id, file_parents)
566
563
class InventoryFile(InventoryEntry):
567
564
"""A file in an inventory."""
670
667
def _read_tree_state(self, path, work_tree):
671
668
"""See InventoryEntry._read_tree_state."""
672
669
self.text_sha1 = work_tree.get_file_sha1(self.file_id, path=path)
670
# FIXME: 20050930 probe for the text size when getting sha1
671
# in _read_tree_state
673
672
self.executable = work_tree.is_executable(self.file_id, path=path)
675
674
def _forget_tree_state(self):
676
675
self.text_sha1 = None
677
676
self.executable = None
679
def _snapshot_text(self, file_parents, work_tree, versionedfile_store, transaction):
678
def _snapshot_text(self, file_parents, work_tree, commit_builder):
680
679
"""See InventoryEntry._snapshot_text."""
681
mutter('storing text of file {%s} in revision {%s} into %r',
682
self.file_id, self.revision, versionedfile_store)
683
# special case to avoid diffing on renames or
685
if (len(file_parents) == 1
686
and self.text_sha1 == file_parents.values()[0].text_sha1
687
and self.text_size == file_parents.values()[0].text_size):
688
previous_ie = file_parents.values()[0]
689
versionedfile = versionedfile_store.get_weave(self.file_id, transaction)
690
versionedfile.clone_text(self.revision, previous_ie.revision, file_parents.keys())
692
new_lines = work_tree.get_file(self.file_id).readlines()
693
self._add_text_to_weave(new_lines, file_parents.keys(), versionedfile_store,
695
self.text_sha1 = sha_strings(new_lines)
696
self.text_size = sum(map(len, new_lines))
680
def get_content_byte_lines():
681
return work_tree.get_file(self.file_id).readlines()
682
self.text_sha1, self.text_size = commit_builder.modified_file_text(
683
self.file_id, file_parents, get_content_byte_lines, self.text_sha1, self.text_size)
699
685
def _unchanged(self, previous_ie):
700
686
"""See InventoryEntry._unchanged."""
794
780
compatible = False
795
781
return compatible
783
def _snapshot_text(self, file_parents, work_tree, commit_builder):
784
"""See InventoryEntry._snapshot_text."""
785
commit_builder.modified_link(
786
self.file_id, file_parents, self.symlink_target)
798
789
class Inventory(object):
799
790
"""Inventory of versioned files in a tree.