git-gui: Run the pre-commit hook in the background.
I started to notice on Windows that commits took a lot longer to get going than on my Mac OS X system. The real reason is the repositories that I'm testing with on Windows all enabled the standard pre-commit hook while my test repository on Mac OS X doesn't have it executable (so its not running). So the Windows repositories are spending this lag time running that hook. Now we run the pre-commit hook in the background, allowing the UI to update and tell the user we are busy doing things. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 12, 2006 at 17:58 UTC
4658b56fce4e8b7c4489ae7b0fe9ecf1e236b70b
1 file changed
+43
-12
git-gui
+43
-12
@@ -664,8 +664,8 @@ proc load_last_commit {} {
664
665
proc commit_tree {} {
666
global tcl_platform HEAD gitdir commit_type file_states
667
- global commit_active ui_status_value
668
- global ui_comm
667
+ global commit_active pch_error
668
+ global ui_status_value ui_comm
669
670
if {$commit_active || ![lock_index update]} return
671
@@ -739,33 +739,64 @@ A good commit message has the following format:
739
return
740
}
741
742
+ set commit_active 1
743
+
744
# -- Ask the pre-commit hook for the go-ahead.
745
#
746
set pchook [file join $gitdir hooks pre-commit]
747
if {$tcl_platform(platform) == {windows} && [file isfile $pchook]} {
746
- set pchook [list sh -c \
747
- "if test -x \"$pchook\"; then exec \"$pchook\"; fi"]
748
+ set pchook [list sh -c [concat \
749
+ "if test -x \"$pchook\";" \
750
+ "then exec \"$pchook\" 2>&1;" \
751
+ "fi"]]
752
} elseif {[file executable $pchook]} {
749
- set pchook [list $pchook]
753
+ set pchook [list $pchook |& cat]
754
} else {
755
set pchook {}
756
}
753
- if {$pchook != {} && [catch {eval exec $pchook} err]} {
754
- hook_failed_popup pre-commit $err
755
- unlock_index
757
+ if {$pchook != {}} {
758
+ set ui_status_value {Calling pre-commit hook...}
759
+ set pch_error {}
760
+ set fd_ph [open "| $pchook" r]
761
+ fconfigure $fd_ph -blocking 0 -translation binary
762
+ fileevent $fd_ph readable \
763
+ [list commit_stage1 $fd_ph $curHEAD $msg]
764
+ } else {
765
+ commit_stage2 $curHEAD $msg
766
+ }
767
+}
768
+
769
+proc commit_stage1 {fd_ph curHEAD msg} {
770
+ global commit_active pch_error ui_status_value
771
+
772
+ append pch_error [read $fd_ph]
773
+ fconfigure $fd_ph -blocking 1
774
+ if {[eof $fd_ph]} {
775
+ if {[catch {close $fd_ph}]} {
776
+ set ui_status_value {Commit declined by pre-commit hook.}
777
+ hook_failed_popup pre-commit $pch_error
778
+ unlock_index
779
+ set commit_active 0
780
+ set pch_error {}
781
+ return
782
+ }
783
+ commit_stage2 $curHEAD $msg
784
return
785
}
786
+ fconfigure $fd_ph -blocking 0
787
+}
788
+
789
+proc commit_stage2 {curHEAD msg} {
790
+ global ui_status_value
791
792
# -- Write the tree in the background.
793
#
761
- set commit_active 1
794
set ui_status_value {Committing changes...}
763
-
795
set fd_wt [open "| git write-tree" r]
765
- fileevent $fd_wt readable [list commit_stage2 $fd_wt $curHEAD $msg]
796
+ fileevent $fd_wt readable [list commit_stage3 $fd_wt $curHEAD $msg]
797
}
798
768
-proc commit_stage2 {fd_wt curHEAD msg} {
799
+proc commit_stage3 {fd_wt curHEAD msg} {
800
global single_commit gitdir HEAD PARENT commit_type
801
global commit_active ui_status_value ui_comm
802
global file_states