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>
diff --git a/git-gui b/git-gui
index e2e0bea..62545b7 100755
--- a/git-gui
+++ b/git-gui
@@ -1251,12 +1251,11 @@
}
proc update_index {msg pathList after} {
- global update_index_cp update_index_rsd ui_status_value
+ global update_index_cp ui_status_value
if {![lock_index update]} return
set update_index_cp 0
- set update_index_rsd 0
set pathList [lsort $pathList]
set totalCnt [llength $pathList]
set batch [expr {int($totalCnt * .01) + 1}]
@@ -1285,13 +1284,12 @@
}
proc write_update_index {fd pathList totalCnt batch msg after} {
- global update_index_cp update_index_rsd ui_status_value
+ global update_index_cp ui_status_value
global file_states current_diff
if {$update_index_cp >= $totalCnt} {
close $fd
unlock_index
- if {$update_index_rsd} reshow_diff
uplevel #0 $after
return
}
@@ -1321,9 +1319,6 @@
puts -nonewline $fd $path
puts -nonewline $fd "\0"
display_file $path $new
- if {$current_diff eq $path} {
- set update_index_rsd 1
- }
}
set ui_status_value [format \
@@ -1859,19 +1854,23 @@
}
proc do_include_all {} {
- global file_states
+ global file_states current_diff
if {![lock_index begin-update]} return
set pathList [list]
+ set after {}
foreach path [array names file_states] {
- set s $file_states($path)
- set m [lindex $s 0]
- switch -- $m {
+ switch -- [lindex $file_states($path) 0] {
AM -
MM -
_M -
- _D {lappend pathList $path}
+ _D {
+ lappend pathList $path
+ if {$path eq $current_diff} {
+ set after {reshow_diff;}
+ }
+ }
}
}
if {$pathList eq {}} {
@@ -1880,7 +1879,7 @@
update_index \
"Including all modified files" \
$pathList \
- {set ui_status_value {Ready to commit.}}
+ [concat $after {set ui_status_value {Ready to commit.}}]
}
}
@@ -2204,7 +2203,7 @@
}
proc toggle_or_diff {w x y} {
- global file_lists ui_index ui_other
+ global file_lists current_diff ui_index ui_other
global last_clicked selected_paths
set pos [split [$w index @$x,$y] .]
@@ -2222,10 +2221,15 @@
$ui_other tag remove in_sel 0.0 end
if {$col == 0} {
+ if {$current_diff eq $path} {
+ set after {reshow_diff;}
+ } else {
+ set after {}
+ }
update_index \
"Including [short_path $path]" \
[list $path] \
- {set ui_status_value {Ready.}}
+ [concat $after {set ui_status_value {Ready.}}]
} else {
show_diff $path $w $lno
}
@@ -2642,7 +2646,7 @@
# -- Diff Header
set current_diff {}
set diff_actions [list]
-proc current_diff_trace {varname args} {
+proc trace_current_diff {varname args} {
global current_diff diff_actions file_states
if {$current_diff eq {}} {
set s {}
@@ -2664,7 +2668,7 @@
uplevel #0 $w $o
}
}
-trace add variable current_diff write current_diff_trace
+trace add variable current_diff write trace_current_diff
frame .vpane.lower.diff.header -background orange
label .vpane.lower.diff.header.status \