513
514
return self.new_path(old_path)
516
def old_contents_id(self, file_id):
517
if self.contents_by_id:
518
if self.base_tree.has_id(file_id):
522
new_path = self.id2path(file_id)
523
return self.base_tree.path2id(new_path)
515
525
def get_file(self, file_id):
516
new_path = self.id2path(file_id)
517
base_id = self.base_tree.path2id(new_path)
526
base_id = self.old_contents_id(file_id)
518
527
if base_id is not None:
519
528
patch_original = self.base_tree.get_file(base_id)
521
530
patch_original = None
522
file_patch = self.patches.get(new_path)
531
file_patch = self.patches.get(self.id2path(file_id))
523
532
if file_patch is None:
524
533
return patch_original
525
534
return patched_file(file_patch, patch_original)
684
693
return out.read()
687
"""Ensure that inventory adds work"""
695
def make_tree_2(self):
688
696
ctree = self.make_tree_1()[0]
689
697
ctree.note_rename("grandparent/parent/file",
690
698
"grandparent/alt_parent/file")
691
699
assert ctree.id2path("e") is None
692
700
assert ctree.path2id("grandparent/parent/file") is None
693
701
ctree.note_id("e", "grandparent/parent/file")
694
add_patch = self.unified_diff(["Hello\n"], ["Extra cheese\n"])
705
"""File/inventory adds"""
706
ctree = self.make_tree_2()
707
add_patch = self.unified_diff([], ["Extra cheese\n"])
695
708
ctree.note_patch("grandparent/parent/file", add_patch)
709
self.adds_test(ctree)
711
def adds_test(self, ctree):
697
712
assert ctree.id2path("e") == "grandparent/parent/file"
698
713
assert ctree.path2id("grandparent/parent/file") == "e"
699
714
assert ctree.get_file("e").read() == "Extra cheese\n"
716
def test_adds2(self):
717
"""File/inventory adds, with patch-compatibile renames"""
718
ctree = self.make_tree_2()
719
ctree.contents_by_id = False
720
add_patch = self.unified_diff(["Hello\n"], ["Extra cheese\n"])
721
ctree.note_patch("grandparent/parent/file", add_patch)
722
self.adds_test(ctree)
724
def make_tree_3(self):
702
725
ctree, mtree = self.make_tree_1()
703
726
mtree.add_file("e", "grandparent/parent/topping", "Anchovies\n")
704
727
ctree.note_rename("grandparent/parent/file",
705
728
"grandparent/alt_parent/file")
706
729
ctree.note_rename("grandparent/parent/topping",
707
730
"grandparent/alt_parent/stopping")
733
def get_file_test(self, ctree):
734
assert ctree.get_file("e").read() == "Lemon\n"
735
assert ctree.get_file("c").read() == "Hello\n"
737
def test_get_file(self):
738
"""Get file contents"""
739
ctree = self.make_tree_3()
740
mod_patch = self.unified_diff(["Anchovies\n"], ["Lemon\n"])
741
ctree.note_patch("grandparent/alt_parent/stopping", mod_patch)
742
self.get_file_test(ctree)
744
def test_get_file2(self):
745
"""Get file contents, with patch-compatibile renames"""
746
ctree = self.make_tree_3()
747
ctree.contents_by_id = False
708
748
mod_patch = self.unified_diff([], ["Lemon\n"])
709
749
ctree.note_patch("grandparent/alt_parent/stopping", mod_patch)
710
750
mod_patch = self.unified_diff([], ["Hello\n"])
711
751
ctree.note_patch("grandparent/alt_parent/file", mod_patch)
712
assert ctree.get_file("e").read() == "Lemon\n"
713
assert ctree.get_file("c").read() == "Hello\n"
752
self.get_file_test(ctree)
715
754
def test_delete(self):
716
755
"Deletion by changeset"