Avoid runaway processes in gitk
cover Avoid runaway processes in gitk
As in the 'git gui blame' case, gitk back-end processes can sometimes run for a while without producing any output, e.g. diff-files on a slow filesystem.
These patches make gitk explicitly kill its back-end processes.
Alexander Gavrilov (3):
gitk: Kill back-end processes on window close.
gitk: Register diff-files & diff-index in commfd, to ensure kill.
gitk: On Windows use a Cygwin-specific flag for kill.
gitk | 79 ++++++++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 53 insertions(+), 26 deletions(-)
PATCH 1/3 gitk: Kill back-end processes on window close.
When collecting commits for a rarely changed, or recently created file or directory, rev-list may work for a noticeable period of time without producing any output. Such processes don't receive SIGPIPE for a while after gitk is closed, thus becoming runaway CPU hogs.
--- gitk | 35 +++++++++++++++++++++++++---------- 1 files changed, 25 insertions(+), 10 deletions(-)
gitk +25 -10
@@ -375,19 +375,33 @@ proc start_rev_list {view} { return 1 } +proc stop_instance {inst} { + global commfd leftover + + set fd $commfd($inst) + catch { + set pid [pid $fd] + exec kill $pid + } + catch {close $fd} + nukefile $fd + unset commfd($inst) + unset leftover($inst) +} + +proc stop_backends {} { + global commfd + + foreach inst [array names commfd] { + stop_instance $inst + } +} + proc stop_rev_list {view} { - global commfd viewinstances leftover + global viewinstances foreach inst $viewinstances($view) { - set fd $commfd($inst) - catch { - set pid [pid $fd] - exec kill $pid - } - catch {close $fd} - nukefile $fd - unset commfd($inst) - unset leftover($inst) + stop_instance $inst } set viewinstances($view) {} }
@@ -2103,6 +2117,7 @@ proc makewindow {} { bind . <$M1B-minus> {incrfont -1} bind . <$M1B-KP_Subtract> {incrfont -1} wm protocol . WM_DELETE_WINDOW doquit + bind . <Destroy> {stop_backends} bind . <Button-1> "click %W" bind $fstring <Key-Return> {dofind 1 1} bind $sha1entry <Key-Return> gotocommit
Signature · 1 line
1.5.6.2.39.gd084
PATCH 2/3 gitk: Register diff-files & diff-index in commfd, to ensure kill.
Local change analysis can take a noticeable amount of time on large file sets, and produce no output if there are no changes. Register the back-ends in commfd, so that they get properly killed on window close.
--- gitk | 39 +++++++++++++++++++++++---------------- 1 files changed, 23 insertions(+), 16 deletions(-)
gitk +23 -16
@@ -90,6 +90,15 @@ proc dorunq {} { } } +proc reg_instance {fd} { + global commfd leftover loginstance + + set i [incr loginstance] + set commfd($i) $fd + set leftover($i) {} + return $i +} + proc unmerged_files {files} { global nr_unmerged
@@ -294,10 +303,10 @@ proc parseviewrevs {view revs} { # Start off a git log process and arrange to read its output proc start_rev_list {view} { global startmsecs commitidx viewcomplete curview - global commfd leftover tclencoding + global tclencoding global viewargs viewargscmd viewfiles vfilelimit global showlocalchanges commitinterest - global viewactive loginstance viewinstances vmergeonly + global viewactive viewinstances vmergeonly global pending_select mainheadid global vcanopt vflags vrevs vorigargs
@@ -354,10 +363,8 @@ proc start_rev_list {view} { error_popup "[mc "Error executing git log:"] $err" return 0 } - set i [incr loginstance] + set i [reg_instance $fd] set viewinstances($view) [list $i] - set commfd($i) $fd - set leftover($i) {} if {$showlocalchanges && $mainheadid ne {}} { lappend commitinterest($mainheadid) {dodiffindex} }
@@ -420,8 +427,8 @@ proc getcommits {} { proc updatecommits {} { global curview vcanopt vorigargs vfilelimit viewinstances - global viewactive viewcomplete loginstance tclencoding - global startmsecs commfd showneartags showlocalchanges leftover + global viewactive viewcomplete tclencoding + global startmsecs showneartags showlocalchanges global mainheadid pending_select global isworktree global varcid vposids vnegids vflags vrevs
@@ -482,10 +489,8 @@ proc updatecommits {} { if {$viewactive($view) == 0} { set startmsecs [clock clicks -milliseconds] } - set i [incr loginstance] + set i [reg_instance $fd] lappend viewinstances($view) $i - set commfd($i) $fd - set leftover($i) {} fconfigure $fd -blocking 0 -translation lf -eofchar {} if {$tclencoding != {}} { fconfigure $fd -encoding $tclencoding
@@ -4063,10 +4068,11 @@ proc dodiffindex {} { incr lserial set fd [open "|git diff-index --cached HEAD" r] fconfigure $fd -blocking 0 - filerun $fd [list readdiffindex $fd $lserial] + set i [reg_instance $fd] + filerun $fd [list readdiffindex $fd $lserial $i] } -proc readdiffindex {fd serial} { +proc readdiffindex {fd serial inst} { global mainheadid nullid nullid2 curview commitinfo commitdata lserial set isdiff 1
@@ -4077,7 +4083,7 @@ proc readdiffindex {fd serial} { set isdiff 0 } # we only need to see one line and we don't really care what it says... - close $fd + stop_instance $inst if {$serial != $lserial} { return 0
@@ -4086,7 +4092,8 @@ proc readdiffindex {fd serial} { # now see if there are any local changes not checked in to the index set fd [open "|git diff-files" r] fconfigure $fd -blocking 0 - filerun $fd [list readdifffiles $fd $serial] + set i [reg_instance $fd] + filerun $fd [list readdifffiles $fd $serial $i] if {$isdiff && ![commitinview $nullid2 $curview]} { # add the line for the changes in the index to the graph
@@ -4103,7 +4110,7 @@ proc readdiffindex {fd serial} { return 0 } -proc readdifffiles {fd serial} { +proc readdifffiles {fd serial inst} { global mainheadid nullid nullid2 curview global commitinfo commitdata lserial
@@ -4115,7 +4122,7 @@ proc readdifffiles {fd serial} { set isdiff 0 } # we only need to see one line and we don't really care what it says... - close $fd + stop_instance $inst if {$serial != $lserial} { return 0
Signature · 1 line
1.5.6.2.39.gd084
PATCH 3/3 gitk: On Windows use a Cygwin-specific flag for kill.
MSysGit compiles git binaries as native Windows executables, so they cannot be killed unless a special flag is specified.
This flag is implemented by the Cygwin version of kill, which is also included in MSysGit.
--- gitk | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
gitk +6 -1
@@ -388,7 +388,12 @@ proc stop_instance {inst} { set fd $commfd($inst) catch { set pid [pid $fd] - exec kill $pid + + if {$::tcl_platform(platform) eq {windows}} { + exec kill -f $pid + } else { + exec kill $pid + } } catch {close $fd} nukefile $fd
Signature · 1 line
1.5.6.2.39.gd084