Skip to content

Commit 30b14ed

Browse files
committed
git-gui: Elide CRs appearing in diff output from display.
If we are displaying a diff for a DOS-style (CRLF) formatted file then the Tk text widget would normally show the CR at the end of every line; in most fonts this will come out as a square box. Rather than showing this character we'll tag it with a tag which forces the character to be elided away, so its not displayed. However since the character is still within the text buffer we can still obtain it and supply it over to `git apply` when staging or unstaging an individual hunk, ensuring that the file contents is always fully preserved as-is. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent a25c518 commit 30b14ed

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

git-gui.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,9 @@ proc read_diff {fd} {
793793
}
794794
}
795795
$ui_diff insert end $line $tags
796+
if {[string index $line end] eq "\r"} {
797+
$ui_diff tag add d_cr {end - 2c}
798+
}
796799
$ui_diff insert end "\n" $tags
797800
}
798801
$ui_diff conf -state disabled
@@ -4304,6 +4307,7 @@ pack $ui_diff -side left -fill both -expand 1
43044307
pack .vpane.lower.diff.header -side top -fill x
43054308
pack .vpane.lower.diff.body -side bottom -fill both -expand 1
43064309

4310+
$ui_diff tag conf d_cr -elide true
43074311
$ui_diff tag conf d_@ -foreground blue -font font_diffbold
43084312
$ui_diff tag conf d_+ -foreground {#00a000}
43094313
$ui_diff tag conf d_- -foreground red

0 commit comments

Comments
 (0)