aboutsummaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-09-10 02:14:18 -0700
committerJunio C Hamano <gitster@pobox.com>2008-09-10 02:14:18 -0700
commit26c10c7ad39357bd94129c3949fed67c39302b0f (patch)
tree88ffbda22c14a4fd3778623ee31afeb09915e71f /diff.c
parent94c27881bd98d5bb70e3d4f8a18e384095c876b9 (diff)
parent392809702016cde59d50a7b07e8c27f6d0ec3c3f (diff)
downloadgit-26c10c7ad39357bd94129c3949fed67c39302b0f.tar.gz
git-26c10c7ad39357bd94129c3949fed67c39302b0f.tar.xz
Merge branch 'jc/maint-hide-cr-in-diff-from-less' into maint
* jc/maint-hide-cr-in-diff-from-less: diff: Help "less" hide ^M from the output
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/diff.c b/diff.c
index b3a7da70a..5e01b2bb2 100644
--- a/diff.c
+++ b/diff.c
@@ -511,13 +511,20 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
{
- int has_trailing_newline = (len > 0 && line[len-1] == '\n');
+ int has_trailing_newline, has_trailing_carriage_return;
+
+ has_trailing_newline = (len > 0 && line[len-1] == '\n');
if (has_trailing_newline)
len--;
+ has_trailing_carriage_return = (len > 0 && line[len-1] == '\r');
+ if (has_trailing_carriage_return)
+ len--;
fputs(set, file);
fwrite(line, len, 1, file);
fputs(reset, file);
+ if (has_trailing_carriage_return)
+ fputc('\r', file);
if (has_trailing_newline)
fputc('\n', file);
}