@matheusbsbs / matheus-bagliano / commits / 20ddfcaa7e
Fork 0

git-gui: Test for Cygwin differently than from Windows.

Running on Cygwin is different than if we were running through MinGW. In the Cygwin case we have cygpath available to us, we need to perform UNIX<->Windows path translation sometimes, and we need to perform odd things like spawning our own login shells to perform network operations. But in the MinGW case these don't occur. Git knows native Windows file paths, and login shells may not even exist. Now git-gui will avoid running cygpath unless it knows its on Cygwin. It also uses a different shortcut type when Cygwin is not present, and it avoids invoking /bin/sh to execute hooks if Cygwin is not present. This latter part probably needs more testing in the MinGW case. This change also improves how we start gitk. If the user is on any type of Windows system its known that gitk won't start right if ~/.gitk exists. So we delete it before starting if we are running on any type of Windows operating system. We always use the same wish executable which launched git-gui to start gitk; this way on Windows we don't have to jump back to /bin/sh just to go into the first wish found in the user's PATH. This should help on MinGW when we probably don't want to spawn a shell just to start gitk. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 28, 2007 at 20:58 UTC 20ddfcaa7e7f91816f1195a2dbb1b5268fd71e3d
1 file changed +104 -34
git-gui.sh
+104 -34
@@ -26,7 +26,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA}
26
27 set _appname [lindex [file split $argv0] end]
28 set _gitdir {}
29 +set _gitexec {}
30 set _reponame {}
31 +set _iscygwin {}
32
33 proc appname {} {
34 global _appname
@@ -41,11 +43,56 @@ proc gitdir {args} {
43 return [eval [concat [list file join $_gitdir] $args]]
44 }
45
46 +proc gitexec {args} {
47 + global _gitexec
48 + if {$_gitexec eq {}} {
49 + if {[catch {set _gitexec [exec git --exec-path]} err]} {
50 + error "Git not installed?\n\n$err"
51 + }
52 + }
53 + if {$args eq {}} {
54 + return $_gitexec
55 + }
56 + return [eval [concat [list file join $_gitexec] $args]]
57 +}
58 +
59 proc reponame {} {
60 global _reponame
61 return $_reponame
62 }
63
64 +proc is_MacOSX {} {
65 + global tcl_platform tk_library
66 + if {[tk windowingsystem] eq {aqua}} {
67 + return 1
68 + }
69 + return 0
70 +}
71 +
72 +proc is_Windows {} {
73 + global tcl_platform
74 + if {$tcl_platform(platform) eq {windows}} {
75 + return 1
76 + }
77 + return 0
78 +}
79 +
80 +proc is_Cygwin {} {
81 + global tcl_platform _iscygwin
82 + if {$_iscygwin eq {}} {
83 + if {$tcl_platform(platform) eq {windows}} {
84 + if {[catch {set p [exec cygpath --windir]} err]} {
85 + set _iscygwin 0
86 + } else {
87 + set _iscygwin 1
88 + }
89 + } else {
90 + set _iscygwin 0
91 + }
92 + }
93 + return $_iscygwin
94 +}
95 +
96 ######################################################################
97 ##
98 ## config
@@ -234,6 +281,9 @@ if { [catch {set _gitdir $env(GIT_DIR)}]
281 error_popup "Cannot find the git directory:\n\n$err"
282 exit 1
283 }
284 +if {![file isdirectory $_gitdir] && [is_Cygwin]} {
285 + catch {set _gitdir [exec cygpath --unix $_gitdir]}
286 +}
287 if {![file isdirectory $_gitdir]} {
288 catch {wm withdraw .}
289 error_popup "Git directory not found:\n\n$_gitdir"
@@ -241,7 +291,7 @@ if {![file isdirectory $_gitdir]} {
291 }
292 if {[lindex [file split $_gitdir] end] ne {.git}} {
293 catch {wm withdraw .}
244 - error_popup "Cannot use funny .git directory:\n\n$gitdir"
294 + error_popup "Cannot use funny .git directory:\n\n$_gitdir"
295 exit 1
296 }
297 if {[catch {cd [file dirname $_gitdir]} err]} {
@@ -1076,7 +1126,7 @@ A good commit message has the following format:
1126 # On Cygwin [file executable] might lie so we need to ask
1127 # the shell if the hook is executable. Yes that's annoying.
1128 #
1079 - if {[is_Windows] && [file isfile $pchook]} {
1129 + if {[is_Cygwin] && [file isfile $pchook]} {
1130 set pchook [list sh -c [concat \
1131 "if test -x \"$pchook\";" \
1132 "then exec \"$pchook\" 2>&1;" \
@@ -1215,7 +1265,7 @@ proc commit_committree {fd_wt curHEAD msg} {
1265 # -- Run the post-commit hook.
1266 #
1267 set pchook [gitdir hooks post-commit]
1218 - if {[is_Windows] && [file isfile $pchook]} {
1268 + if {[is_Cygwin] && [file isfile $pchook]} {
1269 set pchook [list sh -c [concat \
1270 "if test -x \"$pchook\";" \
1271 "then exec \"$pchook\";" \
@@ -3020,22 +3070,6 @@ unset i
3070 ##
3071 ## util
3072
3023 -proc is_MacOSX {} {
3024 - global tcl_platform tk_library
3025 - if {[tk windowingsystem] eq {aqua}} {
3026 - return 1
3027 - }
3028 - return 0
3029 -}
3030 -
3031 -proc is_Windows {} {
3032 - global tcl_platform
3033 - if {$tcl_platform(platform) eq {windows}} {
3034 - return 1
3035 - }
3036 - return 0
3037 -}
3038 -
3073 proc bind_button3 {w cmd} {
3074 bind $w <Any-Button-3> $cmd
3075 if {[is_MacOSX]} {
@@ -3159,10 +3193,10 @@ proc console_init {w} {
3193 }
3194
3195 proc console_exec {w cmd after} {
3162 - # -- Windows tosses the enviroment when we exec our child.
3196 + # -- Cygwin's Tcl tosses the enviroment when we exec our child.
3197 # But most users need that so we have to relogin. :-(
3198 #
3165 - if {[is_Windows]} {
3199 + if {[is_Cygwin]} {
3200 set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
3201 }
3202
@@ -3284,19 +3318,27 @@ proc console_done {args} {
3318 set starting_gitk_msg {Starting gitk... please wait...}
3319
3320 proc do_gitk {revs} {
3287 - global ui_status_value starting_gitk_msg
3321 + global env ui_status_value starting_gitk_msg
3322 +
3323 + # -- On Windows gitk is severly broken, and right now it seems like
3324 + # nobody cares about fixing it. The only known workaround is to
3325 + # always delete ~/.gitk before starting the program.
3326 + #
3327 + if {[is_Windows]} {
3328 + catch {file delete [file join $env(HOME) .gitk]}
3329 + }
3330
3289 - set cmd gitk
3331 + # -- Always start gitk through whatever we were loaded with. This
3332 + # lets us bypass using shell process on Windows systems.
3333 + #
3334 + set cmd [info nameofexecutable]
3335 + lappend cmd [gitexec gitk]
3336 if {$revs ne {}} {
3337 append cmd { }
3338 append cmd $revs
3339 }
3294 - if {[is_Windows]} {
3295 - set cmd "sh -c \"exec $cmd\""
3296 - }
3297 - append cmd { &}
3340
3299 - if {[catch {eval exec $cmd} err]} {
3341 + if {[catch {eval exec $cmd &} err]} {
3342 error_popup "Failed to start gitk:\n\n$err"
3343 } else {
3344 set ui_status_value $starting_gitk_msg
@@ -3894,6 +3936,29 @@ proc do_save_config {w} {
3936 proc do_windows_shortcut {} {
3937 global argv0
3938
3939 + set fn [tk_getSaveFile \
3940 + -parent . \
3941 + -title "[appname] ([reponame]): Create Desktop Icon" \
3942 + -initialfile "Git [reponame].bat"]
3943 + if {$fn != {}} {
3944 + if {[catch {
3945 + set fd [open $fn w]
3946 + puts $fd "@ECHO Entering [reponame]"
3947 + puts $fd "@ECHO Starting git-gui... please wait..."
3948 + puts $fd "@SET PATH=[file normalize [gitexec]];%PATH%"
3949 + puts $fd "@SET GIT_DIR=[file normalize [gitdir]]"
3950 + puts -nonewline $fd "@\"[info nameofexecutable]\""
3951 + puts $fd " \"[file normalize $argv0]\""
3952 + close $fd
3953 + } err]} {
3954 + error_popup "Cannot write script:\n\n$err"
3955 + }
3956 + }
3957 +}
3958 +
3959 +proc do_cygwin_shortcut {} {
3960 + global argv0
3961 +
3962 if {[catch {
3963 set desktop [exec cygpath \
3964 --windows \
@@ -3985,7 +4050,7 @@ proc do_macosx_app {} {
4050
4051 set fd [open $exe w]
4052 set gd [file normalize [gitdir]]
3988 - set ep [file normalize [exec git --exec-path]]
4053 + set ep [file normalize [gitexec]]
4054 regsub -all ' $gd "'\\''" gd
4055 regsub -all ' $ep "'\\''" ep
4056 puts $fd "#!/bin/sh"
@@ -4211,7 +4276,12 @@ if {!$single_commit} {
4276
4277 .mbar.repository add separator
4278
4214 - if {[is_Windows]} {
4279 + if {[is_Cygwin]} {
4280 + .mbar.repository add command \
4281 + -label {Create Desktop Icon} \
4282 + -command do_cygwin_shortcut \
4283 + -font font_ui
4284 + } elseif {[is_Windows]} {
4285 .mbar.repository add command \
4286 -label {Create Desktop Icon} \
4287 -command do_windows_shortcut \
@@ -4416,17 +4486,17 @@ if {![is_MacOSX]} {
4486
4487 set browser {}
4488 catch {set browser $repo_config(instaweb.browser)}
4419 -set doc_path [file dirname [exec git --exec-path]]
4489 +set doc_path [file dirname [gitexec]]
4490 set doc_path [file join $doc_path Documentation index.html]
4491
4422 -if {[is_Windows]} {
4492 +if {[is_Cygwin]} {
4493 set doc_path [exec cygpath --windows $doc_path]
4494 }
4495
4496 if {$browser eq {}} {
4497 if {[is_MacOSX]} {
4498 set browser open
4429 - } elseif {[is_Windows]} {
4499 + } elseif {[is_Cygwin]} {
4500 set program_files [file dirname [exec cygpath --windir]]
4501 set program_files [file join $program_files {Program Files}]
4502 set firefox [file join $program_files {Mozilla Firefox} firefox.exe]
@@ -4988,7 +5058,7 @@ focus -force $ui_comm
5058 # does *not* pass its env array onto any processes it spawns.
5059 # This means that git processes get none of our environment.
5060 #
4991 -if {[is_Windows]} {
5061 +if {[is_Cygwin]} {
5062 set ignored_env 0
5063 set suggest_user {}
5064 set msg "Possible environment issues exist.