@matheusbsbs / matheus-bagliano / commits / 8134722306
Fork 0

git-gui: Refactor 'exec git subcmd' idiom.

As we frequently need to execute a Git subcommand and obtain its returned output we are making heavy use of [exec git foo] to run foo. As I'm concerned about possibly needing to carry environment data through a shell on Cygwin for at least some subcommands, I'm migrating all current calls to a new git proc. This actually makes the code look cleaner too, as we aren't saying 'exec git' everywhere. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Feb 12, 2007 at 22:48 UTC 81347223066fee64997cbb731925bc8c1abd35d7
1 file changed +31 -23
git-gui.sh
+31 -23
@@ -46,7 +46,7 @@ proc gitdir {args} {
46 proc gitexec {args} {
47 global _gitexec
48 if {$_gitexec eq {}} {
49 - if {[catch {set _gitexec [exec git --exec-path]} err]} {
49 + if {[catch {set _gitexec [git --exec-path]} err]} {
50 error "Git not installed?\n\n$err"
51 }
52 }
@@ -202,14 +202,14 @@ proc save_config {} {
202 set value $global_config_new($name)
203 if {$value ne $global_config($name)} {
204 if {$value eq $default_config($name)} {
205 - catch {exec git config --global --unset $name}
205 + catch {git config --global --unset $name}
206 } else {
207 regsub -all "\[{}\]" $value {"} value
208 - exec git config --global $name $value
208 + git config --global $name $value
209 }
210 set global_config($name) $value
211 if {$value eq $repo_config($name)} {
212 - catch {exec git config --unset $name}
212 + catch {git config --unset $name}
213 set repo_config($name) $value
214 }
215 }
@@ -219,16 +219,24 @@ proc save_config {} {
219 set value $repo_config_new($name)
220 if {$value ne $repo_config($name)} {
221 if {$value eq $global_config($name)} {
222 - catch {exec git config --unset $name}
222 + catch {git config --unset $name}
223 } else {
224 regsub -all "\[{}\]" $value {"} value
225 - exec git config $name $value
225 + git config $name $value
226 }
227 set repo_config($name) $value
228 }
229 }
230 }
231
232 +######################################################################
233 +##
234 +## handy utils
235 +
236 +proc git {args} {
237 + return [eval exec git $args]
238 +}
239 +
240 proc error_popup {msg} {
241 set title [appname]
242 if {[reponame] ne {}} {
@@ -292,7 +300,7 @@ proc ask_popup {msg} {
300 ## repository setup
301
302 if { [catch {set _gitdir $env(GIT_DIR)}]
295 - && [catch {set _gitdir [exec git rev-parse --git-dir]} err]} {
303 + && [catch {set _gitdir [git rev-parse --git-dir]} err]} {
304 catch {wm withdraw .}
305 error_popup "Cannot find the git directory:\n\n$err"
306 exit 1
@@ -365,7 +373,7 @@ proc repository_state {ctvar hdvar mhvar} {
373
374 set mh [list]
375
368 - if {[catch {set current_branch [exec git symbolic-ref HEAD]}]} {
376 + if {[catch {set current_branch [git symbolic-ref HEAD]}]} {
377 set current_branch {}
378 } else {
379 regsub ^refs/((heads|tags|remotes)/)? \
@@ -374,7 +382,7 @@ proc repository_state {ctvar hdvar mhvar} {
382 current_branch
383 }
384
377 - if {[catch {set hd [exec git rev-parse --verify HEAD]}]} {
385 + if {[catch {set hd [git rev-parse --verify HEAD]}]} {
386 set hd {}
387 set ct initial
388 return
@@ -402,7 +410,7 @@ proc PARENT {} {
410 return $p
411 }
412 if {$empty_tree eq {}} {
405 - set empty_tree [exec git mktree << {}]
413 + set empty_tree [git mktree << {}]
414 }
415 return $empty_tree
416 }
@@ -1042,7 +1050,7 @@ proc committer_ident {} {
1050 global GIT_COMMITTER_IDENT
1051
1052 if {$GIT_COMMITTER_IDENT eq {}} {
1045 - if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
1053 + if {[catch {set me [git var GIT_COMMITTER_IDENT]} err]} {
1054 error_popup "Unable to obtain your identity:\n\n$err"
1055 return {}
1056 }
@@ -1275,7 +1283,7 @@ proc commit_committree {fd_wt curHEAD msg} {
1283 # -- Let rerere do its thing.
1284 #
1285 if {[file isdirectory [gitdir rr-cache]]} {
1278 - catch {exec git rerere}
1286 + catch {git rerere}
1287 }
1288
1289 # -- Run the post-commit hook.
@@ -1894,7 +1902,7 @@ proc do_create_branch_action {w} {
1902 focus $w.desc.name_t
1903 return
1904 }
1897 - if {![catch {exec git show-ref --verify -- "refs/heads/$newbranch"}]} {
1905 + if {![catch {git show-ref --verify -- "refs/heads/$newbranch"}]} {
1906 tk_messageBox \
1907 -icon error \
1908 -type ok \
@@ -1904,7 +1912,7 @@ proc do_create_branch_action {w} {
1912 focus $w.desc.name_t
1913 return
1914 }
1907 - if {[catch {exec git check-ref-format "heads/$newbranch"}]} {
1915 + if {[catch {git check-ref-format "heads/$newbranch"}]} {
1916 tk_messageBox \
1917 -icon error \
1918 -type ok \
@@ -1921,7 +1929,7 @@ proc do_create_branch_action {w} {
1929 tracking {set rev $create_branch_trackinghead}
1930 expression {set rev $create_branch_revexp}
1931 }
1924 - if {[catch {set cmt [exec git rev-parse --verify "${rev}^0"]}]} {
1932 + if {[catch {set cmt [git rev-parse --verify "${rev}^0"]}]} {
1933 tk_messageBox \
1934 -icon error \
1935 -type ok \
@@ -2100,7 +2108,7 @@ proc do_delete_branch_action {w} {
2108 }
2109 if {$check_rev eq {:none}} {
2110 set check_cmt {}
2103 - } elseif {[catch {set check_cmt [exec git rev-parse --verify "${check_rev}^0"]}]} {
2111 + } elseif {[catch {set check_cmt [git rev-parse --verify "${check_rev}^0"]}]} {
2112 tk_messageBox \
2113 -icon error \
2114 -type ok \
@@ -2114,10 +2122,10 @@ proc do_delete_branch_action {w} {
2122 set not_merged [list]
2123 foreach i [$w.list.l curselection] {
2124 set b [$w.list.l get $i]
2117 - if {[catch {set o [exec git rev-parse --verify $b]}]} continue
2125 + if {[catch {set o [git rev-parse --verify $b]}]} continue
2126 if {$check_cmt ne {}} {
2127 if {$b eq $check_rev} continue
2120 - if {[catch {set m [exec git merge-base $o $check_cmt]}]} continue
2128 + if {[catch {set m [git merge-base $o $check_cmt]}]} continue
2129 if {$o ne $m} {
2130 lappend not_merged $b
2131 continue
@@ -2155,7 +2163,7 @@ Delete the selected branches?}
2163 foreach i $to_delete {
2164 set b [lindex $i 0]
2165 set o [lindex $i 1]
2158 - if {[catch {exec git update-ref -d "refs/heads/$b" $o} err]} {
2166 + if {[catch {git update-ref -d "refs/heads/$b" $o} err]} {
2167 append failed " - $b: $err\n"
2168 } else {
2169 set x [lsearch -sorted -exact $all_heads $b]
@@ -2366,7 +2374,7 @@ Staying on branch '$current_branch'."
2374 # here, it Just Works(tm). If it doesn't we are in some really ugly
2375 # state that is difficult to recover from within git-gui.
2376 #
2369 - if {[catch {exec git symbolic-ref HEAD "refs/heads/$new_branch"} err]} {
2377 + if {[catch {git symbolic-ref HEAD "refs/heads/$new_branch"} err]} {
2378 error_popup "Failed to set current branch.
2379
2380 This working directory is only partially switched.
@@ -4161,7 +4169,7 @@ proc do_quit {} {
4169 set rc_geometry {}
4170 }
4171 if {$cfg_geometry ne $rc_geometry} {
4164 - catch {exec git config gui.geometry $cfg_geometry}
4172 + catch {git config gui.geometry $cfg_geometry}
4173 }
4174 }
4175
@@ -4412,7 +4420,7 @@ $copyright" \
4420
4421 set v {}
4422 append v "[appname] version $appvers\n"
4415 - append v "[exec git version]\n"
4423 + append v "[git version]\n"
4424 append v "\n"
4425 if {$tcl_patchLevel eq $tk_patchLevel} {
4426 append v "Tcl/Tk version $tcl_patchLevel"
@@ -5904,7 +5912,7 @@ if {[is_enabled transport]} {
5912 if {[is_enabled multicommit]} {
5913 set object_limit 2000
5914 if {[is_Windows]} {set object_limit 200}
5907 - regexp {^([0-9]+) objects,} [exec git count-objects] _junk objects_current
5915 + regexp {^([0-9]+) objects,} [git count-objects] _junk objects_current
5916 if {$objects_current >= $object_limit} {
5917 if {[ask_popup \
5918 "This repository currently has $objects_current loose objects.