Example #1
0
    def test_paths(self):
        blob_a1 = make_object(Blob, data=b'a1')
        blob_b2 = make_object(Blob, data=b'b2')
        blob_a3 = make_object(Blob, data=b'a3')
        blob_b3 = make_object(Blob, data=b'b3')
        c1, c2, c3 = self.make_linear_commits(3,
                                              trees={
                                                  1: [(b'a', blob_a1)],
                                                  2: [(b'a', blob_a1),
                                                      (b'x/b', blob_b2)],
                                                  3: [(b'a', blob_a3),
                                                      (b'x/b', blob_b3)]
                                              })

        self.assertWalkYields([c3, c2, c1], [c3.id])
        self.assertWalkYields([c3, c1], [c3.id], paths=[b'a'])
        self.assertWalkYields([c3, c2], [c3.id], paths=[b'x/b'])

        # All changes are included, not just for requested paths.
        changes = [
            TreeChange(CHANGE_MODIFY, (b'a', F, blob_a1.id),
                       (b'a', F, blob_a3.id)),
            TreeChange(CHANGE_MODIFY, (b'x/b', F, blob_b2.id),
                       (b'x/b', F, blob_b3.id)),
        ]
        self.assertWalkYields([TestWalkEntry(c3, changes)], [c3.id],
                              max_entries=1,
                              paths=[b'a'])
 def test_exact_rename_many_to_one(self):
     blob = make_object(Blob, data=b'1')
     tree1 = self.commit_tree([(b'a', blob), (b'b', blob)])
     tree2 = self.commit_tree([(b'c', blob)])
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, blob.id), (b'c', F, blob.id)),
          TreeChange.delete((b'b', F, blob.id))],
         self.detect_renames(tree1, tree2))
 def test_exact_rename_split_different_type(self):
     blob = make_object(Blob, data=b'/foo')
     tree1 = self.commit_tree([(b'a', blob, 0o100644)])
     tree2 = self.commit_tree([(b'a', blob, 0o120000)])
     self.assertEqual(
         [TreeChange.add((b'a', 0o120000, blob.id)),
          TreeChange.delete((b'a', 0o100644, blob.id))],
         self.detect_renames(tree1, tree2))
 def test_exact_copy_change_mode(self):
     blob = make_object(Blob, data=b'a\nb\nc\nd\n')
     tree1 = self.commit_tree([(b'a', blob)])
     tree2 = self.commit_tree([(b'a', blob, 0o100755), (b'b', blob)])
     self.assertEqual(
         [TreeChange(CHANGE_MODIFY, (b'a', F, blob.id),
                     (b'a', 0o100755, blob.id)),
          TreeChange(CHANGE_COPY, (b'a', F, blob.id), (b'b', F, blob.id))],
         self.detect_renames(tree1, tree2))
 def test_find_copies_harder_exact(self):
     blob = make_object(Blob, data=b'blob')
     tree1 = self.commit_tree([(b'a', blob)])
     tree2 = self.commit_tree([(b'a', blob), (b'b', blob)])
     self.assertEqual([TreeChange.add((b'b', F, blob.id))],
                      self.detect_renames(tree1, tree2))
     self.assertEqual(
         [TreeChange(CHANGE_COPY, (b'a', F, blob.id), (b'b', F, blob.id))],
         self.detect_renames(tree1, tree2, find_copies_harder=True))
 def test_tree_changes_to_tree(self):
     blob_a = make_object(Blob, data=b'a')
     blob_x = make_object(Blob, data=b'x')
     tree1 = self.commit_tree([(b'a', blob_a)])
     tree2 = self.commit_tree([(b'a/x', blob_x)])
     self.assertChangesEqual(
         [TreeChange.delete((b'a', F, blob_a.id)),
          TreeChange.add((b'a/x', F, blob_x.id))],
         tree1, tree2)
 def test_tree_changes_change_type(self):
     blob_a1 = make_object(Blob, data=b'a')
     blob_a2 = make_object(Blob, data=b'/foo/bar')
     tree1 = self.commit_tree([(b'a', blob_a1, 0o100644)])
     tree2 = self.commit_tree([(b'a', blob_a2, 0o120000)])
     self.assertChangesEqual(
         [TreeChange.delete((b'a', 0o100644, blob_a1.id)),
          TreeChange.add((b'a', 0o120000, blob_a2.id))],
         tree1, tree2)
 def test_exact_rename_and_different_type(self):
     blob1 = make_object(Blob, data=b'1')
     blob2 = make_object(Blob, data=b'2')
     tree1 = self.commit_tree([(b'a', blob1)])
     tree2 = self.commit_tree([(b'a', blob2, 0o120000), (b'b', blob1)])
     self.assertEqual(
             [TreeChange.add((b'a', 0o120000, blob2.id)),
              TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                         (b'b', F, blob1.id))],
             self.detect_renames(tree1, tree2))
 def test_tree_changes_for_merge_add_exact_rename_conflict(self):
     blob = make_object(Blob, data=b'a\nb\nc\nd\n')
     parent1 = self.commit_tree([(b'a', blob)])
     parent2 = self.commit_tree([])
     merge = self.commit_tree([(b'b', blob)])
     self.assertChangesForMergeEqual(
         [[TreeChange(CHANGE_RENAME, (b'a', F, blob.id),
                      (b'b', F, blob.id)),
           TreeChange.add((b'b', F, blob.id))]],
         [parent1, parent2], merge, rename_detector=self.detector)
 def test_tree_changes_for_merge_delete_delete_conflict(self):
     blob1 = make_object(Blob, data=b'1')
     blob2 = make_object(Blob, data=b'2')
     parent1 = self.commit_tree([(b'a', blob1)])
     parent2 = self.commit_tree([(b'a', blob2)])
     merge = self.commit_tree([])
     self.assertChangesForMergeEqual(
         [[TreeChange.delete((b'a', F, blob1.id)),
           TreeChange.delete((b'a', F, blob2.id))]],
         [parent1, parent2], merge)
 def test_exact_rename_one_to_one(self):
     blob1 = make_object(Blob, data=b'1')
     blob2 = make_object(Blob, data=b'2')
     tree1 = self.commit_tree([(b'a', blob1), (b'b', blob2)])
     tree2 = self.commit_tree([(b'c', blob1), (b'd', blob2)])
     self.assertEqual(
             [TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                         (b'c', F, blob1.id)),
              TreeChange(CHANGE_RENAME, (b'b', F, blob2.id),
                         (b'd', F, blob2.id))],
             self.detect_renames(tree1, tree2))
 def test_exact_copy_modify(self):
     blob1 = make_object(Blob, data=b'a\nb\nc\nd\n')
     blob2 = make_object(Blob, data=b'a\nb\nc\ne\n')
     tree1 = self.commit_tree([(b'a', blob1)])
     tree2 = self.commit_tree([(b'a', blob2), (b'b', blob1)])
     self.assertEqual(
         [TreeChange(CHANGE_MODIFY, (b'a', F, blob1.id),
                     (b'a', F, blob2.id)),
          TreeChange(CHANGE_COPY, (b'a', F, blob1.id),
                     (b'b', F, blob1.id))],
         self.detect_renames(tree1, tree2))
 def test_tree_changes_no_changes(self):
     blob = make_object(Blob, data=b'blob')
     tree = self.commit_tree([(b'a', blob), (b'b/c', blob)])
     self.assertChangesEqual([], self.empty_tree, self.empty_tree)
     self.assertChangesEqual([], tree, tree)
     self.assertChangesEqual(
         [TreeChange(CHANGE_UNCHANGED, (b'a', F, blob.id),
                     (b'a', F, blob.id)),
          TreeChange(CHANGE_UNCHANGED, (b'b/c', F, blob.id),
                     (b'b/c', F, blob.id))],
         tree, tree, want_unchanged=True)
 def test_find_copies_harder_content(self):
     blob1 = make_object(Blob, data=b'a\nb\nc\nd\n')
     blob2 = make_object(Blob, data=b'a\nb\nc\ne\n')
     tree1 = self.commit_tree([(b'a', blob1)])
     tree2 = self.commit_tree([(b'a', blob1), (b'b', blob2)])
     self.assertEqual([TreeChange.add((b'b', F, blob2.id))],
                      self.detect_renames(tree1, tree2))
     self.assertEqual(
         [TreeChange(CHANGE_COPY, (b'a', F, blob1.id),
                     (b'b', F, blob2.id))],
         self.detect_renames(tree1, tree2, find_copies_harder=True))
 def test_content_rename_many_to_one(self):
     blob1 = make_object(Blob, data=b'a\nb\nc\nd\n')
     blob2 = make_object(Blob, data=b'a\nb\nc\ne\n')
     blob3 = make_object(Blob, data=b'a\nb\nc\nf\n')
     tree1 = self.commit_tree([(b'a', blob1), (b'b', blob2)])
     tree2 = self.commit_tree([(b'c', blob3)])
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                     (b'c', F, blob3.id)),
          TreeChange.delete((b'b', F, blob2.id))],
         self.detect_renames(tree1, tree2))
 def test_content_rename_one_to_one(self):
     b11 = make_object(Blob, data=b'a\nb\nc\nd\n')
     b12 = make_object(Blob, data=b'a\nb\nc\ne\n')
     b21 = make_object(Blob, data=b'e\nf\ng\n\h')
     b22 = make_object(Blob, data=b'e\nf\ng\n\i')
     tree1 = self.commit_tree([(b'a', b11), (b'b', b21)])
     tree2 = self.commit_tree([(b'c', b12), (b'd', b22)])
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, b11.id), (b'c', F, b12.id)),
          TreeChange(CHANGE_RENAME, (b'b', F, b21.id), (b'd', F, b22.id))],
         self.detect_renames(tree1, tree2))
 def test_content_rename_one_to_many(self):
     blob1 = make_object(Blob, data=b'aa\nb\nc\nd\ne\n')
     blob2 = make_object(Blob, data=b'ab\nb\nc\nd\ne\n')  # 8/11 match
     blob3 = make_object(Blob, data=b'aa\nb\nc\nd\nf\n')  # 9/11 match
     tree1 = self.commit_tree([(b'a', blob1)])
     tree2 = self.commit_tree([(b'b', blob2), (b'c', blob3)])
     self.assertEqual(
         [TreeChange(CHANGE_COPY, (b'a', F, blob1.id), (b'b', F, blob2.id)),
          TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                     (b'c', F, blob3.id))],
         self.detect_renames(tree1, tree2))
 def test_content_rename_with_more_deletions(self):
     blob1 = make_object(Blob, data=b'')
     tree1 = self.commit_tree([(b'a', blob1), (b'b', blob1), (b'c', blob1),
                               (b'd', blob1)])
     tree2 = self.commit_tree([(b'e', blob1), (b'f', blob1), (b'g', blob1)])
     self.maxDiff = None
     self.assertEqual(
       [TreeChange(CHANGE_RENAME, (b'a', F, blob1.id), (b'e', F, blob1.id)),
        TreeChange(CHANGE_RENAME, (b'b', F, blob1.id), (b'f', F, blob1.id)),
        TreeChange(CHANGE_RENAME, (b'c', F, blob1.id), (b'g', F, blob1.id)),
        TreeChange.delete((b'd', F, blob1.id))],
       self.detect_renames(tree1, tree2))
 def test_tree_changes_for_merge_modify_rename_conflict(self):
     blob1 = make_object(Blob, data=b'a\nb\nc\nd\n')
     blob2 = make_object(Blob, data=b'a\nb\nc\ne\n')
     parent1 = self.commit_tree([(b'a', blob1)])
     parent2 = self.commit_tree([(b'b', blob1)])
     merge = self.commit_tree([(b'b', blob2)])
     self.assertChangesForMergeEqual(
         [[TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                      (b'b', F, blob2.id)),
           TreeChange(CHANGE_MODIFY, (b'b', F, blob1.id),
                      (b'b', F, blob2.id))]],
         [parent1, parent2], merge, rename_detector=self.detector)
 def test_content_rename_swap(self):
     blob1 = make_object(Blob, data=b'a\nb\nc\nd\n')
     blob2 = make_object(Blob, data=b'e\nf\ng\nh\n')
     blob3 = make_object(Blob, data=b'a\nb\nc\ne\n')
     blob4 = make_object(Blob, data=b'e\nf\ng\ni\n')
     tree1 = self.commit_tree([(b'a', blob1), (b'b', blob2)])
     tree2 = self.commit_tree([(b'a', blob4), (b'b', blob3)])
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                     (b'b', F, blob3.id)),
          TreeChange(CHANGE_RENAME, (b'b', F, blob2.id),
                     (b'a', F, blob4.id))],
         self.detect_renames(tree1, tree2, rewrite_threshold=60))
 def test_content_rename_gitlink(self):
     blob1 = make_object(Blob, data=b'blob1')
     blob2 = make_object(Blob, data=b'blob2')
     link1 = b'1' * 40
     link2 = b'2' * 40
     tree1 = self.commit_tree([(b'a', blob1), (b'b', link1, 0o160000)])
     tree2 = self.commit_tree([(b'c', blob2), (b'd', link2, 0o160000)])
     self.assertEqual(
         [TreeChange.delete((b'a', 0o100644, blob1.id)),
          TreeChange.delete((b'b', 0o160000, link1)),
          TreeChange.add((b'c', 0o100644, blob2.id)),
          TreeChange.add((b'd', 0o160000, link2))],
         self.detect_renames(tree1, tree2))
 def test_rename_threshold(self):
     blob1 = make_object(Blob, data=b'a\nb\nc\n')
     blob2 = make_object(Blob, data=b'a\nb\nd\n')
     tree1 = self.commit_tree([(b'a', blob1)])
     tree2 = self.commit_tree([(b'b', blob2)])
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                     (b'b', F, blob2.id))],
         self.detect_renames(tree1, tree2, rename_threshold=50))
     self.assertEqual(
         [TreeChange.delete((b'a', F, blob1.id)),
          TreeChange.add((b'b', F, blob2.id))],
         self.detect_renames(tree1, tree2, rename_threshold=75))
 def test_tree_changes_for_merge_modify_modify_conflict(self):
     blob1 = make_object(Blob, data=b'1')
     blob2 = make_object(Blob, data=b'2')
     blob3 = make_object(Blob, data=b'3')
     parent1 = self.commit_tree([(b'a', blob1)])
     parent2 = self.commit_tree([(b'a', blob2)])
     merge = self.commit_tree([(b'a', blob3)])
     self.assertChangesForMergeEqual(
         [[TreeChange(CHANGE_MODIFY, (b'a', F, blob1.id),
                      (b'a', F, blob3.id)),
           TreeChange(CHANGE_MODIFY, (b'a', F, blob2.id),
                      (b'a', F, blob3.id))]],
         [parent1, parent2], merge)
 def test_tree_changes_add_delete(self):
     blob_a = make_object(Blob, data=b'a')
     blob_b = make_object(Blob, data=b'b')
     tree = self.commit_tree([(b'a', blob_a, 0o100644),
                              (b'x/b', blob_b, 0o100755)])
     self.assertChangesEqual(
         [TreeChange.add((b'a', 0o100644, blob_a.id)),
          TreeChange.add((b'x/b', 0o100755, blob_b.id))],
         self.empty_tree, tree)
     self.assertChangesEqual(
         [TreeChange.delete((b'a', 0o100644, blob_a.id)),
          TreeChange.delete((b'x/b', 0o100755, blob_b.id))],
         tree, self.empty_tree)
    def test_tree_changes_rename_detector(self):
        blob_a1 = make_object(Blob, data=b'a\nb\nc\nd\n')
        blob_a2 = make_object(Blob, data=b'a\nb\nc\ne\n')
        blob_b = make_object(Blob, data=b'b')
        tree1 = self.commit_tree([(b'a', blob_a1), (b'b', blob_b)])
        tree2 = self.commit_tree([(b'c', blob_a2), (b'b', blob_b)])
        detector = RenameDetector(self.store)

        self.assertChangesEqual(
            [TreeChange.delete((b'a', F, blob_a1.id)),
             TreeChange.add((b'c', F, blob_a2.id))],
            tree1, tree2)
        self.assertChangesEqual(
            [TreeChange.delete((b'a', F, blob_a1.id)),
             TreeChange(CHANGE_UNCHANGED, (b'b', F, blob_b.id),
                        (b'b', F, blob_b.id)),
             TreeChange.add((b'c', F, blob_a2.id))],
            tree1, tree2, want_unchanged=True)
        self.assertChangesEqual(
            [TreeChange(CHANGE_RENAME, (b'a', F, blob_a1.id),
                        (b'c', F, blob_a2.id))],
            tree1, tree2, rename_detector=detector)
        self.assertChangesEqual(
            [TreeChange(CHANGE_RENAME, (b'a', F, blob_a1.id),
                        (b'c', F, blob_a2.id)),
             TreeChange(CHANGE_UNCHANGED, (b'b', F, blob_b.id),
                        (b'b', F, blob_b.id))],
            tree1, tree2, rename_detector=detector, want_unchanged=True)
 def test_tree_changes_for_merge_octopus_delete(self):
     blob1 = make_object(Blob, data=b'1')
     blob2 = make_object(Blob, data=b'3')
     parent1 = self.commit_tree([(b'a', blob1)])
     parent2 = self.commit_tree([(b'a', blob2)])
     parent3 = merge = self.commit_tree([])
     self.assertChangesForMergeEqual([], [parent1, parent1, parent1], merge)
     self.assertChangesForMergeEqual([], [parent1, parent1, parent3], merge)
     self.assertChangesForMergeEqual([], [parent1, parent3, parent3], merge)
     self.assertChangesForMergeEqual(
         [[TreeChange.delete((b'a', F, blob1.id)),
           TreeChange.delete((b'a', F, blob2.id)),
           None]],
         [parent1, parent2, parent3], merge)
    def test_tree_changes_name_order(self):
        blob = make_object(Blob, data=b'a')
        tree1 = self.commit_tree([(b'a', blob), (b'a.', blob), (b'a..', blob)])
        # Tree order is the reverse of this, so if we used tree order, 'a..'
        # would not be merged.
        tree2 = self.commit_tree(
                [(b'a/x', blob), (b'a./x', blob), (b'a..', blob)])

        self.assertChangesEqual(
            [TreeChange.delete((b'a', F, blob.id)),
             TreeChange.add((b'a/x', F, blob.id)),
             TreeChange.delete((b'a.', F, blob.id)),
             TreeChange.add((b'a./x', F, blob.id))],
            tree1, tree2)
 def test_content_rename_many_to_many(self):
     blob1 = make_object(Blob, data=b'a\nb\nc\nd\n')
     blob2 = make_object(Blob, data=b'a\nb\nc\ne\n')
     blob3 = make_object(Blob, data=b'a\nb\nc\nf\n')
     blob4 = make_object(Blob, data=b'a\nb\nc\ng\n')
     tree1 = self.commit_tree([(b'a', blob1), (b'b', blob2)])
     tree2 = self.commit_tree([(b'c', blob3), (b'd', blob4)])
     # TODO(dborowitz): Distribute renames rather than greedily choosing
     # copies.
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, blob1.id),
                     (b'c', F, blob3.id)),
          TreeChange(CHANGE_COPY, (b'a', F, blob1.id), (b'd', F, blob4.id)),
          TreeChange.delete((b'b', F, blob2.id))],
         self.detect_renames(tree1, tree2))
Example #29
0
    def test_filter_with_merge(self):
        blob_a = make_object(Blob, data=b'a')
        blob_a2 = make_object(Blob, data=b'a2')
        blob_b = make_object(Blob, data=b'b')
        blob_b2 = make_object(Blob, data=b'b2')
        x1, y2, m3 = self.make_commits(
            [[1], [2], [3, 1, 2]],
            trees={
                1: [(b'x/a', blob_a)],
                2: [(b'y/b', blob_b)],
                3: [(b'x/a', blob_a2), (b'y/b', blob_b2)]
            })

        # Get the WalkEntry for the merge commit.
        walker = Walker(self.store, m3.id)
        entries = list(walker)
        walker_entry = entries[0]
        self.assertEqual(walker_entry.commit.id, m3.id)
        changes = walker_entry.changes(b'x')
        self.assertEqual(1, len(changes))

        entry_a = (b'a', F, blob_a.id)
        entry_a2 = (b'a', F, blob_a2.id)
        self.assertEqual(
            [[TreeChange(CHANGE_MODIFY, entry_a, entry_a2)]],
            changes,
        )
 def test_want_unchanged(self):
     blob_a1 = make_object(Blob, data=b'a\nb\nc\nd\n')
     blob_b = make_object(Blob, data=b'b')
     blob_c2 = make_object(Blob, data=b'a\nb\nc\ne\n')
     tree1 = self.commit_tree([(b'a', blob_a1), (b'b', blob_b)])
     tree2 = self.commit_tree([(b'c', blob_c2), (b'b', blob_b)])
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, blob_a1.id),
                     (b'c', F, blob_c2.id))],
         self.detect_renames(tree1, tree2))
     self.assertEqual(
         [TreeChange(CHANGE_RENAME, (b'a', F, blob_a1.id),
                     (b'c', F, blob_c2.id)),
          TreeChange(CHANGE_UNCHANGED, (b'b', F, blob_b.id),
                     (b'b', F, blob_b.id))],
         self.detect_renames(tree1, tree2, want_unchanged=True))