git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] diff: bugfix: binary file permission regression

From
Nazri Ramliy <ayiehere@gmail.com>
Date
Jun 10, 2010, 18:31 UTC
Message-ID
<1276194685-28098-1-git-send-email-ayiehere@gmail.com>

Regression at 3e97c7c6af2901cec63bf35fcd43ae3472e24af8 "No diff -b/-w output for all-whitespace changes"

When a binary file's permission is modified, git status reports the file as modified, but git diff shows nothing.

Add a test file too.
---
 diff.c                            |    4 ++--
 t/t4043-diff-binary-permission.sh |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100755 t/t4043-diff-binary-permission.sh
diff --git a/diff.c b/diff.c
index 494f560..0aa1a2d 100644
--- a/diff.c
+++ b/diff.c
@@ -1745,12 +1745,12 @@ static void builtin_diff(const char *name_a,
 	      (!textconv_two && diff_filespec_is_binary(two)) )) {
 		if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
 			die("unable to read files to diff");
+		fprintf(o->file, "%s", header.buf);
+		strbuf_reset(&header);
 		/* Quite common confusing case */
 		if (mf1.size == mf2.size &&
 		    !memcmp(mf1.ptr, mf2.ptr, mf1.size))
 			goto free_ab_and_return;
-		fprintf(o->file, "%s", header.buf);
-		strbuf_reset(&header);
 		if (DIFF_OPT_TST(o, BINARY))
 			emit_binary_diff(o->file, &mf1, &mf2);
 		else
diff --git a/t/t4043-diff-binary-permission.sh b/t/t4043-diff-binary-permission.sh
new file mode 100755
index 0000000..7b77fb3
--- /dev/null
+++ b/t/t4043-diff-binary-permission.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Nazri Ramliy
+#
+
+test_description='Test permission change on binary files
+
+'
+. ./test-lib.sh
+
+/bin/echo -e "\0\0\0\0" > a.bin
+chmod 644 a.bin
+git update-index --add a.bin
+chmod 755 a.bin
+
+cat << EOF > expect
+diff --git a/a.bin b/a.bin
+old mode 100644
+new mode 100755
+EOF
+
+git diff > out
+
+test_expect_success 'diff-binary-permission' 'test_cmp expect out'
+
+test_done
-- 
1.7.1.245.g7c42e.dirty
Next: Nazri Ramliy
Message 1 of 4 in “diff: bugfix: binary file permission regression”
  1. diff: bugfix: binary file permission regressionNazri Ramliy, Jun 10, 2010
  2. Nazri RamliyJun 11, 2010
  3. Christian CouderJun 11, 2010
  4. Nazri RamliyJun 11, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.