590
585
if old_path in self.deleted:
592
return self.base_tree.path2id(old_path)
587
if getattr(self.base_tree, 'path2id', None) is not None:
588
return self.base_tree.path2id(old_path)
590
return self.base_tree.inventory.path2id(old_path)
594
592
def id2path(self, file_id):
595
593
"""Return the new path in the target tree of the file with id file_id"""
626
624
base_id = self.old_contents_id(file_id)
627
625
if (base_id is not None and
628
base_id != self.base_tree.get_root_id()):
626
base_id != self.base_tree.inventory.root.file_id):
629
627
patch_original = self.base_tree.get_file(base_id)
631
629
patch_original = None
632
630
file_patch = self.patches.get(self.id2path(file_id))
633
631
if file_patch is None:
634
632
if (patch_original is None and
635
self.kind(file_id) == 'directory'):
633
self.get_kind(file_id) == 'directory'):
636
634
return StringIO()
637
635
if patch_original is None:
638
636
raise AssertionError("None: %s" % file_id)
643
641
'Malformed patch for %s, %r' % (file_id, file_patch))
644
642
return patched_file(file_patch, patch_original)
646
def get_symlink_target(self, file_id, path=None):
648
path = self.id2path(file_id)
644
def get_symlink_target(self, file_id):
645
new_path = self.id2path(file_id)
650
return self._targets[path]
647
return self._targets[new_path]
652
649
return self.base_tree.get_symlink_target(file_id)
654
def kind(self, file_id):
651
def get_kind(self, file_id):
655
652
if file_id in self._kinds:
656
653
return self._kinds[file_id]
657
return self.base_tree.kind(file_id)
659
def get_file_revision(self, file_id):
660
path = self.id2path(file_id)
661
if path in self._last_changed:
662
return self._last_changed[path]
664
return self.base_tree.get_file_revision(file_id)
654
return self.base_tree.inventory[file_id].kind
666
656
def is_executable(self, file_id):
667
657
path = self.id2path(file_id)
668
658
if path in self._executable:
669
659
return self._executable[path]
671
return self.base_tree.is_executable(file_id)
661
return self.base_tree.inventory[file_id].executable
673
663
def get_last_changed(self, file_id):
674
664
path = self.id2path(file_id)
687
677
if new_path not in self.patches:
688
678
# If the entry does not have a patch, then the
689
679
# contents must be the same as in the base_tree
690
text_size = self.base_tree.get_file_size(file_id)
691
text_sha1 = self.base_tree.get_file_sha1(file_id)
692
return text_size, text_sha1
680
ie = self.base_tree.inventory[file_id]
681
if ie.text_size is None:
682
return ie.text_size, ie.text_sha1
683
return int(ie.text_size), ie.text_sha1
693
684
fileobj = self.get_file(file_id)
694
685
content = fileobj.read()
695
686
return len(content), sha_string(content)
700
691
This need to be called before ever accessing self.inventory
702
693
from os.path import dirname, basename
694
base_inv = self.base_tree.inventory
703
695
inv = Inventory(None, self.revision_id)
705
697
def add_entry(file_id):
712
704
parent_path = dirname(path)
713
705
parent_id = self.path2id(parent_path)
715
kind = self.kind(file_id)
707
kind = self.get_kind(file_id)
716
708
revision_id = self.get_last_changed(file_id)
718
710
name = basename(path)
723
715
ie.executable = self.is_executable(file_id)
724
716
elif kind == 'symlink':
725
717
ie = InventoryLink(file_id, name, parent_id)
726
ie.symlink_target = self.get_symlink_target(file_id, path)
718
ie.symlink_target = self.get_symlink_target(file_id)
727
719
ie.revision = revision_id
729
721
if kind == 'file':
746
738
# at that instant
747
739
inventory = property(_get_inventory)
749
root_inventory = property(_get_inventory)
751
def all_file_ids(self):
753
[entry.file_id for path, entry in self.inventory.iter_entries()])
742
for path, entry in self.inventory.iter_entries():
755
745
def list_files(self, include_root=False, from_dir=None, recursive=True):
756
746
# The only files returned by this are those from the version