git-gui: Fix diff parsing for lines starting with "--" or "++"
Languages like Lua and SQL use "--" to mark a line as commented out. If this appears at column 0 and is part of the pre-image we may see "--- foo" in the diff, indicating that the line whose content is "-- foo" has been removed from the new version. git-gui was incorrectly parsing "--- foo" as the old file name in the file header, causing it to generate a bad patch file when the user tried to stage or unstage a hunk or the selected line. We need to keep track of where we are in the parsing so that we do not misread a deletion or addition record as part of the header. Reported-by: Alexander Gladysh <agladysh@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
9dc3793166
commit
ca53c3fdcf
18
lib/diff.tcl
18
lib/diff.tcl
@ -192,6 +192,7 @@ proc show_diff {path w {lno {}} {scroll_pos {}}} {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set ::current_diff_inheader 1
|
||||||
fconfigure $fd \
|
fconfigure $fd \
|
||||||
-blocking 0 \
|
-blocking 0 \
|
||||||
-encoding binary \
|
-encoding binary \
|
||||||
@ -207,18 +208,21 @@ proc read_diff {fd scroll_pos} {
|
|||||||
while {[gets $fd line] >= 0} {
|
while {[gets $fd line] >= 0} {
|
||||||
# -- Cleanup uninteresting diff header lines.
|
# -- Cleanup uninteresting diff header lines.
|
||||||
#
|
#
|
||||||
if { [string match {diff --git *} $line]
|
if {$::current_diff_inheader} {
|
||||||
|| [string match {diff --cc *} $line]
|
if { [string match {diff --git *} $line]
|
||||||
|| [string match {diff --combined *} $line]
|
|| [string match {diff --cc *} $line]
|
||||||
|| [string match {--- *} $line]
|
|| [string match {diff --combined *} $line]
|
||||||
|| [string match {+++ *} $line]} {
|
|| [string match {--- *} $line]
|
||||||
append current_diff_header $line "\n"
|
|| [string match {+++ *} $line]} {
|
||||||
continue
|
append current_diff_header $line "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if {[string match {index *} $line]} continue
|
if {[string match {index *} $line]} continue
|
||||||
if {$line eq {deleted file mode 120000}} {
|
if {$line eq {deleted file mode 120000}} {
|
||||||
set line "deleted symlink"
|
set line "deleted symlink"
|
||||||
}
|
}
|
||||||
|
set ::current_diff_inheader 0
|
||||||
|
|
||||||
# -- Automatically detect if this is a 3 way diff.
|
# -- Automatically detect if this is a 3 way diff.
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user