git-gui: Correctly handle files containing LF in their name.

If we are given a file whose path name contains an LF (\n) we now
escape it by inserting the common escape string \n instead of the
LF character whenever we display the name in the UI.  This way the
text fields don't start to span multiple lines just to display one
file, and it keeps the line numbers correct within the file lists.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
maint
Shawn O. Pearce 2006-11-11 17:59:34 -05:00
parent 03e4ec5364
commit 68e009dec4
1 changed files with 13 additions and 8 deletions

21
git-gui
View File

@ -385,9 +385,9 @@ proc show_diff {path {w {}} {lno {}}} {
set m [lindex $s 0] set m [lindex $s 0]
set diff_3way 0 set diff_3way 0
set diff_active 1 set diff_active 1
set ui_fname_value $path set ui_fname_value [escape_path $path]
set ui_fstatus_value [mapdesc $m $path] set ui_fstatus_value [mapdesc $m $path]
set ui_status_value "Loading diff of $path..." set ui_status_value "Loading diff of [escape_path $path]..."


set cmd [list | git diff-index -p $PARENT -- $path] set cmd [list | git diff-index -p $PARENT -- $path]
switch $m { switch $m {
@ -404,7 +404,7 @@ proc show_diff {path {w {}} {lno {}}} {
} err ]} { } err ]} {
set diff_active 0 set diff_active 0
unlock_index unlock_index
set ui_status_value "Unable to display $path" set ui_status_value "Unable to display [escape_path $path]"
error_popup "Error loading file:\n$err" error_popup "Error loading file:\n$err"
return return
} }
@ -421,7 +421,7 @@ proc show_diff {path {w {}} {lno {}}} {
if {[catch {set fd [open $cmd r]} err]} { if {[catch {set fd [open $cmd r]} err]} {
set diff_active 0 set diff_active 0
unlock_index unlock_index
set ui_status_value "Unable to display $path" set ui_status_value "Unable to display [escape_path $path]"
error_popup "Error loading diff:\n$err" error_popup "Error loading diff:\n$err"
return return
} }
@ -569,7 +569,7 @@ before committing.
U* { U* {
error_popup "Unmerged files cannot be committed. error_popup "Unmerged files cannot be committed.


File $path has merge conflicts. File [escape_path $path] has merge conflicts.
You must resolve them and include the file before committing. You must resolve them and include the file before committing.
" "
unlock_index unlock_index
@ -578,7 +578,7 @@ You must resolve them and include the file before committing.
default { default {
error_popup "Unknown file state [lindex $s 0] detected. error_popup "Unknown file state [lindex $s 0] detected.


File $path cannot be committed by this program. File [escape_path $path] cannot be committed by this program.
" "
} }
} }
@ -842,6 +842,11 @@ proc mapdesc {state path} {
return $r return $r
} }


proc escape_path {path} {
regsub -all "\n" $path "\\n" path
return $path
}

set next_icon_id 0 set next_icon_id 0


proc merge_state {path new_state} { proc merge_state {path new_state} {
@ -905,7 +910,7 @@ proc display_file {path state} {
-align center -padx 5 -pady 1 \ -align center -padx 5 -pady 1 \
-name [lindex $s 1] \ -name [lindex $s 1] \
-image $new_icon -image $new_icon
$new_w insert $lno.1 "$path\n" $new_w insert $lno.1 "[escape_path $path]\n"
$new_w conf -state disabled $new_w conf -state disabled
} elseif {$new_icon != [mapicon $old_m $path]} { } elseif {$new_icon != [mapicon $old_m $path]} {
$new_w conf -state normal $new_w conf -state normal
@ -929,7 +934,7 @@ proc display_all_files {} {
-align center -padx 5 -pady 1 \ -align center -padx 5 -pady 1 \
-name [lindex $s 1] \ -name [lindex $s 1] \
-image [mapicon $m $path] -image [mapicon $m $path]
$w insert end "$path\n" $w insert end "[escape_path $path]\n"
} }


$ui_index conf -state disabled $ui_index conf -state disabled