git-gui: Only reshow diff when really necessary.
I noticed that we were reshowing the current diff during a commit; this occurs because we feed every added and modified file through update-index just before commit. During the update-index process we reshow the current diff if the current file in the diff pane was one of those added or modified files we reprocessed. This just slows down the UI more than is necessary. So refactoring update_index so that we don't call reshow_diff from within that code; instead we do it at a higher level. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 18, 2006 at 03:03 UTC
32e0bcab59334ed8f1955c8afa830de22362c1ec
1 file changed
+21
-17
git-gui
+21
-17
@@ -1251,12 +1251,11 @@ proc display_all_files {} {
1251
}
1252
1253
proc update_index {msg pathList after} {
1254
- global update_index_cp update_index_rsd ui_status_value
1254
+ global update_index_cp ui_status_value
1255
1256
if {![lock_index update]} return
1257
1258
set update_index_cp 0
1259
- set update_index_rsd 0
1259
set pathList [lsort $pathList]
1260
set totalCnt [llength $pathList]
1261
set batch [expr {int($totalCnt * .01) + 1}]
@@ -1285,13 +1284,12 @@ proc update_index {msg pathList after} {
1284
}
1285
1286
proc write_update_index {fd pathList totalCnt batch msg after} {
1288
- global update_index_cp update_index_rsd ui_status_value
1287
+ global update_index_cp ui_status_value
1288
global file_states current_diff
1289
1290
if {$update_index_cp >= $totalCnt} {
1291
close $fd
1292
unlock_index
1294
- if {$update_index_rsd} reshow_diff
1293
uplevel #0 $after
1294
return
1295
}
@@ -1321,9 +1319,6 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
1319
puts -nonewline $fd $path
1320
puts -nonewline $fd "\0"
1321
display_file $path $new
1324
- if {$current_diff eq $path} {
1325
- set update_index_rsd 1
1326
- }
1322
}
1323
1324
set ui_status_value [format \
@@ -1859,19 +1854,23 @@ proc do_rescan {} {
1854
}
1855
1856
proc do_include_all {} {
1862
- global file_states
1857
+ global file_states current_diff
1858
1859
if {![lock_index begin-update]} return
1860
1861
set pathList [list]
1862
+ set after {}
1863
foreach path [array names file_states] {
1868
- set s $file_states($path)
1869
- set m [lindex $s 0]
1870
- switch -- $m {
1864
+ switch -- [lindex $file_states($path) 0] {
1865
AM -
1866
MM -
1867
_M -
1874
- _D {lappend pathList $path}
1868
+ _D {
1869
+ lappend pathList $path
1870
+ if {$path eq $current_diff} {
1871
+ set after {reshow_diff;}
1872
+ }
1873
+ }
1874
}
1875
}
1876
if {$pathList eq {}} {
@@ -1880,7 +1879,7 @@ proc do_include_all {} {
1879
update_index \
1880
"Including all modified files" \
1881
$pathList \
1883
- {set ui_status_value {Ready to commit.}}
1882
+ [concat $after {set ui_status_value {Ready to commit.}}]
1883
}
1884
}
1885
@@ -2204,7 +2203,7 @@ proc do_macosx_app {} {
2203
}
2204
2205
proc toggle_or_diff {w x y} {
2207
- global file_lists ui_index ui_other
2206
+ global file_lists current_diff ui_index ui_other
2207
global last_clicked selected_paths
2208
2209
set pos [split [$w index @$x,$y] .]
@@ -2222,10 +2221,15 @@ proc toggle_or_diff {w x y} {
2221
$ui_other tag remove in_sel 0.0 end
2222
2223
if {$col == 0} {
2224
+ if {$current_diff eq $path} {
2225
+ set after {reshow_diff;}
2226
+ } else {
2227
+ set after {}
2228
+ }
2229
update_index \
2230
"Including [short_path $path]" \
2231
[list $path] \
2228
- {set ui_status_value {Ready.}}
2232
+ [concat $after {set ui_status_value {Ready.}}]
2233
} else {
2234
show_diff $path $w $lno
2235
}
@@ -2642,7 +2646,7 @@ bind_button3 $ui_comm "tk_popup $ctxm %X %Y"
2646
# -- Diff Header
2647
set current_diff {}
2648
set diff_actions [list]
2645
-proc current_diff_trace {varname args} {
2649
+proc trace_current_diff {varname args} {
2650
global current_diff diff_actions file_states
2651
if {$current_diff eq {}} {
2652
set s {}
@@ -2664,7 +2668,7 @@ proc current_diff_trace {varname args} {
2668
uplevel #0 $w $o
2669
}
2670
}
2667
-trace add variable current_diff write current_diff_trace
2671
+trace add variable current_diff write trace_current_diff
2672
2673
frame .vpane.lower.diff.header -background orange
2674
label .vpane.lower.diff.header.status \