Skip to content

Commit 2f7c9a7

Browse files
committed
git-gui: Support native Win32 Tcl/Tk under Cygwin
Cygwin has been stuck on the 8.4.1 version of Tcl/Tk for quite some time, even though the main Tcl/Tk distribution is already shipping an 8.4.15. The problem is Tcl/Tk no longer supports Cygwin so apparently building the package for Cygwin is now a non-trivial task. Its actually quite easy to build the native Win32 version of Tcl/Tk by compiling with the -mno-cygwin flag passed to GCC but this means we lose all of the "fancy" Cygwin path translations that the Tcl library was doing for us. This is particularly an issue when we are trying to start git-gui through the git wrapper as the git wrapper is passing off a Cygwin path for $0 and Tcl cannot find the startup script or the library directory. We now use `cygpath -m -a` to convert the UNIX style paths to Windows style paths in our startup script if we are building on Cygwin. Doing so allows either the Cygwin-ized Tcl/Tk 8.4.1 that comes with Cygwin or a manually built 8.4.15 that is running the pure Win32 implementation to read our script. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent d4278b5 commit 2f7c9a7

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

Makefile

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,35 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
9292
SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
9393
TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH))
9494
TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH))
95+
TCLTK_PATH_SED = $(subst ','\'',$(subst \,\\,$(TCLTK_PATH)))
9596

9697
gg_libdir ?= $(sharedir)/git-gui/lib
9798
libdir_SQ = $(subst ','\'',$(gg_libdir))
99+
libdir_SED = $(subst ','\'',$(subst \,\\,$(gg_libdir)))
100+
exedir = $(dir $(gitexecdir))share/git-gui/lib
98101

99-
exedir = $(dir $(gitexecdir))share/git-gui/lib
100-
exedir_SQ = $(subst ','\'',$(exedir))
102+
GITGUI_SCRIPT := $$0
103+
GITGUI_RELATIVE :=
104+
105+
ifeq ($(exedir),$(gg_libdir))
106+
GITGUI_RELATIVE := 1
107+
endif
108+
109+
ifeq ($(uname_O),Cygwin)
110+
GITGUI_SCRIPT := `cygpath --windows --absolute "$(GITGUI_SCRIPT)"`
111+
ifeq ($(GITGUI_RELATIVE),)
112+
gg_libdir := $(shell cygpath --windows --absolute "$(gg_libdir)")
113+
endif
114+
endif
101115

102116
$(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
103117
$(QUIET_GEN)rm -f $@ $@+ && \
104-
GITGUI_RELATIVE= && \
105-
if test '$(exedir_SQ)' = '$(libdir_SQ)'; then \
106-
if test "$(uname_O)" = Cygwin; \
107-
then GITGUI_RELATIVE= ; \
108-
else GITGUI_RELATIVE=1; \
109-
fi; \
110-
fi && \
111118
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
112-
-e 's|^ exec wish "$$0"| exec $(subst |,'\|',$(TCLTK_PATH_SQ)) "$$0"|' \
119+
-e '1,30s|^ argv0=$$0| argv0=$(GITGUI_SCRIPT)|' \
120+
-e '1,30s|^ exec wish | exec '\''$(TCLTK_PATH_SED)'\'' |' \
113121
-e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
114-
-e 's|@@GITGUI_RELATIVE@@|'$$GITGUI_RELATIVE'|' \
115-
-e $$GITGUI_RELATIVE's|@@GITGUI_LIBDIR@@|$(libdir_SQ)|' \
122+
-e 's|@@GITGUI_RELATIVE@@|$(GITGUI_RELATIVE)|' \
123+
-e '$(GITGUI_RELATIVE)s|@@GITGUI_LIBDIR@@|$(libdir_SED)|' \
116124
$@.sh >$@+ && \
117125
chmod +x $@+ && \
118126
mv $@+ $@

git-gui.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
echo 'git-gui version @@GITGUI_VERSION@@'; \
77
exit; \
88
fi; \
9-
exec wish "$0" -- "$@"
9+
argv0=$0; \
10+
exec wish "$argv0" -- "$@"
1011

1112
set appvers {@@GITGUI_VERSION@@}
1213
set copyright {
@@ -740,7 +741,7 @@ if {[catch {
740741
exit 1
741742
}
742743
if {![file isdirectory $_gitdir] && [is_Cygwin]} {
743-
catch {set _gitdir [exec cygpath --unix $_gitdir]}
744+
catch {set _gitdir [exec cygpath --windows $_gitdir]}
744745
}
745746
if {![file isdirectory $_gitdir]} {
746747
catch {wm withdraw .}

0 commit comments

Comments
 (0)