Skip to content

Commit b8dfb16

Browse files
angavrilovspearce
authored andcommitted
git-gui: Implement automatic rescan after Tool execution.
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 <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 67df911 commit b8dfb16

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

lib/tools.tcl

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ proc tools_exec {fullname} {
102102

103103
set cmdline $repo_config(guitool.$fullname.cmd)
104104
if {[is_config_true "guitool.$fullname.noconsole"]} {
105-
exec sh -c $cmdline &
105+
tools_run_silent [list sh -c $cmdline] \
106+
[list tools_complete $fullname {}]
106107
} else {
107108
regsub {/} $fullname { / } title
108109
set w [console::new \
109110
[mc "Tool: %s" $title] \
110111
[mc "Running: %s" $cmdline]]
111-
console::exec $w [list sh -c $cmdline]
112+
console::exec $w [list sh -c $cmdline] \
113+
[list tools_complete $fullname $w]
112114
}
113115

114116
unset env(GIT_GUITOOL)
@@ -117,3 +119,41 @@ proc tools_exec {fullname} {
117119
catch { unset env(ARGS) }
118120
catch { unset env(REVISION) }
119121
}
122+
123+
proc tools_run_silent {cmd after} {
124+
lappend cmd 2>@1
125+
set fd [_open_stdout_stderr $cmd]
126+
127+
fconfigure $fd -blocking 0 -translation binary
128+
fileevent $fd readable [list tools_consume_input $fd $after]
129+
}
130+
131+
proc tools_consume_input {fd after} {
132+
read $fd
133+
if {[eof $fd]} {
134+
fconfigure $fd -blocking 1
135+
if {[catch {close $fd}]} {
136+
uplevel #0 $after 0
137+
} else {
138+
uplevel #0 $after 1
139+
}
140+
}
141+
}
142+
143+
proc tools_complete {fullname w {ok 1}} {
144+
if {$w ne {}} {
145+
console::done $w $ok
146+
}
147+
148+
if {$ok} {
149+
set msg [mc "Tool completed succesfully: %s" $fullname]
150+
} else {
151+
set msg [mc "Tool failed: %s" $fullname]
152+
}
153+
154+
if {[is_config_true "guitool.$fullname.norescan"]} {
155+
ui_status $msg
156+
} else {
157+
rescan [list ui_status $msg]
158+
}
159+
}

0 commit comments

Comments
 (0)