/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to read_changeset.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-07-01 18:39:23 UTC
  • mto: (0.5.85) (1185.82.1 bzr-w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: aaron.bentley@utoronto.ca-20050701183923-a62103dc665202a8
Make contents-addressing configurable

Show diffs side-by-side

added added

removed removed

Lines of Context:
430
430
        self._new_id_r = {}
431
431
        self.patches = {}
432
432
        self.deleted = []
 
433
        self.contents_by_id = True
433
434
 
434
435
    def note_rename(self, old_path, new_path):
435
436
        assert not self._renamed.has_key(old_path)
512
513
            return None
513
514
        return self.new_path(old_path)
514
515
 
 
516
    def old_contents_id(self, file_id):
 
517
        if self.contents_by_id:
 
518
            if self.base_tree.has_id(file_id):
 
519
                return file_id
 
520
            else:
 
521
                return None
 
522
        new_path = self.id2path(file_id)
 
523
        return self.base_tree.path2id(new_path)
 
524
        
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)
520
529
        else:
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)
683
692
            out.seek(0,0)
684
693
            return out.read()
685
694
 
686
 
        def test_adds(self):
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"])
 
702
            return ctree
 
703
 
 
704
        def test_adds(self):
 
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)
696
710
 
 
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"
700
715
 
701
 
        def test_get(self):
 
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)
 
723
 
 
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")
 
731
            return ctree
 
732
 
 
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"
 
736
 
 
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)
 
743
 
 
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)
714
753
 
715
754
        def test_delete(self):
716
755
            "Deletion by changeset"