Skip to content

Commit

Permalink
git-gui: Fix "unoptimized loading" to not cause git-gui to crash
Browse files Browse the repository at this point in the history
If the tclsh command was not available to us at the time we were
"built" our lib/tclIndex just lists all of our library files and
we source all of them at once during startup, rather than trying
to lazily load only the procedures we need.  This is a problem as
some of our library code now depends upon the git-version proc,
and that proc is not defined until after the library was fully
loaded.

I'm moving the library loading until after we have determined the
version of git we are talking to, as this ensures that the required
git-reversion procedure is defined before any library code can be
loaded.  Since error_popup is defined in the library we instead use
tk_messageBox directly for errors found during the version detection.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information
Shawn O. Pearce committed Aug 22, 2007
1 parent ce015c2 commit 875b7c9
Showing 1 changed file with 63 additions and 51 deletions.
114 changes: 63 additions & 51 deletions git-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,54 +60,6 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
}
}

######################################################################
##
## configure our library

set oguilib {@@GITGUI_LIBDIR@@}
set oguirel {@@GITGUI_RELATIVE@@}
if {$oguirel eq {1}} {
set oguilib [file dirname [file dirname [file normalize $argv0]]]
set oguilib [file join $oguilib share git-gui lib]
} elseif {[string match @@* $oguirel]} {
set oguilib [file join [file dirname [file normalize $argv0]] lib]
}

set idx [file join $oguilib tclIndex]
if {[catch {set fd [open $idx r]} err]} {
catch {wm withdraw .}
tk_messageBox \
-icon error \
-type ok \
-title "git-gui: fatal error" \
-message $err
exit 1
}
if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
set idx [list]
while {[gets $fd n] >= 0} {
if {$n ne {} && ![string match #* $n]} {
lappend idx $n
}
}
} else {
set idx {}
}
close $fd

if {$idx ne {}} {
set loaded [list]
foreach p $idx {
if {[lsearch -exact $loaded $p] >= 0} continue
source [file join $oguilib $p]
lappend loaded $p
}
unset loaded p
} else {
set auto_path [concat [list $oguilib] $auto_path]
}
unset -nocomplain oguirel idx fd

######################################################################
##
## read only globals
Expand Down Expand Up @@ -532,7 +484,11 @@ if {$_git eq {}} {

if {[catch {set _git_version [git --version]} err]} {
catch {wm withdraw .}
error_popup "Cannot determine Git version:
tk_messageBox \
-icon error \
-type ok \
-title "git-gui: fatal error" \
-message "Cannot determine Git version:
$err
Expand All @@ -541,7 +497,11 @@ $err
}
if {![regsub {^git version } $_git_version {} _git_version]} {
catch {wm withdraw .}
error_popup "Cannot parse Git version string:\n\n$_git_version"
tk_messageBox \
-icon error \
-type ok \
-title "git-gui: fatal error" \
-message "Cannot parse Git version string:\n\n$_git_version"
exit 1
}

Expand Down Expand Up @@ -619,14 +579,66 @@ proc git-version {args} {

if {[git-version < 1.5]} {
catch {wm withdraw .}
error_popup "[appname] requires Git 1.5.0 or later.
tk_messageBox \
-icon error \
-type ok \
-title "git-gui: fatal error" \
-message "[appname] requires Git 1.5.0 or later.
You are using [git-version]:
[git --version]"
exit 1
}

######################################################################
##
## configure our library

set oguilib {@@GITGUI_LIBDIR@@}
set oguirel {@@GITGUI_RELATIVE@@}
if {$oguirel eq {1}} {
set oguilib [file dirname [file dirname [file normalize $argv0]]]
set oguilib [file join $oguilib share git-gui lib]
} elseif {[string match @@* $oguirel]} {
set oguilib [file join [file dirname [file normalize $argv0]] lib]
}

set idx [file join $oguilib tclIndex]
if {[catch {set fd [open $idx r]} err]} {
catch {wm withdraw .}
tk_messageBox \
-icon error \
-type ok \
-title "git-gui: fatal error" \
-message $err
exit 1
}
if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
set idx [list]
while {[gets $fd n] >= 0} {
if {$n ne {} && ![string match #* $n]} {
lappend idx $n
}
}
} else {
set idx {}
}
close $fd

if {$idx ne {}} {
set loaded [list]
foreach p $idx {
if {[lsearch -exact $loaded $p] >= 0} continue
source [file join $oguilib $p]
lappend loaded $p
}
unset loaded p
} else {
set auto_path [concat [list $oguilib] $auto_path]
}
unset -nocomplain oguirel idx fd

######################################################################
##
## feature option selection
Expand Down

0 comments on commit 875b7c9

Please sign in to comment.