616
616
new_path = self.id2path(file_id)
617
617
return self.base_tree.path2id(new_path)
619
def get_file(self, path, file_id=None):
619
def get_file(self, path):
620
620
"""Return a file-like object containing the new contents of the
621
621
file given by file_id.
624
624
in the text-store, so that the file contents would
628
file_id = self.path2id(path)
627
file_id = self.path2id(path)
629
628
base_id = self.old_contents_id(file_id)
630
629
if (base_id is not None and
631
630
base_id != self.base_tree.get_root_id()):
632
old_path = self.old_path(path)
633
patch_original = self.base_tree.get_file(
631
old_path = self.base_tree.id2path(base_id)
632
patch_original = self.base_tree.get_file(old_path)
636
634
patch_original = None
637
635
file_patch = self.patches.get(path)
638
636
if file_patch is None:
639
637
if (patch_original is None and
640
self.kind(path, file_id) == 'directory'):
638
self.kind(path) == 'directory'):
642
640
if patch_original is None:
643
641
raise AssertionError("None: %s" % file_id)
648
646
'Malformed patch for %s, %r' % (file_id, file_patch))
649
647
return patched_file(file_patch, patch_original)
651
def get_symlink_target(self, path, file_id=None):
649
def get_symlink_target(self, path):
653
651
return self._targets[path]
655
653
old_path = self.old_path(path)
656
return self.base_tree.get_symlink_target(old_path, file_id)
654
return self.base_tree.get_symlink_target(old_path)
658
def kind(self, path, file_id=None):
656
def kind(self, path):
660
658
return self._kinds[path]
662
660
old_path = self.old_path(path)
663
return self.base_tree.kind(old_path, file_id)
661
return self.base_tree.kind(old_path)
665
def get_file_revision(self, path, file_id=None):
663
def get_file_revision(self, path):
666
664
if path in self._last_changed:
667
665
return self._last_changed[path]
669
667
old_path = self.old_path(path)
670
return self.base_tree.get_file_revision(old_path, file_id)
668
return self.base_tree.get_file_revision(old_path)
672
def is_executable(self, path, file_id=None):
670
def is_executable(self, path):
673
671
if path in self._executable:
674
672
return self._executable[path]
676
674
old_path = self.old_path(path)
677
return self.base_tree.is_executable(old_path, file_id)
675
return self.base_tree.is_executable(old_path)
679
def get_last_changed(self, path, file_id=None):
677
def get_last_changed(self, path):
680
678
if path in self._last_changed:
681
679
return self._last_changed[path]
682
680
old_path = self.old_path(path)
683
return self.base_tree.get_file_revision(old_path, file_id)
681
return self.base_tree.get_file_revision(old_path)
685
683
def get_size_and_sha1(self, new_path, file_id=None):
686
684
"""Return the size and sha1 hash of the given file id.
693
691
# If the entry does not have a patch, then the
694
692
# contents must be the same as in the base_tree
695
693
base_path = self.old_path(new_path)
696
text_size = self.base_tree.get_file_size(base_path, file_id)
697
text_sha1 = self.base_tree.get_file_sha1(base_path, file_id)
694
text_size = self.base_tree.get_file_size(base_path)
695
text_sha1 = self.base_tree.get_file_sha1(base_path)
698
696
return text_size, text_sha1
699
fileobj = self.get_file(new_path, file_id)
697
fileobj = self.get_file(new_path)
700
698
content = fileobj.read()
701
699
return len(content), sha_string(content)
715
713
parent_path = dirname(path)
716
714
parent_id = self.path2id(parent_path)
718
kind = self.kind(path, file_id)
719
revision_id = self.get_last_changed(path, file_id)
716
kind = self.kind(path)
717
revision_id = self.get_last_changed(path)
721
719
name = basename(path)
722
720
if kind == 'directory':
723
721
ie = InventoryDirectory(file_id, name, parent_id)
724
722
elif kind == 'file':
725
723
ie = InventoryFile(file_id, name, parent_id)
726
ie.executable = self.is_executable(path, file_id)
724
ie.executable = self.is_executable(path)
727
725
elif kind == 'symlink':
728
726
ie = InventoryLink(file_id, name, parent_id)
729
ie.symlink_target = self.get_symlink_target(path, file_id)
727
ie.symlink_target = self.get_symlink_target(path)
730
728
ie.revision = revision_id
732
730
if kind == 'file':
733
ie.text_size, ie.text_sha1 = self.get_size_and_sha1(
731
ie.text_size, ie.text_sha1 = self.get_size_and_sha1(path)
735
732
if ie.text_size is None:
737
734
'Got a text_size of None for file_id %r' % file_id)