Commit f0f2ff9cacc17dd9d4523e3647990e5db6013f20

Edward Thomson 2013-06-17T17:33:40

test failure when renames produce similar similarities

diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index 2600bd8..103ecd6 100644
--- a/tests-clar/diff/rename.c
+++ b/tests-clar/diff/rename.c
@@ -908,6 +908,76 @@ void test_diff_rename__rejected_match_can_match_others(void)
 	git_buf_free(&two);
 }
 
+static void write_similarity_file_two(const char *filename, size_t b_lines)
+{
+	git_buf contents = GIT_BUF_INIT;
+	size_t i;
+
+	for (i = 0; i < b_lines; i++)
+		git_buf_printf(&contents, "%0.2d - bbbbb\r\n", (i+1));
+
+	for (i = b_lines; i < 50; i++)
+		git_buf_printf(&contents, "%0.2d - aaaaa%s", (i+1), (i == 49 ? "" : "\r\n"));
+
+	cl_git_pass(
+		git_futils_writebuffer(&contents, filename, O_RDWR|O_CREAT, 0777));
+
+	git_buf_free(&contents);
+}
+
+void test_diff_rename__rejected_match_can_match_others_two(void)
+{
+	git_reference *head, *selfsimilar;
+	git_index *index;
+	git_tree *tree;
+	git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+	git_diff_list *diff;
+	git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+	git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
+	const char *sources[] = { "a.txt", "b.txt" };
+	const char *targets[] = { "c.txt", "d.txt" };
+	struct rename_expected expect = { 2, sources, targets };
+
+	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+	cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
+	cl_git_pass(git_reference_symbolic_set_target(
+		&selfsimilar, head, "refs/heads/renames_similar_two"));
+	cl_git_pass(git_checkout_head(g_repo, &opts));
+	cl_git_pass(git_repository_index(&index, g_repo));
+
+	cl_git_pass(p_unlink("renames/a.txt"));
+	cl_git_pass(p_unlink("renames/b.txt"));
+
+	cl_git_pass(git_index_remove_bypath(index, "a.txt"));
+	cl_git_pass(git_index_remove_bypath(index, "b.txt"));
+
+	write_similarity_file_two("renames/c.txt", 7);
+	write_similarity_file_two("renames/d.txt", 8);
+
+	cl_git_pass(git_index_add_bypath(index, "c.txt"));
+	cl_git_pass(git_index_add_bypath(index, "d.txt"));
+
+	cl_git_pass(git_index_write(index));
+
+	cl_git_pass(
+		git_revparse_single((git_object **)&tree, g_repo, "HEAD^{tree}"));
+
+	cl_git_pass(
+		git_diff_tree_to_index(&diff, g_repo, tree, index, &diffopts));
+	cl_git_pass(git_diff_find_similar(diff, &findopts));
+
+	cl_git_pass(
+		git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
+	cl_assert(expect.idx > 0);
+
+	git_diff_list_free(diff);
+	git_tree_free(tree);
+	git_index_free(index);
+	git_reference_free(head);
+	git_reference_free(selfsimilar);
+}
+
 void test_diff_rename__case_changes_are_split(void)
 {
 	git_index *index;
diff --git a/tests-clar/resources/renames/.gitted/objects/17/58bdd7c16a72ff7c17d8de0c957ced3ccad645 b/tests-clar/resources/renames/.gitted/objects/17/58bdd7c16a72ff7c17d8de0c957ced3ccad645
new file mode 100644
index 0000000..01801ed
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/17/58bdd7c16a72ff7c17d8de0c957ced3ccad645
@@ -0,0 +1,5 @@
+xEͱ
@QbWq
 H_&{]yYX`='흶=ZohzF
+
+
+
+MhBЄ&4	MhB3ьf4hF3юKx
\ No newline at end of file
diff --git a/tests-clar/resources/renames/.gitted/objects/50/e90273af7d826ff0a95865bcd3ba8412c447d9 b/tests-clar/resources/renames/.gitted/objects/50/e90273af7d826ff0a95865bcd3ba8412c447d9
new file mode 100644
index 0000000..a98d14e
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/objects/50/e90273af7d826ff0a95865bcd3ba8412c447d9
@@ -0,0 +1,3 @@
+xmM
+0`9\@OdE@&4hLI"]c}bծaBORvΡ5"
+b0[kLopͭU˺SC; 8hsF_le2}ɩ-!Dg4*IDO;!~)>m䮔~*D
\ No newline at end of file
diff --git a/tests-clar/resources/renames/.gitted/objects/b9/25b224cc91f897001a9993fbce169fdaa8858f b/tests-clar/resources/renames/.gitted/objects/b9/25b224cc91f897001a9993fbce169fdaa8858f
new file mode 100644
index 0000000..90e107f
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/b9/25b224cc91f897001a9993fbce169fdaa8858f differ
diff --git a/tests-clar/resources/renames/.gitted/objects/ea/c43f5195a2cee53b7458d8dad16aedde10711b b/tests-clar/resources/renames/.gitted/objects/ea/c43f5195a2cee53b7458d8dad16aedde10711b
new file mode 100644
index 0000000..2fb0250
Binary files /dev/null and b/tests-clar/resources/renames/.gitted/objects/ea/c43f5195a2cee53b7458d8dad16aedde10711b differ
diff --git a/tests-clar/resources/renames/.gitted/refs/heads/renames_similar_two b/tests-clar/resources/renames/.gitted/refs/heads/renames_similar_two
new file mode 100644
index 0000000..4ee5d04
--- /dev/null
+++ b/tests-clar/resources/renames/.gitted/refs/heads/renames_similar_two
@@ -0,0 +1 @@
+50e90273af7d826ff0a95865bcd3ba8412c447d9