Commit e72ade87fdb3acf3cbb6bf6d52cd774d924e0e2c

Kevin Swinton 2020-04-18T11:32:56

Fix binary diff showing /dev/null Fixes issue where a changed binary file's content in the working tree isn't displayed correctly, instead showing an oid of zero, and with its path being reported incorrectly as "/dev/null".

diff --git a/src/patch_generate.c b/src/patch_generate.c
index 18256d0..6dd61c1 100644
--- a/src/patch_generate.c
+++ b/src/patch_generate.c
@@ -209,9 +209,7 @@ static int patch_generated_load(git_patch_generated *patch, git_patch_generated_
 
 	if ((error = git_diff_file_content__load(
 			&patch->ofile, &patch->base.diff_opts)) < 0 ||
-		should_skip_binary(patch, patch->ofile.file))
-		goto cleanup;
-	if ((error = git_diff_file_content__load(
+	    (error = git_diff_file_content__load(
 			&patch->nfile, &patch->base.diff_opts)) < 0 ||
 		should_skip_binary(patch, patch->nfile.file))
 		goto cleanup;
diff --git a/tests/diff/format_email.c b/tests/diff/format_email.c
index 28f840a..bdfc4ca 100644
--- a/tests/diff/format_email.c
+++ b/tests/diff/format_email.c
@@ -487,7 +487,7 @@ void test_diff_format_email__binary(void)
 	"Subject: [PATCH] Modified binary file\n" \
 	"\n" \
 	"---\n" \
-	" binary.bin | Bin 3 -> 0 bytes\n" \
+	" binary.bin | Bin 3 -> 5 bytes\n" \
 	" 1 file changed, 0 insertions(+), 0 deletions(-)\n" \
 	"\n" \
 	"diff --git a/binary.bin b/binary.bin\n" \
@@ -496,7 +496,6 @@ void test_diff_format_email__binary(void)
 	"--\n" \
 	"libgit2 " LIBGIT2_VERSION "\n" \
 	"\n";
-	/* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */
 
 	opts.summary = "Modified binary file";
 
diff --git a/tests/diff/stats.c b/tests/diff/stats.c
index 1503556..8bd7263 100644
--- a/tests/diff/stats.c
+++ b/tests/diff/stats.c
@@ -298,9 +298,8 @@ void test_diff_stats__binary(void)
 {
 	git_buf buf = GIT_BUF_INIT;
 	const char *stat =
-	" binary.bin | Bin 3 -> 0 bytes\n"
+	" binary.bin | Bin 3 -> 5 bytes\n"
 	" 1 file changed, 0 insertions(+), 0 deletions(-)\n";
-	/* TODO: Actually 0 bytes here should be 5!. Seems like we don't load the new content for binary files? */
 
 	diff_stats_from_commit_oid(
 		&_stats, "8d7523f6fcb2404257889abe0d96f093d9f524f9", false);