git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH (GIT-GUI) v2 5/5] git-gui: Implement automatic rescan after Tool execution.

From
Alexander Gavrilov <angavrilov@gmail.com>
Date
Nov 16, 2008, 18:46 UTC
Message-ID
<1226861211-16995-6-git-send-email-angavrilov@gmail.com>
In-Reply-To
<1226861211-16995-5-git-send-email-angavrilov@gmail.com>

The Tools menu is generally intended for commands that affect the working directory or repository state. Thus, the user would usually want to initiate rescan after execution of a tool. This commit implements it.

In case somebody would want to avoid rescanning after certain tools, it also adds an option that controls it, although it is not made available through the Add dialog.

Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com>
---
 lib/tools.tcl |   44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/lib/tools.tcl b/lib/tools.tcl
index 044432e..51366b0 100644
--- a/lib/tools.tcl
+++ b/lib/tools.tcl
@@ -102,13 +102,15 @@ proc tools_exec {fullname} {
 
 	set cmdline $repo_config(guitool.$fullname.cmd)
 	if {[is_config_true "guitool.$fullname.noconsole"]} {
-		exec sh -c $cmdline &
+		tools_run_silent [list sh -c $cmdline] \
+				 [list tools_complete $fullname {}]
 	} else {
 		regsub {/} $fullname { / } title
 		set w [console::new \
 			[mc "Tool: %s" $title] \
 			[mc "Running: %s" $cmdline]]
-		console::exec $w [list sh -c $cmdline]
+		console::exec $w [list sh -c $cmdline] \
+				 [list tools_complete $fullname $w]
 	}
 
 	unset env(GIT_GUITOOL)
@@ -117,3 +119,41 @@ proc tools_exec {fullname} {
 	catch { unset env(ARGS) }
 	catch { unset env(REVISION) }
 }
+
+proc tools_run_silent {cmd after} {
+	lappend cmd 2>@1
+	set fd [_open_stdout_stderr $cmd]
+	
+	fconfigure $fd -blocking 0 -translation binary
+	fileevent $fd readable [list tools_consume_input $fd $after]
+}
+
+proc tools_consume_input {fd after} {
+	read $fd
+	if {[eof $fd]} {
+		fconfigure $fd -blocking 1
+		if {[catch {close $fd}]} {
+			uplevel #0 $after 0
+		} else {
+			uplevel #0 $after 1
+		}
+	}
+}
+
+proc tools_complete {fullname w {ok 1}} {
+	if {$w ne {}} {
+		console::done $w $ok
+	}
+
+	if {$ok} {
+		set msg [mc "Tool completed succesfully: %s" $fullname]
+	} else {
+		set msg [mc "Tool failed: %s" $fullname]
+	}
+
+	if {[is_config_true "guitool.$fullname.norescan"]} {
+		ui_status $msg
+	} else {
+		rescan [list ui_status $msg]
+	}
+}
-- 
1.6.0.3.15.gb8d36
Previous: Alexander GavrilovNext: Shawn O. Pearce
Message 6 of 7 in “Add a customizable Tools menu.”
  1. 0/5 Add a customizable Tools menu.Alexander Gavrilov, Nov 16, 2008
  2. 1/5 git-gui: Implement system-wide configuration handling.Alexander Gavrilov, Nov 16, 2008
  3. 2/5 git-gui: Fix the after callback execution in rescan.Alexander Gavrilov, Nov 16, 2008
  4. 3/5 git-gui: Add a Tools menu for arbitrary commands.Alexander Gavrilov, Nov 16, 2008
  5. 4/5 git-gui: Allow Tools request arguments from the user.Alexander Gavrilov, Nov 16, 2008
  6. 5/5 git-gui: Implement automatic rescan after Tool execution.Alexander Gavrilov, Nov 16, 2008
  7. Shawn O. PearceNov 16, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.