From 8d0f46754ff933f014e033c0e4f442927788fa29 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 3 May 2012 16:27:22 +0200 Subject: [PATCH 1/7] diff: remove unused parameter --- src/diff_output.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/diff_output.c b/src/diff_output.c index c380db996..4eefbf284 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -169,7 +169,6 @@ static int file_is_binary_by_attr( } static int file_is_binary_by_content( - git_diff_list *diff, git_diff_delta *delta, git_map *old_data, git_map *new_data) @@ -177,8 +176,6 @@ static int file_is_binary_by_content( git_buf search; git_text_stats stats; - GIT_UNUSED(diff); - if ((delta->old_file.flags & BINARY_DIFF_FLAGS) == 0) { search.ptr = old_data->data; search.size = min(old_data->len, 4000); @@ -408,7 +405,7 @@ int git_diff_foreach( */ if (delta->binary == -1) { error = file_is_binary_by_content( - diff, delta, &old_data, &new_data); + delta, &old_data, &new_data); if (error < 0) goto cleanup; } From 245c5eaec553ca1793b2a83c288fd2595f70c6a5 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 3 May 2012 16:34:02 +0200 Subject: [PATCH 2/7] diff: When diffing two blobs, ensure the delta callback parameter is filled with relevant information --- src/diff_output.c | 8 ++++++-- tests-clar/diff/blob.c | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/diff_output.c b/src/diff_output.c index 4eefbf284..788c8b8f0 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -728,12 +728,16 @@ int git_diff_blobs( delta.status = old_data.ptr ? (new_data.ptr ? GIT_DELTA_MODIFIED : GIT_DELTA_DELETED) : (new_data.ptr ? GIT_DELTA_ADDED : GIT_DELTA_UNTRACKED); - delta.old_file.mode = 0100644; /* can't know the truth from a blob alone */ - delta.new_file.mode = 0100644; + delta.old_file.mode = 0000000; /* can't know the truth from a blob alone */ + delta.new_file.mode = 0000000; git_oid_cpy(&delta.old_file.oid, git_object_id((const git_object *)old_blob)); git_oid_cpy(&delta.new_file.oid, git_object_id((const git_object *)new_blob)); delta.old_file.path = NULL; delta.new_file.path = NULL; + delta.old_file.size = old_data.size; + delta.new_file.size = new_data.size; + delta.old_file.flags = 0; + delta.new_file.flags = 0; delta.similarity = 0; info.diff = NULL; diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c index ed1f14a07..65b350005 100644 --- a/tests-clar/diff/blob.c +++ b/tests-clar/diff/blob.c @@ -13,7 +13,7 @@ void test_diff_blob__cleanup(void) cl_git_sandbox_cleanup(); } -void test_diff_blob__0(void) +void test_diff_blob__can_compare_text_blobs(void) { git_blob *a, *b, *c, *d; git_oid a_oid, b_oid, c_oid, d_oid; From 4f80676182dfd93992cc701072a71651dd5613ee Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 3 May 2012 17:19:06 +0200 Subject: [PATCH 3/7] diff: fix the diffing of a concrete blob against a null one --- src/diff_output.c | 42 +++++++++++++++----------------- tests-clar/diff/blob.c | 55 ++++++++++++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 35 deletions(-) diff --git a/src/diff_output.c b/src/diff_output.c index 788c8b8f0..dbcc89fa5 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -686,7 +686,6 @@ int git_diff_print_patch( return error; } - int git_diff_blobs( git_blob *old_blob, git_blob *new_blob, @@ -701,44 +700,43 @@ int git_diff_blobs( xpparam_t xdiff_params; xdemitconf_t xdiff_config; xdemitcb_t xdiff_callback; + git_blob *new, *old; + + memset(&delta, 0, sizeof(delta)); + + new = new_blob; + old = old_blob; if (options && (options->flags & GIT_DIFF_REVERSE)) { - git_blob *swap = old_blob; - old_blob = new_blob; - new_blob = swap; + git_blob *swap = old; + old = new; + new = swap; } - if (old_blob) { - old_data.ptr = (char *)git_blob_rawcontent(old_blob); - old_data.size = git_blob_rawsize(old_blob); + if (old) { + old_data.ptr = (char *)git_blob_rawcontent(old); + old_data.size = git_blob_rawsize(old); + git_oid_cpy(&delta.old_file.oid, git_object_id((const git_object *)old)); } else { old_data.ptr = ""; old_data.size = 0; } - if (new_blob) { - new_data.ptr = (char *)git_blob_rawcontent(new_blob); - new_data.size = git_blob_rawsize(new_blob); + if (new) { + new_data.ptr = (char *)git_blob_rawcontent(new); + new_data.size = git_blob_rawsize(new); + git_oid_cpy(&delta.new_file.oid, git_object_id((const git_object *)new)); } else { new_data.ptr = ""; new_data.size = 0; } /* populate a "fake" delta record */ - delta.status = old_data.ptr ? - (new_data.ptr ? GIT_DELTA_MODIFIED : GIT_DELTA_DELETED) : - (new_data.ptr ? GIT_DELTA_ADDED : GIT_DELTA_UNTRACKED); - delta.old_file.mode = 0000000; /* can't know the truth from a blob alone */ - delta.new_file.mode = 0000000; - git_oid_cpy(&delta.old_file.oid, git_object_id((const git_object *)old_blob)); - git_oid_cpy(&delta.new_file.oid, git_object_id((const git_object *)new_blob)); - delta.old_file.path = NULL; - delta.new_file.path = NULL; + delta.status = new ? + (old ? GIT_DELTA_MODIFIED : GIT_DELTA_ADDED) : + (old ? GIT_DELTA_DELETED : GIT_DELTA_UNTRACKED); delta.old_file.size = old_data.size; delta.new_file.size = new_data.size; - delta.old_file.flags = 0; - delta.new_file.flags = 0; - delta.similarity = 0; info.diff = NULL; info.delta = δ diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c index 65b350005..9364bdc6d 100644 --- a/tests-clar/diff/blob.c +++ b/tests-clar/diff/blob.c @@ -2,23 +2,38 @@ #include "diff_helpers.h" static git_repository *g_repo = NULL; +static diff_expects exp; +static git_diff_options opts; +static git_blob *d; void test_diff_blob__initialize(void) { + git_oid d_oid; + g_repo = cl_git_sandbox_init("attr"); + + memset(&opts, 0, sizeof(opts)); + opts.context_lines = 1; + opts.interhunk_lines = 1; + + memset(&exp, 0, sizeof(exp)); + + /* tests/resources/attr/root_test4.txt */ + cl_git_pass(git_oid_fromstrn(&d_oid, "fe773770c5a6", 12)); + cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &d_oid, 6)); } void test_diff_blob__cleanup(void) { + git_blob_free(d); + cl_git_sandbox_cleanup(); } void test_diff_blob__can_compare_text_blobs(void) { - git_blob *a, *b, *c, *d; - git_oid a_oid, b_oid, c_oid, d_oid; - git_diff_options opts = {0}; - diff_expects exp; + git_blob *a, *b, *c; + git_oid a_oid, b_oid, c_oid; /* tests/resources/attr/root_test1 */ cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8)); @@ -32,16 +47,8 @@ void test_diff_blob__can_compare_text_blobs(void) cl_git_pass(git_oid_fromstrn(&c_oid, "c96bbb2c2557a832", 16)); cl_git_pass(git_blob_lookup_prefix(&c, g_repo, &c_oid, 8)); - /* tests/resources/attr/root_test4.txt */ - cl_git_pass(git_oid_fromstrn(&d_oid, "fe773770c5a6", 12)); - cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &d_oid, 6)); - /* Doing the equivalent of a `git diff -U1` on these files */ - opts.context_lines = 1; - opts.interhunk_lines = 1; - - memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_blobs( a, b, &opts, &exp, diff_hunk_fn, diff_line_fn)); @@ -86,6 +93,28 @@ void test_diff_blob__can_compare_text_blobs(void) git_blob_free(a); git_blob_free(b); git_blob_free(c); - git_blob_free(d); } +void test_diff_blob__can_compare_against_null_blobs(void) +{ + git_blob *e = NULL; + + cl_git_pass(git_diff_blobs( + d, e, &opts, &exp, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.hunks == 1); + cl_assert(exp.hunk_old_lines == 14); + cl_assert(exp.lines == 14); + cl_assert(exp.line_dels == 14); + + opts.flags |= GIT_DIFF_REVERSE; + memset(&exp, 0, sizeof(exp)); + + cl_git_pass(git_diff_blobs( + d, e, &opts, &exp, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.hunks == 1); + cl_assert(exp.hunk_new_lines == 14); + cl_assert(exp.lines == 14); + cl_assert(exp.line_adds == 14); +} From cfe25b13fa04e12ed7a4f60fc5f323b990db20cd Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 3 May 2012 16:11:40 +0200 Subject: [PATCH 4/7] tests: add two binary blobs to attr test repository - edf3dce -> assets.github.com/images/icons/emoji/alien.png?v5 - de863bf -> assets.github.com/images/icons/emoji/heart.png?v5 --- .../de/863bff4976c9ed7e17a4da0fd524908dc84049 | Bin 0 -> 4115 bytes .../ed/f3dcee4003d71f139777898882ccd097e34c53 | Bin 0 -> 6289 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests-clar/resources/attr/.gitted/objects/de/863bff4976c9ed7e17a4da0fd524908dc84049 create mode 100644 tests-clar/resources/attr/.gitted/objects/ed/f3dcee4003d71f139777898882ccd097e34c53 diff --git a/tests-clar/resources/attr/.gitted/objects/de/863bff4976c9ed7e17a4da0fd524908dc84049 b/tests-clar/resources/attr/.gitted/objects/de/863bff4976c9ed7e17a4da0fd524908dc84049 new file mode 100644 index 0000000000000000000000000000000000000000..7d9b8551f450f457ad12bf8f0297c9536f9791cf GIT binary patch literal 4115 zcmV+u5bW=G0RadQ_wQnCZ(<-cFgY{;iBL{Q4GJ0x0000DNk~Le0000$0000$2nGNE z0IF$m-T(jq32;bRa{vGqB>(^xB>_oNB=7(L53or@K~#7F?OO?qmDLqK_r2L?iVl>p zxG<YO^T$nK?Oltt6&vktxKcWq5|$#VyR+cgNbQtYf&M#f?9Eb zsO$&|$Sw>pGt9hs%kB5w_s-+aKmU6(Zx{v>J;|MW|GS-YzH{!m%gh*St$dv+@^x08 zx_<+}*WCk(Is(8=#&jzcInRiki}3@HcSoK|itIwZIwkVfU?M+J><4`RYs|L2!mKy}|7IsL0QZF@vGFFo_0IVj}o~P%HM(Y8Rhtr z;$rDJV1V=)HA+rC^GvA(?`Tnx)bH9Qwd>c*&UfCCy&E@5Gp6R`1Rh@a*b0$b{$nki zFgN7|V5~7EXNWvkY|J<+PfMRRc(9x^b*l8c^irvSAf}`wJ3EC0UYjYMR`m`2hpjhOorlzz|5GGPuDn%!qB*i^?NaDy5*|2b-te7=R4%O8O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;)p4gT1Av;$$A6h%{lAJ|w)SHj@RxuC zz}k&i^B2SIw;p%RGYq;E0P_43{sRP_@EV@O`>F?U7r-w-wg7~Sam(DCk*!OzE(d^G zVL9;se_jR%efW*vKySq|xNM5GYx&)kbV2~2f(VSGu>=;Q$hdbAwz?L7!pc5fK_?6V zDu-XbUIGxB@R0dtS123C7n#Z@>Tm R002ovPDHLkV1lr3z0p*+!u9|F literal 0 HcmV?d00001 diff --git a/tests-clar/resources/attr/.gitted/objects/ed/f3dcee4003d71f139777898882ccd097e34c53 b/tests-clar/resources/attr/.gitted/objects/ed/f3dcee4003d71f139777898882ccd097e34c53 new file mode 100644 index 0000000000000000000000000000000000000000..d28184670fc72db86d7342d0308a7bbbe5f33f57 GIT binary patch literal 6289 zcmV;C7;fiy0Re^>dFNtmZ(<-eGB!8>iBL{Q4GJ0x0000DNk~Le0000$0000$2nGNE z0IF$m-T(jq32;bRa{vGqB>(^xB>_oNB=7(L7%oXfK~#7F?OF+NRM(Zgy?3iy-P%A% z2!W75>|jO^2*M^{8*Ik`8@whd*LcZhCY73{QZYAwhtuBr08($oL_m-p_u+q?I^uS+JA z@qU>A*%FC_B+=vXxWr>IiAJLXI3A6~qVL4w@mCrS9z2!#{FOStq72a0)R^X&Ot+eh z#)m8x>w1gTYBrio0w#z-uM;3gSAXhUC#e-E$%{!afT;Kn=kY{R0A6Czs6>LnXebii z6^+GqG(@AXB@Z8t{-0yO{8g*An#|_Ewd6RKTdfu`o6Vw!#C1BIQ1UjjMO^tVaXRy) zurN>TR-2f?9JUBR4u*o#*XI?#-z&a;p9CXer3uu~1T-QNiAX3Emhe#EXfzV}aovFf zf4CA%xNHrmuBn-4vf2ODX3x3ZX0r(-FM0!19H8@Zb7gjAr7Wzfl=9N)lJ9Z?xK#`Q zo^5($R9rD4B>g_Ww05-1DR-lsYitznz<^>xBA$?NI3&SfP=bR){~Zku{@t0whwCqg z5tqe)`KwnyWXrMtG{@m^S^?fj8%HmhK3!HXUoMNQ=SqR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WaTBW(Z{-tBP-{ZFc1kaqG9)Hx5hwG!-MKwTsg9CyI)LEss zoG=lK`0zdN1MyjipaIs-Sly6{0Vrj!*Dvc3q`2$qWdDaBs@1}cqDS5F6H5KnKp2u9 zUZ2Ej0!^~R%Tu!VJ@hRpMIhAC-U+K>M#|ERP9pKtXSF?8Svs4W5r@?M=EUB;&wwt1 zXCmO8EO;;G^SAd6ZBV5pE(cVE9e z_=CSxvBB9h^)dz9Ysv($Y$-p0k;qq?K@<^OZ&$Z$-g>)SfBP0`Zf#TZXrXWz`LdfX~mMC>x45y3JfhESOd+iGIP!xaiio;hsec&4s;OtyaxeJ7dB!#8XFIt*tho|P^M>qqdC0Kr1qRs zYnRLb4ggKC;ow9kBOK_~#kIBfl~-0hP&9Lvz8Lv~3$Z~rP*Z9oIy?dX+yOJ*>%W;)|N93r#|_&4!64wj}t5-Jg)NuKPtn+^+~tO zW&mdb6S$gC1IP$=E}7OPwY7Jbme0DsVCGB<Rj3wlduN>K2>PMk4tS=gaMo!OrUV-9H|9l0?#c4 z)22_aT)go9;?mL^T_vRk#s*BQZIHgfn92{B$_5e3bEl^tzc>52vH8i~M;np(T0J^5~1kX;XYgU7w zSEgMR256*#5p<9mBgh1$4LGXg3P+j^8`YTwS=uz68XX<&T?2kujt=9D+pa1Dv{}Ij z0%s>Pc%<%YOu*?dc&azS)82!SIM1(Y`&<}61YiQCP2k+3W~X+fykLp}1kX;@4+H!a zadH@I!uGi_Ad?F4g3@PC2g9ifIxt`MvX(i|WX}H=GURP>?3~#q00000NkvXXu0mjf HkUYVmJKDxa literal 0 HcmV?d00001 From 28ef7f9b28a8b58946e553090f8967d7c51ebc78 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 3 May 2012 17:25:01 +0200 Subject: [PATCH 5/7] diff: make git_diff_blobs() able to detect binary blobs --- include/git2/diff.h | 1 + src/diff_output.c | 28 ++++++++ tests-clar/diff/blob.c | 123 ++++++++++++++++++++++++++++++--- tests-clar/diff/diff_helpers.c | 2 + tests-clar/diff/diff_helpers.h | 2 + 5 files changed, 146 insertions(+), 10 deletions(-) diff --git a/include/git2/diff.h b/include/git2/diff.h index 6afa608bb..f0f45022b 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -343,6 +343,7 @@ GIT_EXTERN(int) git_diff_blobs( git_blob *new_blob, git_diff_options *options, void *cb_data, + git_diff_file_fn file_cb, git_diff_hunk_fn hunk_cb, git_diff_data_fn line_cb); diff --git a/src/diff_output.c b/src/diff_output.c index dbcc89fa5..dadbe284f 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -298,6 +298,16 @@ static void release_content(git_diff_file *file, git_map *map, git_blob *blob) } } +static void fill_map_from_mmfile(git_map *dst, mmfile_t *src) { + assert(dst && src); + + dst->data = src->ptr; + dst->len = src->size; +#ifdef GIT_WIN32 + dst->fmh = NULL; +#endif +} + int git_diff_foreach( git_diff_list *diff, void *data, @@ -691,12 +701,14 @@ int git_diff_blobs( git_blob *new_blob, git_diff_options *options, void *cb_data, + git_diff_file_fn file_cb, git_diff_hunk_fn hunk_cb, git_diff_data_fn line_cb) { diff_output_info info; git_diff_delta delta; mmfile_t old_data, new_data; + git_map old_map, new_map; xpparam_t xdiff_params; xdemitconf_t xdiff_config; xdemitcb_t xdiff_callback; @@ -738,6 +750,22 @@ int git_diff_blobs( delta.old_file.size = old_data.size; delta.new_file.size = new_data.size; + fill_map_from_mmfile(&old_map, &old_data); + fill_map_from_mmfile(&new_map, &new_data); + + if (file_is_binary_by_content(&delta, &old_map, &new_map) < 0) + return -1; + + if (file_cb != NULL) { + int error = file_cb(cb_data, &delta, 1); + if (error < 0) + return error; + } + + /* don't do hunk and line diffs if file is binary */ + if (delta.binary == 1) + return 0; + info.diff = NULL; info.delta = δ info.cb_data = cb_data; diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c index 9364bdc6d..1bcb1f8e7 100644 --- a/tests-clar/diff/blob.c +++ b/tests-clar/diff/blob.c @@ -4,11 +4,11 @@ static git_repository *g_repo = NULL; static diff_expects exp; static git_diff_options opts; -static git_blob *d; +static git_blob *d, *alien; void test_diff_blob__initialize(void) { - git_oid d_oid; + git_oid oid; g_repo = cl_git_sandbox_init("attr"); @@ -19,13 +19,18 @@ void test_diff_blob__initialize(void) memset(&exp, 0, sizeof(exp)); /* tests/resources/attr/root_test4.txt */ - cl_git_pass(git_oid_fromstrn(&d_oid, "fe773770c5a6", 12)); - cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &d_oid, 6)); + cl_git_pass(git_oid_fromstrn(&oid, "fe773770c5a6", 12)); + cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 6)); + + /* alien.png */ + cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8)); + cl_git_pass(git_blob_lookup_prefix(&alien, g_repo, &oid, 4)); } void test_diff_blob__cleanup(void) { git_blob_free(d); + git_blob_free(alien); cl_git_sandbox_cleanup(); } @@ -50,7 +55,11 @@ void test_diff_blob__can_compare_text_blobs(void) /* Doing the equivalent of a `git diff -U1` on these files */ cl_git_pass(git_diff_blobs( - a, b, &opts, &exp, diff_hunk_fn, diff_line_fn)); + a, b, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.files == 1); + cl_assert(exp.file_mods == 1); + cl_assert(exp.at_least_one_of_them_is_binary == false); cl_assert(exp.hunks == 1); cl_assert(exp.lines == 6); @@ -60,7 +69,11 @@ void test_diff_blob__can_compare_text_blobs(void) memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_blobs( - b, c, &opts, &exp, diff_hunk_fn, diff_line_fn)); + b, c, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.files == 1); + cl_assert(exp.file_mods == 1); + cl_assert(exp.at_least_one_of_them_is_binary == false); cl_assert(exp.hunks == 1); cl_assert(exp.lines == 15); @@ -70,7 +83,11 @@ void test_diff_blob__can_compare_text_blobs(void) memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_blobs( - a, c, &opts, &exp, diff_hunk_fn, diff_line_fn)); + a, c, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.files == 1); + cl_assert(exp.file_mods == 1); + cl_assert(exp.at_least_one_of_them_is_binary == false); cl_assert(exp.hunks == 1); cl_assert(exp.lines == 13); @@ -82,7 +99,11 @@ void test_diff_blob__can_compare_text_blobs(void) memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_blobs( - c, d, &opts, &exp, diff_hunk_fn, diff_line_fn)); + c, d, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.files == 1); + cl_assert(exp.file_mods == 1); + cl_assert(exp.at_least_one_of_them_is_binary == false); cl_assert(exp.hunks == 2); cl_assert(exp.lines == 14); @@ -100,7 +121,11 @@ void test_diff_blob__can_compare_against_null_blobs(void) git_blob *e = NULL; cl_git_pass(git_diff_blobs( - d, e, &opts, &exp, diff_hunk_fn, diff_line_fn)); + d, e, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.files == 1); + cl_assert(exp.file_dels == 1); + cl_assert(exp.at_least_one_of_them_is_binary == false); cl_assert(exp.hunks == 1); cl_assert(exp.hunk_old_lines == 14); @@ -111,10 +136,88 @@ void test_diff_blob__can_compare_against_null_blobs(void) memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_blobs( - d, e, &opts, &exp, diff_hunk_fn, diff_line_fn)); + d, e, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.files == 1); + cl_assert(exp.file_adds == 1); + cl_assert(exp.at_least_one_of_them_is_binary == false); cl_assert(exp.hunks == 1); cl_assert(exp.hunk_new_lines == 14); cl_assert(exp.lines == 14); cl_assert(exp.line_adds == 14); + + opts.flags ^= GIT_DIFF_REVERSE; + memset(&exp, 0, sizeof(exp)); + + cl_git_pass(git_diff_blobs( + alien, NULL, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.at_least_one_of_them_is_binary == true); + + cl_assert(exp.files == 1); + cl_assert(exp.file_dels == 1); + cl_assert(exp.hunks == 0); + cl_assert(exp.lines == 0); + + memset(&exp, 0, sizeof(exp)); + + cl_git_pass(git_diff_blobs( + NULL, alien, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.at_least_one_of_them_is_binary == true); + + cl_assert(exp.files == 1); + cl_assert(exp.file_adds == 1); + cl_assert(exp.hunks == 0); + cl_assert(exp.lines == 0); +} + +void assert_binary_blobs_comparison(diff_expects exp) +{ + cl_assert(exp.at_least_one_of_them_is_binary == true); + + cl_assert(exp.files == 1); + cl_assert(exp.file_mods == 1); + cl_assert(exp.hunks == 0); + cl_assert(exp.lines == 0); +} + +void test_diff_blob__can_compare_two_binary_blobs(void) +{ + git_blob *heart; + git_oid h_oid; + + /* heart.png */ + cl_git_pass(git_oid_fromstrn(&h_oid, "de863bff", 8)); + cl_git_pass(git_blob_lookup_prefix(&heart, g_repo, &h_oid, 4)); + + cl_git_pass(git_diff_blobs( + alien, heart, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + assert_binary_blobs_comparison(exp); + + memset(&exp, 0, sizeof(exp)); + + cl_git_pass(git_diff_blobs( + heart, alien, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + assert_binary_blobs_comparison(exp); + + git_blob_free(heart); +} + +void test_diff_blob__can_compare_a_binary_blob_and_a_text_blob(void) +{ + cl_git_pass(git_diff_blobs( + alien, d, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + assert_binary_blobs_comparison(exp); + + memset(&exp, 0, sizeof(exp)); + + cl_git_pass(git_diff_blobs( + d, alien, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + assert_binary_blobs_comparison(exp); } diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c index 74a44ab99..b12d88868 100644 --- a/tests-clar/diff/diff_helpers.c +++ b/tests-clar/diff/diff_helpers.c @@ -30,6 +30,8 @@ int diff_file_fn( GIT_UNUSED(progress); + e-> at_least_one_of_them_is_binary = delta->binary; + e->files++; switch (delta->status) { case GIT_DELTA_ADDED: e->file_adds++; break; diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h index ca8c40177..994af0f76 100644 --- a/tests-clar/diff/diff_helpers.h +++ b/tests-clar/diff/diff_helpers.h @@ -20,6 +20,8 @@ typedef struct { int line_ctxt; int line_adds; int line_dels; + + bool at_least_one_of_them_is_binary; } diff_expects; extern int diff_file_fn( From 9a29f8d56c37803a67af3ff4bc4c8724a126366f Mon Sep 17 00:00:00 2001 From: nulltoken Date: Fri, 4 May 2012 07:55:09 +0200 Subject: [PATCH 6/7] diff: fix the diffing of two identical blobs --- src/diff_output.c | 8 ++++++++ tests-clar/diff/blob.c | 31 +++++++++++++++++++++++++++++++ tests-clar/diff/diff_helpers.c | 1 + tests-clar/diff/diff_helpers.h | 1 + tests-clar/diff/tree.c | 18 +++++++++--------- 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/diff_output.c b/src/diff_output.c index dadbe284f..9c8e07972 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -747,6 +747,10 @@ int git_diff_blobs( delta.status = new ? (old ? GIT_DELTA_MODIFIED : GIT_DELTA_ADDED) : (old ? GIT_DELTA_DELETED : GIT_DELTA_UNTRACKED); + + if (git_oid_cmp(&delta.new_file.oid, &delta.old_file.oid) == 0) + delta.status = GIT_DELTA_UNMODIFIED; + delta.old_file.size = old_data.size; delta.new_file.size = new_data.size; @@ -762,6 +766,10 @@ int git_diff_blobs( return error; } + /* don't do hunk and line diffs if the two blobs are identical */ + if (delta.status == GIT_DELTA_UNMODIFIED) + return 0; + /* don't do hunk and line diffs if file is binary */ if (delta.binary == 1) return 0; diff --git a/tests-clar/diff/blob.c b/tests-clar/diff/blob.c index 1bcb1f8e7..cceb00d25 100644 --- a/tests-clar/diff/blob.c +++ b/tests-clar/diff/blob.c @@ -173,6 +173,37 @@ void test_diff_blob__can_compare_against_null_blobs(void) cl_assert(exp.lines == 0); } +void assert_identical_blobs_comparison(diff_expects exp) +{ + cl_assert(exp.files == 1); + cl_assert(exp.file_unmodified == 1); + cl_assert(exp.hunks == 0); + cl_assert(exp.lines == 0); +} + +void test_diff_blob__can_compare_identical_blobs(void) +{ + cl_git_pass(git_diff_blobs( + d, d, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.at_least_one_of_them_is_binary == false); + assert_identical_blobs_comparison(exp); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_blobs( + NULL, NULL, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.at_least_one_of_them_is_binary == false); + assert_identical_blobs_comparison(exp); + + memset(&exp, 0, sizeof(exp)); + cl_git_pass(git_diff_blobs( + alien, alien, &opts, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); + + cl_assert(exp.at_least_one_of_them_is_binary == true); + assert_identical_blobs_comparison(exp); +} + void assert_binary_blobs_comparison(diff_expects exp) { cl_assert(exp.at_least_one_of_them_is_binary == true); diff --git a/tests-clar/diff/diff_helpers.c b/tests-clar/diff/diff_helpers.c index b12d88868..8587be9b1 100644 --- a/tests-clar/diff/diff_helpers.c +++ b/tests-clar/diff/diff_helpers.c @@ -39,6 +39,7 @@ int diff_file_fn( case GIT_DELTA_MODIFIED: e->file_mods++; break; case GIT_DELTA_IGNORED: e->file_ignored++; break; case GIT_DELTA_UNTRACKED: e->file_untracked++; break; + case GIT_DELTA_UNMODIFIED: e->file_unmodified++; break; default: break; } return 0; diff --git a/tests-clar/diff/diff_helpers.h b/tests-clar/diff/diff_helpers.h index 994af0f76..0aaa6c111 100644 --- a/tests-clar/diff/diff_helpers.h +++ b/tests-clar/diff/diff_helpers.h @@ -11,6 +11,7 @@ typedef struct { int file_mods; int file_ignored; int file_untracked; + int file_unmodified; int hunks; int hunk_new_lines; diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index 06f51a16b..b932fa10e 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -113,16 +113,16 @@ void test_diff_tree__options(void) */ diff_expects test_expects[] = { /* a vs b tests */ - { 5, 3, 0, 2, 0, 0, 4, 0, 0, 51, 2, 46, 3 }, - { 5, 3, 0, 2, 0, 0, 4, 0, 0, 53, 4, 46, 3 }, - { 5, 0, 3, 2, 0, 0, 4, 0, 0, 52, 3, 3, 46 }, - { 5, 3, 0, 2, 0, 0, 5, 0, 0, 54, 3, 48, 3 }, + { 5, 3, 0, 2, 0, 0, 0, 4, 0, 0, 51, 2, 46, 3 }, + { 5, 3, 0, 2, 0, 0, 0, 4, 0, 0, 53, 4, 46, 3 }, + { 5, 0, 3, 2, 0, 0, 0, 4, 0, 0, 52, 3, 3, 46 }, + { 5, 3, 0, 2, 0, 0, 0, 5, 0, 0, 54, 3, 48, 3 }, /* c vs d tests */ - { 1, 0, 0, 1, 0, 0, 1, 0, 0, 22, 9, 10, 3 }, - { 1, 0, 0, 1, 0, 0, 1, 0, 0, 19, 12, 7, 0 }, - { 1, 0, 0, 1, 0, 0, 1, 0, 0, 20, 11, 8, 1 }, - { 1, 0, 0, 1, 0, 0, 1, 0, 0, 20, 11, 8, 1 }, - { 1, 0, 0, 1, 0, 0, 1, 0, 0, 18, 11, 0, 7 }, + { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 22, 9, 10, 3 }, + { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 19, 12, 7, 0 }, + { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 11, 8, 1 }, + { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 20, 11, 8, 1 }, + { 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 18, 11, 0, 7 }, { 0 }, }; diff_expects *expected; From d1c4312a021eb165d21b7390607f2b2bcba098ae Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 3 May 2012 22:21:08 +0200 Subject: [PATCH 7/7] diff: improve git_diff_blobs() documentation --- include/git2/diff.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/git2/diff.h b/include/git2/diff.h index f0f45022b..bafe6268c 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -337,6 +337,14 @@ GIT_EXTERN(int) git_diff_print_patch( /** * Directly run a text diff on two blobs. + * + * Compared to a file, a blob lacks some contextual information. As such, the + * `git_diff_file` parameters of the callbacks will be filled accordingly to the following: + * `mode` will be set to 0, `path` will be set to NULL. When dealing with a NULL blob, `oid` + * will be set to 0. + * + * When at least one of the blobs being dealt with is binary, the `git_diff_delta` binary + * attribute will be set to 1 and no call to the hunk_cb nor line_cb will be made. */ GIT_EXTERN(int) git_diff_blobs( git_blob *old_blob,