Skip to content

Commit e6131d3

Browse files
angavrilovspearce
authored andcommitted
Kill the blame back-end on window close.
Currently 'git-gui blame' does not kill its back-end process, hoping that it will die anyway when the pipe is closed. However, in some cases the process works for a long time without producing any output. This behavior results in a runaway CPU hog. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent 57cae87 commit e6131d3

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

git-gui.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,20 @@ proc githook_read {hook_name args} {
497497
return {}
498498
}
499499
500+
proc kill_file_process {fd} {
501+
set process [pid $fd]
502+
503+
catch {
504+
if {[is_Windows]} {
505+
# Use a Cygwin-specific flag to allow killing
506+
# native Windows processes
507+
exec kill -f $process
508+
} else {
509+
exec kill $process
510+
}
511+
}
512+
}
513+
500514
proc sq {value} {
501515
regsub -all ' $value "'\\''" value
502516
return "'$value'"

lib/blame.tcl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,27 @@ constructor new {i_commit i_path} {
326326
bind $w.file_pane <Configure> \
327327
"if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
328328

329+
wm protocol $top WM_DELETE_WINDOW "destroy $top"
330+
bind $top <Destroy> [cb _kill]
331+
329332
_load $this {}
330333
}
331334

335+
method _kill {} {
336+
if {$current_fd ne {}} {
337+
kill_file_process $current_fd
338+
catch {close $current_fd}
339+
set current_fd {}
340+
}
341+
}
342+
332343
method _load {jump} {
333344
variable group_colors
334345

335346
_hide_tooltip $this
336347

337348
if {$total_lines != 0 || $current_fd ne {}} {
338-
if {$current_fd ne {}} {
339-
catch {close $current_fd}
340-
set current_fd {}
341-
}
349+
_kill $this
342350

343351
foreach i $w_columns {
344352
$i conf -state normal

0 commit comments

Comments
 (0)