[PATCH (GIT-GUI) 2/3] Kill the blame back-end on window close.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git@...>
Cc: Shawn O. Pearce <spearce@...>
Date: Wednesday, July 16, 2008 - 4:48 pm

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>
---

	The -f flag is necessary for msysgit.

	For this fix I submitted to msysgit a patch that includes
	a Cygwin-compatible kill.exe in the installer.

	-- Alexander

 git-gui.sh    |   14 ++++++++++++++
 lib/blame.tcl |   16 ++++++++++++----
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/git-gui.sh b/git-gui.sh
index b1ed0ec..83e2645 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -497,6 +497,20 @@ proc githook_read {hook_name args} {
 	return {}
 }
 
+proc kill_file_process {fd} {
+	set process [pid $fd]
+
+	catch {
+		if {[is_Windows]} {
+			# Use a Cygwin-specific flag to allow killing
+			# native Windows processes
+			exec kill -f $process
+		} else {
+			exec kill $process
+		}
+	}
+}
+
 proc sq {value} {
 	regsub -all ' $value "'\\''" value
 	return "'$value'"
diff --git a/lib/blame.tcl b/lib/blame.tcl
index 192505d..2c19048 100644
--- a/lib/blame.tcl
+++ b/lib/blame.tcl
@@ -326,19 +326,27 @@ constructor new {i_commit i_path} {
 	bind $w.file_pane <Configure> \
 	"if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
 
+	wm protocol $top WM_DELETE_WINDOW "destroy $top"
+	bind $top <Destroy> [cb _kill]
+
 	_load $this {}
 }
 
+method _kill {} {
+	if {$current_fd ne {}} {
+		kill_file_process $current_fd
+		catch {close $current_fd}
+		set current_fd {}
+	}
+}
+
 method _load {jump} {
 	variable group_colors
 
 	_hide_tooltip $this
 
 	if {$total_lines != 0 || $current_fd ne {}} {
-		if {$current_fd ne {}} {
-			catch {close $current_fd}
-			set current_fd {}
-		}
+		_kill $this
 
 		foreach i $w_columns {
 			$i conf -state normal
-- 
1.5.6.3.17.g3f148

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH (GIT-GUI) 0/3] Improve gui blame usability for large ..., Alexander Gavrilov, (Wed Jul 16, 4:42 pm)
Re: [PATCH (GIT-GUI) 0/3] Improve gui blame usability for la..., Alexander Gavrilov, (Fri Jul 18, 1:39 am)
[PATCH (GIT-GUI) 1/3] Add options to control the search for ..., Alexander Gavrilov, (Wed Jul 16, 4:43 pm)
[PATCH (GIT-GUI) 2/3] Kill the blame back-end on window close., Alexander Gavrilov, (Wed Jul 16, 4:48 pm)
[PATCH (GIT-GUI) 3/3] Add a menu item to invoke full copy de..., Alexander Gavrilov, (Wed Jul 16, 4:51 pm)