Commits

Anonymous committed 875b7c9

git-gui: Fix "unoptimized loading" to not cause git-gui to crash

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>

  • Participants
  • Parent commits ce015c2

Comments (0)

Files changed (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
-
-######################################################################
-##
 ## read only globals
 
 set _appname [lindex [file split $argv0] end]
 
 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
 
 }
 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
 }
 
 
 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]:
 
 
 ######################################################################
 ##
+## 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
 
 if {[regexp {^git-(.+)$} [appname] _junk subcommand]} {