~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/intertree_implementations/test_compare.py

  • Committer: Robert Collins
  • Date: 2007-03-02 01:06:12 UTC
  • mto: (2255.11.3 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20070302010612-v4zb59puoc5b0ai5
Teach _iter_changes to gather unversioned path details upon request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
398
398
                (entry.name, None), (entry.kind, None),
399
399
                (entry.executable, None))
400
400
 
 
401
    def renamed(self, from_tree, to_tree, file_id, content_changed):
 
402
        from_entry = from_tree.inventory[file_id]
 
403
        to_entry = to_tree.inventory[file_id]
 
404
        from_path = from_tree.id2path(file_id)
 
405
        to_path = to_tree.id2path(file_id)
 
406
        return (file_id, to_path, content_changed, (True, True),
 
407
            (from_entry.parent_id, to_entry.parent_id),
 
408
            (from_entry.name, to_entry.name),
 
409
            (from_entry.kind, to_entry.kind),
 
410
            (from_entry.executable, to_entry.executable))
 
411
 
401
412
    def unchanged(self, tree, file_id):
402
413
        entry = tree.inventory[file_id]
403
414
        parent = entry.parent_id
609
620
            (False, False)), self.unchanged(tree1, 'c-id')]),
610
621
            self.do_iter_changes(tree1, tree2, include_unchanged=True))
611
622
 
612
 
    def _todo_test_unversioned_paths_in_tree(self):
 
623
    def test_default_ignores_unversioned_files(self):
613
624
        tree1 = self.make_branch_and_tree('tree1')
614
625
        tree2 = self.make_to_branch_and_tree('tree2')
615
 
        self.build_tree(['tree2/file', 'tree2/dir/'])
616
 
        # try:
617
 
        os.symlink('target', 'tree2/link')
618
 
        links_supported = True
619
 
        # except ???:
620
 
        #   links_supported = False
 
626
        self.build_tree(['tree1/a', 'tree1/c',
 
627
                         'tree2/a', 'tree2/b', 'tree2/c'])
 
628
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
 
629
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
 
630
 
621
631
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
622
 
        root_id = tree1.path2id('')
623
632
        tree1.lock_read()
624
633
        self.addCleanup(tree1.unlock)
625
634
        tree2.lock_read()
626
635
        self.addCleanup(tree2.unlock)
627
 
        expected = [
628
 
            self.unversioned(tree2, 'file'),
629
 
            self.unversioned(tree2, 'dir'),
630
 
            ]
631
 
        if links_supported:
632
 
            expected.append(self.unversioned(tree2, 'link'))
633
 
        expected = sorted(expected)
 
636
 
 
637
        # We should ignore the fact that 'b' exists in tree-2
 
638
        # because the want_unversioned parameter was not given.
 
639
        expected = sorted([
 
640
            self.content_changed(tree2, 'a-id'),
 
641
            self.content_changed(tree2, 'c-id'),
 
642
            ])
634
643
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
635
644
 
636
 
    def _todo_test_unversioned_paths_in_tree_specific_files(self):
637
 
        tree1 = self.make_branch_and_tree('tree1')
638
 
        tree2 = self.make_to_branch_and_tree('tree2')
639
 
        self.build_tree(['tree2/file', 'tree2/dir/'])
640
 
        # try:
641
 
        os.symlink('target', 'tree2/link')
642
 
        links_supported = True
643
 
        # except ???:
644
 
        #   links_supported = False
645
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
646
 
        root_id = tree1.path2id('')
647
 
        tree1.lock_read()
648
 
        self.addCleanup(tree1.unlock)
649
 
        tree2.lock_read()
650
 
        self.addCleanup(tree2.unlock)
651
 
        expected = [
652
 
            self.unversioned(tree2, 'file'),
653
 
            self.unversioned(tree2, 'dir'),
654
 
            ]
655
 
        specific_files=['file', 'dir']
656
 
        if links_supported:
657
 
            expected.append(self.unversioned(tree2, 'link'))
658
 
            specific_files.append('link')
659
 
        expected = sorted(expected)
660
 
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
661
 
            specific_files=specific_files))
 
645
    def test_unversioned_paths_in_tree(self):
 
646
        tree1 = self.make_branch_and_tree('tree1')
 
647
        tree2 = self.make_to_branch_and_tree('tree2')
 
648
        self.build_tree(['tree2/file', 'tree2/dir/'])
 
649
        # try:
 
650
        os.symlink('target', 'tree2/link')
 
651
        links_supported = True
 
652
        # except ???:
 
653
        #   links_supported = False
 
654
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
655
        root_id = tree1.path2id('')
 
656
        tree1.lock_read()
 
657
        self.addCleanup(tree1.unlock)
 
658
        tree2.lock_read()
 
659
        self.addCleanup(tree2.unlock)
 
660
        expected = [
 
661
            self.unversioned(tree2, 'file'),
 
662
            self.unversioned(tree2, 'dir'),
 
663
            ]
 
664
        if links_supported:
 
665
            expected.append(self.unversioned(tree2, 'link'))
 
666
        expected = sorted(expected)
 
667
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
668
            want_unversioned=True))
 
669
 
 
670
    def test_unversioned_paths_in_tree_specific_files(self):
 
671
        tree1 = self.make_branch_and_tree('tree1')
 
672
        tree2 = self.make_to_branch_and_tree('tree2')
 
673
        self.build_tree(['tree2/file', 'tree2/dir/'])
 
674
        # try:
 
675
        os.symlink('target', 'tree2/link')
 
676
        links_supported = True
 
677
        # except ???:
 
678
        #   links_supported = False
 
679
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
680
        root_id = tree1.path2id('')
 
681
        tree1.lock_read()
 
682
        self.addCleanup(tree1.unlock)
 
683
        tree2.lock_read()
 
684
        self.addCleanup(tree2.unlock)
 
685
        expected = [
 
686
            self.unversioned(tree2, 'file'),
 
687
            self.unversioned(tree2, 'dir'),
 
688
            ]
 
689
        specific_files=['file', 'dir']
 
690
        if links_supported:
 
691
            expected.append(self.unversioned(tree2, 'link'))
 
692
            specific_files.append('link')
 
693
        expected = sorted(expected)
 
694
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
695
            specific_files=specific_files, require_versioned=False,
 
696
            want_unversioned=True))
 
697
 
 
698
    def test_unversioned_paths_in_target_matching_source_old_names(self):
 
699
        # its likely that naive implementations of unversioned file support
 
700
        # will fail if the path was versioned, but is not any more, 
 
701
        # due to a rename, not due to unversioning it.
 
702
        # That is, if the old tree has a versioned file 'foo', and
 
703
        # the new tree has the same file but versioned as 'bar', and also
 
704
        # has an unknown file 'foo', we should get back output for
 
705
        # both foo and bar.
 
706
        tree1 = self.make_branch_and_tree('tree1')
 
707
        tree2 = self.make_to_branch_and_tree('tree2')
 
708
        self.build_tree(['tree2/file', 'tree2/dir/',
 
709
            'tree1/file', 'tree2/movedfile',
 
710
            'tree1/dir/', 'tree2/moveddir/'])
 
711
        # try:
 
712
        os.symlink('target', 'tree1/link')
 
713
        os.symlink('target', 'tree2/link')
 
714
        os.symlink('target', 'tree2/movedlink')
 
715
        links_supported = True
 
716
        # except ???:
 
717
        #   links_supported = False
 
718
        tree1.add(['file', 'dir', 'link'], ['file-id', 'dir-id', 'link-id'])
 
719
        tree2.add(['movedfile', 'moveddir', 'movedlink'],
 
720
            ['file-id', 'dir-id', 'link-id'])
 
721
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
 
722
        root_id = tree1.path2id('')
 
723
        tree1.lock_read()
 
724
        self.addCleanup(tree1.unlock)
 
725
        tree2.lock_read()
 
726
        self.addCleanup(tree2.unlock)
 
727
        expected = [
 
728
            self.renamed(tree1, tree2, 'dir-id', False),
 
729
            self.renamed(tree1, tree2, 'file-id', True),
 
730
            self.unversioned(tree2, 'file'),
 
731
            self.unversioned(tree2, 'dir'),
 
732
            ]
 
733
        specific_files=['file', 'dir']
 
734
        if links_supported:
 
735
            expected.append(self.renamed(tree1, tree2, 'link-id', False))
 
736
            expected.append(self.unversioned(tree2, 'link'))
 
737
            specific_files.append('link')
 
738
        expected = sorted(expected)
 
739
        # run once with, and once without specific files, to catch
 
740
        # potentially different code paths.
 
741
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
742
            require_versioned=False,
 
743
            want_unversioned=True))
 
744
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
 
745
            specific_files=specific_files, require_versioned=False,
 
746
            want_unversioned=True))
662
747
 
663
748
    def make_trees_with_symlinks(self):
664
749
        tree1 = self.make_branch_and_tree('tree1')
768
853
                          if f_id.endswith('_f-id'))
769
854
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
770
855
 
771
 
    def test_trees_with_unknown(self):
772
 
        tree1 = self.make_branch_and_tree('tree1')
773
 
        tree2 = self.make_to_branch_and_tree('tree2')
774
 
        self.build_tree(['tree1/a', 'tree1/c',
775
 
                         'tree2/a', 'tree2/b', 'tree2/c'])
776
 
        tree1.add(['a', 'c'], ['a-id', 'c-id'])
777
 
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
778
 
 
779
 
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
780
 
        tree1.lock_read()
781
 
        self.addCleanup(tree1.unlock)
782
 
        tree2.lock_read()
783
 
        self.addCleanup(tree2.unlock)
784
 
 
785
 
        # We should ignore the fact that 'b' exists in tree-2
786
 
        expected = sorted([
787
 
            self.content_changed(tree2, 'a-id'),
788
 
            self.content_changed(tree2, 'c-id'),
789
 
            ])
790
 
        self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
791
 
 
792
856
    def test_trees_with_missing_dir(self):
793
857
        tree1 = self.make_branch_and_tree('tree1')
794
858
        tree2 = self.make_to_branch_and_tree('tree2')