+proc _git_cmd {name} {
+ global _git_cmd_path
+
+ if {[catch {set v $_git_cmd_path($name)}]} {
+ switch -- $name {
+ --version -
+ --exec-path { return [list $::_git $name] }
+ }
+
+ set p [gitexec git-$name$::_search_exe]
+ if {[file exists $p]} {
+ set v [list $p]
+ } elseif {[is_Cygwin]} {
+ # On Cygwin git is a proper Cygwin program and knows
+ # how to properly restart the Cygwin environment and
+ # spawn its non-.exe support program.
+ #
+ set v [list $::_git $name]
+ } elseif {[is_Windows]
+ && $::_sh ne {}
+ && [file exists [gitexec git-$name]]} {
+ # Assume this is a UNIX shell script. We can
+ # probably execute it through a Bourne shell.
+ #
+ set v [list $::_sh [gitexec git-$name]]
+ } else {
+ error "No [gitexec git-$name]"
+ }
+ set _git_cmd_path($name) $v
+ }
+ return $v
+}
+
+proc _which {what} {
+ global env _search_exe _search_path
+
+ if {$_search_path eq {}} {
+ if {[is_Cygwin]} {
+ set _search_path [split [exec cygpath \
+ --windows \
+ --path \
+ --absolute \
+ $env(PATH)] {;}]
+ set _search_exe .exe
+ } elseif {[is_Windows]} {
+ set _search_path [split $env(PATH) {;}]
+ set _search_exe .exe
+ } else {
+ set _search_path [split $env(PATH) :]
+ set _search_exe {}
+ }
+ }
+
+ foreach p $_search_path {
+ set p [file join $p $what$_search_exe]
+ if {[file exists $p]} {
+ return [file normalize $p]
+ }
+ }
+ return {}
+}
+