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>
Shawn O. Pearce committed
Nov 11, 2006 at 17:59 UTC
68e009dec44a023efd6f6fcd61c1583b23b04f32
1 file changed
+13
-8
git-gui
+13
-8
@@ -385,9 +385,9 @@ proc show_diff {path {w {}} {lno {}}} {
385
set m [lindex $s 0]
386
set diff_3way 0
387
set diff_active 1
388
- set ui_fname_value $path
388
+ set ui_fname_value [escape_path $path]
389
set ui_fstatus_value [mapdesc $m $path]
390
- set ui_status_value "Loading diff of $path..."
390
+ set ui_status_value "Loading diff of [escape_path $path]..."
391
392
set cmd [list | git diff-index -p $PARENT -- $path]
393
switch $m {
@@ -404,7 +404,7 @@ proc show_diff {path {w {}} {lno {}}} {
404
} err ]} {
405
set diff_active 0
406
unlock_index
407
- set ui_status_value "Unable to display $path"
407
+ set ui_status_value "Unable to display [escape_path $path]"
408
error_popup "Error loading file:\n$err"
409
return
410
}
@@ -421,7 +421,7 @@ proc show_diff {path {w {}} {lno {}}} {
421
if {[catch {set fd [open $cmd r]} err]} {
422
set diff_active 0
423
unlock_index
424
- set ui_status_value "Unable to display $path"
424
+ set ui_status_value "Unable to display [escape_path $path]"
425
error_popup "Error loading diff:\n$err"
426
return
427
}
@@ -569,7 +569,7 @@ before committing.
569
U* {
570
error_popup "Unmerged files cannot be committed.
571
572
-File $path has merge conflicts.
572
+File [escape_path $path] has merge conflicts.
573
You must resolve them and include the file before committing.
574
"
575
unlock_index
@@ -578,7 +578,7 @@ You must resolve them and include the file before committing.
578
default {
579
error_popup "Unknown file state [lindex $s 0] detected.
580
581
-File $path cannot be committed by this program.
581
+File [escape_path $path] cannot be committed by this program.
582
"
583
}
584
}
@@ -842,6 +842,11 @@ proc mapdesc {state path} {
842
return $r
843
}
844
845
+proc escape_path {path} {
846
+ regsub -all "\n" $path "\\n" path
847
+ return $path
848
+}
849
+
850
set next_icon_id 0
851
852
proc merge_state {path new_state} {
@@ -905,7 +910,7 @@ proc display_file {path state} {
910
-align center -padx 5 -pady 1 \
911
-name [lindex $s 1] \
912
-image $new_icon
908
- $new_w insert $lno.1 "$path\n"
913
+ $new_w insert $lno.1 "[escape_path $path]\n"
914
$new_w conf -state disabled
915
} elseif {$new_icon != [mapicon $old_m $path]} {
916
$new_w conf -state normal
@@ -929,7 +934,7 @@ proc display_all_files {} {
934
-align center -padx 5 -pady 1 \
935
-name [lindex $s 1] \
936
-image [mapicon $m $path]
932
- $w insert end "$path\n"
937
+ $w insert end "[escape_path $path]\n"
938
}
939
940
$ui_index conf -state disabled