From 1a79cd959ba2991dd3295f9940b28b606e494ccf Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 26 Apr 2016 01:18:01 -0400 Subject: patch: show copy information for identical copies When showing copy information because we are duplicating contents, for example, when performing a `diff --find-copies-harder -M100 -B100`, then show copy from/to lines in a patch, and do not show context. Ensure that we can also parse such patches. --- tests/diff/diff_helpers.c | 57 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'tests/diff/diff_helpers.c') diff --git a/tests/diff/diff_helpers.c b/tests/diff/diff_helpers.c index 8fa8e3eb5..50752b203 100644 --- a/tests/diff/diff_helpers.c +++ b/tests/diff/diff_helpers.c @@ -242,18 +242,44 @@ void diff_print_raw(FILE *fp, git_diff *diff) git_diff_print_callback__to_file_handle, fp ? fp : stderr)); } +static size_t num_modified_deltas(git_diff *diff) +{ + const git_diff_delta *delta; + size_t i, cnt = 0; + + for (i = 0; i < git_diff_num_deltas(diff); i++) { + delta = git_diff_get_delta(diff, i); + + if (delta->status != GIT_DELTA_UNMODIFIED) + cnt++; + } + + return cnt; +} + void diff_assert_equal(git_diff *a, git_diff *b) { const git_diff_delta *ad, *bd; - size_t i; + size_t i, j; assert(a && b); - cl_assert_equal_i(git_diff_num_deltas(a), git_diff_num_deltas(b)); + cl_assert_equal_i(num_modified_deltas(a), num_modified_deltas(b)); + + for (i = 0, j = 0; + i < git_diff_num_deltas(a) && j < git_diff_num_deltas(b); ) { - for (i = 0; i < git_diff_num_deltas(a); i++) { ad = git_diff_get_delta(a, i); - bd = git_diff_get_delta(b, i); + bd = git_diff_get_delta(b, j); + + if (ad->status == GIT_DELTA_UNMODIFIED) { + i++; + continue; + } + if (bd->status == GIT_DELTA_UNMODIFIED) { + j++; + continue; + } cl_assert_equal_i(ad->status, bd->status); cl_assert_equal_i(ad->flags, bd->flags); @@ -265,15 +291,26 @@ void diff_assert_equal(git_diff *a, git_diff *b) * computed deltas will have flags of `VALID_ID` and * `EXISTS` (parsed deltas will not query the ODB.) */ - cl_assert_equal_oid(&ad->old_file.id, &bd->old_file.id); - cl_assert_equal_i(ad->old_file.id_abbrev, bd->old_file.id_abbrev); + + /* an empty id indicates that it wasn't presented, because + * the diff was identical. (eg, pure rename, mode change only, etc) + */ + if (ad->old_file.id_abbrev && bd->old_file.id_abbrev) { + cl_assert_equal_i(ad->old_file.id_abbrev, bd->old_file.id_abbrev); + cl_assert_equal_oid(&ad->old_file.id, &bd->old_file.id); + cl_assert_equal_i(ad->old_file.mode, bd->old_file.mode); + } cl_assert_equal_s(ad->old_file.path, bd->old_file.path); - cl_assert_equal_i(ad->old_file.mode, bd->old_file.mode); - cl_assert_equal_oid(&ad->new_file.id, &bd->new_file.id); - cl_assert_equal_i(ad->new_file.id_abbrev, bd->new_file.id_abbrev); + if (ad->new_file.id_abbrev && bd->new_file.id_abbrev) { + cl_assert_equal_oid(&ad->new_file.id, &bd->new_file.id); + cl_assert_equal_i(ad->new_file.id_abbrev, bd->new_file.id_abbrev); + cl_assert_equal_i(ad->new_file.mode, bd->new_file.mode); + } cl_assert_equal_s(ad->new_file.path, bd->new_file.path); - cl_assert_equal_i(ad->new_file.mode, bd->new_file.mode); + + i++; + j++; } } -- cgit v1.2.1