@matheusbsbs / matheus-bagliano / commits / 7f1df79bb7
Fork 0

git-gui: Efficiently update the UI after committing.

When we commit we know that whatever was in the index went as part of the commit. Since we generally assume that the user does not update the index except through our user interface we can be reasonably certain that any file which was marked as A/M/D in the index will have had that A/M/D state changed to an _ (not different) by the commit. We can use this knowledge to update the user interface post commit by simply updating the index part of the file state of all files whose index state was A/M/D to _ and then removing any file memory any which wound up with a final state of __ (not different anywhere). Finally we redraw the file lists and update the diff view. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 11, 2006 at 18:38 UTC 7f1df79bb7bad696d1d8965da3937edeb1cfe9f6
1 file changed +56 -29
git-gui
+56 -29
@@ -150,7 +150,7 @@ proc repository_state {hdvar ctvar} {
150 proc update_status {{final Ready.}} {
151 global HEAD PARENT commit_type
152 global ui_index ui_other ui_status_value ui_comm
153 - global status_active file_states file_lists
153 + global status_active file_states
154 global cfg_trust_mtime
155
156 if {$status_active || ![lock_index read]} return
@@ -166,12 +166,6 @@ proc update_status {{final Ready.}} {
166 }
167
168 array unset file_states
169 - array unset file_lists
170 - foreach w [list $ui_index $ui_other] {
171 - $w conf -state normal
172 - $w delete 0.0 end
173 - $w conf -state disabled
174 - }
169
170 if {![$ui_comm edit modified]
171 || [string trim [$ui_comm get 0.0 end]] == {}} {
@@ -319,25 +313,18 @@ proc read_ls_others {fd final} {
313 }
314
315 proc status_eof {fd buf final} {
322 - global status_active $buf
323 - global ui_fname_value ui_status_value file_states
316 + global status_active ui_status_value
317 + upvar $buf to_clear
318
319 if {[eof $fd]} {
326 - set $buf {}
320 + set to_clear {}
321 close $fd
322
323 if {[incr status_active -1] == 0} {
330 - unlock_index
331 -
324 display_all_files
325 + unlock_index
326 + reshow_diff
327 set ui_status_value $final
334 -
335 - if {$ui_fname_value != {} && [array names file_states \
336 - -exact $ui_fname_value] != {}} {
337 - show_diff $ui_fname_value
338 - } else {
339 - clear_diff
340 - }
328 }
329 }
330 }
@@ -360,6 +347,17 @@ proc clear_diff {} {
347 $ui_other tag remove in_diff 0.0 end
348 }
349
350 +proc reshow_diff {} {
351 + global ui_fname_value ui_status_value file_states
352 +
353 + if {$ui_fname_value != {} && [array names file_states \
354 + -exact $ui_fname_value] != {}} {
355 + show_diff $ui_fname_value
356 + } else {
357 + clear_diff
358 + }
359 +}
360 +
361 proc show_diff {path {w {}} {lno {}}} {
362 global file_states file_lists
363 global PARENT diff_3way diff_active
@@ -562,11 +560,11 @@ before committing.
560 foreach path [array names file_states] {
561 set s $file_states($path)
562 switch -glob -- [lindex $s 0] {
565 - _* {continue}
566 - A* -
567 - D* -
568 - M* {set files_ready 1; break}
569 - U* {
563 + _? {continue}
564 + A? -
565 + D? -
566 + M? {set files_ready 1; break}
567 + U? {
568 error_popup "Unmerged files cannot be committed.
569
570 File [escape_path $path] has merge conflicts.
@@ -635,8 +633,9 @@ A good commit message has the following format:
633 }
634
635 proc commit_stage2 {fd_wt curHEAD msg} {
638 - global single_commit gitdir PARENT commit_type
636 + global single_commit gitdir HEAD PARENT commit_type
637 global commit_active ui_status_value ui_comm
638 + global file_states
639
640 gets $fd_wt tree_id
641 close $fd_wt
@@ -663,7 +662,7 @@ proc commit_stage2 {fd_wt curHEAD msg} {
662 }
663 close $fd_mh
664 } err]} {
666 - error_popup "Loading MERGE_HEADs failed:\n$err"
665 + error_popup "Loading MERGE_HEAD failed:\n$err"
666 set commit_active 0
667 set ui_status_value {Commit failed.}
668 unlock_index
@@ -723,12 +722,34 @@ proc commit_stage2 {fd_wt curHEAD msg} {
722
723 if {$single_commit} do_quit
724
726 - set commit_type {}
725 + # -- Update status without invoking any git commands.
726 + #
727 set commit_active 0
728 + set commit_type normal
729 set HEAD $cmt_id
730 set PARENT $cmt_id
731 +
732 + foreach path [array names file_states] {
733 + set s $file_states($path)
734 + set m [lindex $s 0]
735 + switch -glob -- $m {
736 + A? -
737 + M? -
738 + D? {set m _[string index $m 1]}
739 + }
740 +
741 + if {$m == {__}} {
742 + unset file_states($path)
743 + } else {
744 + lset file_states($path) 0 $m
745 + }
746 + }
747 +
748 + display_all_files
749 unlock_index
731 - update_status "Changes committed as [string range $cmt_id 0 7]."
750 + reshow_diff
751 + set ui_status_value \
752 + "Changes committed as [string range $cmt_id 0 7]."
753 }
754
755 ######################################################################
@@ -925,6 +946,10 @@ proc display_all_files {} {
946 $ui_index conf -state normal
947 $ui_other conf -state normal
948
949 + $ui_index delete 0.0 end
950 + $ui_other delete 0.0 end
951 +
952 + array unset file_lists
953 foreach path [lsort [array names file_states]] {
954 set s $file_states($path)
955 set m [lindex $s 0]
@@ -1506,10 +1531,12 @@ proc click {w x y shift wx wy} {
1531 }
1532
1533 proc unclick {w x y} {
1534 + global file_lists
1535 +
1536 set pos [split [$w index @$x,$y] .]
1537 set lno [lindex $pos 0]
1538 set col [lindex $pos 1]
1512 - set path [$w get $lno.1 $lno.end]
1539 + set path [lindex $file_lists($w) [expr $lno - 1]]
1540 if {$path == {}} return
1541
1542 if {$col == 0} {