summaryrefslogtreecommitdiff
path: root/tests-clar/diff/rename.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-07-24 17:11:49 -0700
committerRussell Belfer <rb@github.com>2013-07-24 17:11:49 -0700
commita5140f4dda66263a34080b11cfc34a49c9743100 (patch)
tree5c6d9ed1e5e7d29dbd39a856d0ba99d54345b114 /tests-clar/diff/rename.c
parentf5c4d0225157a6e15fc08f07aa77b5e8f52cdac5 (diff)
downloadlibgit2-a5140f4dda66263a34080b11cfc34a49c9743100.tar.gz
Fix rename detection for tree-to-tree diffs
The performance improvements I introduced for rename detection were not able to run successfully for tree-to-tree diffs because the blob size was not known early enough and so the file signature always had to be calculated nonetheless. This change separates loading blobs into memory from calculating the signature. I can't avoid having to load the large blobs into memory, but by moving it forward, I'm able to avoid the signature calculation if the blob won't come into play for renames.
Diffstat (limited to 'tests-clar/diff/rename.c')
-rw-r--r--tests-clar/diff/rename.c50
1 files changed, 48 insertions, 2 deletions
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index ed58b7aa9..79c89e362 100644
--- a/tests-clar/diff/rename.c
+++ b/tests-clar/diff/rename.c
@@ -1126,7 +1126,7 @@ void test_diff_rename__unmodified_can_be_renamed(void)
void test_diff_rename__many_files(void)
{
git_index *index;
- git_tree *tree;
+ git_tree *tree, *new_tree;
git_diff_list *diff = NULL;
diff_expects exp;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
@@ -1176,6 +1176,52 @@ void test_diff_rename__many_files(void)
cl_assert_equal_i(51, exp.files);
git_diff_list_free(diff);
- git_index_free(index);
+
+ {
+ git_object *parent;
+ git_signature *sig;
+ git_oid tree_id, commit_id;
+ git_reference *ref;
+
+ cl_git_pass(git_index_write_tree(&tree_id, index));
+ cl_git_pass(git_tree_lookup(&new_tree, g_repo, &tree_id));
+
+ cl_git_pass(git_revparse_ext(&parent, &ref, g_repo, "HEAD"));
+ cl_git_pass(git_signature_new(
+ &sig, "Sm Test", "sm@tester.test", 1372350000, 480));
+
+ cl_git_pass(git_commit_create_v(
+ &commit_id, g_repo, git_reference_name(ref), sig, sig,
+ NULL, "yoyoyo", new_tree, 1, parent));
+
+ git_object_free(parent);
+ git_reference_free(ref);
+ git_signature_free(sig);
+ }
+
+ cl_git_pass(git_diff_tree_to_tree(
+ &diff, g_repo, tree, new_tree, &diffopts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, NULL, NULL, &exp));
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(51, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(52, exp.files);
+
+ opts.flags = GIT_DIFF_FIND_ALL;
+ cl_git_pass(git_diff_find_similar(diff, &opts));
+
+ memset(&exp, 0, sizeof(exp));
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, NULL, NULL, &exp));
+ cl_assert_equal_i(1, exp.file_status[GIT_DELTA_RENAMED]);
+ cl_assert_equal_i(50, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(51, exp.files);
+
+ git_diff_list_free(diff);
+
+ git_tree_free(new_tree);
git_tree_free(tree);
+ git_index_free(index);
}