From: Junio C Hamano Date: Thu, 28 Aug 2008 02:48:01 +0000 (-0700) Subject: diff: Help "less" hide ^M from the output X-Git-Tag: v1.6.0.2~11^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/392809702016cde59d50a7b07e8c27f6d0ec3c3f?hp=392809702016cde59d50a7b07e8c27f6d0ec3c3f diff: Help "less" hide ^M from the output When the tracked contents have CRLF line endings, colored diff output shows "^M" at the end of output lines, which is distracting, even though the pager we use by default ("less") knows to hide them. The problem is that "less" hides a carriage-return only at the end of the line, immediately before a line feed. The colored diff output does not take this into account, and emits four element sequence for each line: - force this color; - the line up to but not including the terminating line feed; - reset color - line feed. By including the carriage return at the end of the line in the second item, we are breaking the smart our pager has in order not to show "^M". This can be fixed by changing the sequence to: - force this color; - the line up to but not including the terminating end-of-line; - reset color - end-of-line. where end-of-line is either a single linefeed or a CRLF pair. When the output is not colored, "force this color" and "reset color" sequences are both empty, so we won't have this problem with or without this patch. Signed-off-by: Junio C Hamano ---