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

[PATCH] Teach --text option to diff

From
SFStephan Feder <sf@b-i-t.de>
Date
Jul 7, 2006, 10:33 UTC
Message-ID
<11522684373987-git-send-email-sf@b-i-t.de>

Add new item text to struct diff_options. If set then do not try to detect binary files.

Signed-off-by: Stephan Feder <sf@b-i-t.de>
---

I have to send patches of binary data to a customer but the builtin diff was no help in this case.

Notes:
1. The shorthand -a for --text is not implemented. Is there a conflicting
shorthand?
2. For diffstat --text is ignored. It seems pointless because binary
patch data is not for human consumption anyway.
3. No documentation yet. If the patch is accepted I will add a short
description. To Documentation/diff-options.txt?
Regards
    Stephan
 diff.c |    5 ++++-
 diff.h |    1 +
 2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/diff.c b/diff.c
index f0450a8..1f0219d 100644
--- a/diff.c
+++ b/diff.c
@@ -723,7 +723,7 @@ static void builtin_diff(const char *nam
 	if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
 		die("unable to read files to diff");
 
-	if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) {
+	if (!o->text && (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2))) {
 		/* Quite common confusing case */
 		if (mf1.size == mf2.size &&
 		    !memcmp(mf1.ptr, mf2.ptr, mf1.size))
@@ -1561,6 +1561,9 @@ int diff_opt_parse(struct diff_options *
 		options->output_format |= DIFF_FORMAT_PATCH;
 		options->full_index = options->binary = 1;
 	}
+	else if (!strcmp(arg, "--text")) {
+		options->text = 1;
+	}
 	else if (!strcmp(arg, "--name-only"))
 		options->output_format |= DIFF_FORMAT_NAME;
 	else if (!strcmp(arg, "--name-status"))
diff --git a/diff.h b/diff.h
index d557394..f80f646 100644
--- a/diff.h
+++ b/diff.h
@@ -42,6 +42,7 @@ struct diff_options {
 	unsigned recursive:1,
 		 tree_in_recursive:1,
 		 binary:1,
+		 text:1,
 		 full_index:1,
 		 silent_on_remove:1,
 		 find_copies_harder:1,
-- 
1.4.1.gbc483
Next: Junio C Hamano
Message 1 of 6 in “Teach --text option to diff”
  1. Teach --text option to diffStephan Feder, Jul 7, 2006
  2. Junio C HamanoJul 7, 2006
  3. sfJul 7, 2006
  4. 1/3 Teach diff -a as shorthand for --textStephan Feder, Jul 7, 2006
  5. 2/3 Add -a and --text to common diff options helpStephan Feder, Jul 7, 2006
  6. 3/3 diff-options: Explain --text and -aStephan Feder, Jul 7, 2006

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.