Skip to content

Commit 6d64ea9

Browse files
Stephan FederJunio C Hamano
authored andcommitted
Teach --text option to diff
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 6bdca89 commit 6d64ea9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ static void builtin_diff(const char *name_a,
723723
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
724724
die("unable to read files to diff");
725725

726-
if (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2)) {
726+
if (!o->text && (mmfile_is_binary(&mf1) || mmfile_is_binary(&mf2))) {
727727
/* Quite common confusing case */
728728
if (mf1.size == mf2.size &&
729729
!memcmp(mf1.ptr, mf2.ptr, mf1.size))
@@ -1561,6 +1561,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
15611561
options->output_format |= DIFF_FORMAT_PATCH;
15621562
options->full_index = options->binary = 1;
15631563
}
1564+
else if (!strcmp(arg, "--text")) {
1565+
options->text = 1;
1566+
}
15641567
else if (!strcmp(arg, "--name-only"))
15651568
options->output_format |= DIFF_FORMAT_NAME;
15661569
else if (!strcmp(arg, "--name-status"))

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct diff_options {
4242
unsigned recursive:1,
4343
tree_in_recursive:1,
4444
binary:1,
45+
text:1,
4546
full_index:1,
4647
silent_on_remove:1,
4748
find_copies_harder:1,

0 commit comments

Comments
 (0)