Skip to content

Commit 875b7c9

Browse files
committed
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 <[email protected]>
1 parent ce015c2 commit 875b7c9

File tree

1 file changed

+63
-51
lines changed

1 file changed

+63
-51
lines changed

git-gui.sh

Lines changed: 63 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -60,54 +60,6 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
6060
}
6161
}
6262

63-
######################################################################
64-
##
65-
## configure our library
66-
67-
set oguilib {@@GITGUI_LIBDIR@@}
68-
set oguirel {@@GITGUI_RELATIVE@@}
69-
if {$oguirel eq {1}} {
70-
set oguilib [file dirname [file dirname [file normalize $argv0]]]
71-
set oguilib [file join $oguilib share git-gui lib]
72-
} elseif {[string match @@* $oguirel]} {
73-
set oguilib [file join [file dirname [file normalize $argv0]] lib]
74-
}
75-
76-
set idx [file join $oguilib tclIndex]
77-
if {[catch {set fd [open $idx r]} err]} {
78-
catch {wm withdraw .}
79-
tk_messageBox \
80-
-icon error \
81-
-type ok \
82-
-title "git-gui: fatal error" \
83-
-message $err
84-
exit 1
85-
}
86-
if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
87-
set idx [list]
88-
while {[gets $fd n] >= 0} {
89-
if {$n ne {} && ![string match #* $n]} {
90-
lappend idx $n
91-
}
92-
}
93-
} else {
94-
set idx {}
95-
}
96-
close $fd
97-
98-
if {$idx ne {}} {
99-
set loaded [list]
100-
foreach p $idx {
101-
if {[lsearch -exact $loaded $p] >= 0} continue
102-
source [file join $oguilib $p]
103-
lappend loaded $p
104-
}
105-
unset loaded p
106-
} else {
107-
set auto_path [concat [list $oguilib] $auto_path]
108-
}
109-
unset -nocomplain oguirel idx fd
110-
11163
######################################################################
11264
##
11365
## read only globals
@@ -532,7 +484,11 @@ if {$_git eq {}} {
532484

533485
if {[catch {set _git_version [git --version]} err]} {
534486
catch {wm withdraw .}
535-
error_popup "Cannot determine Git version:
487+
tk_messageBox \
488+
-icon error \
489+
-type ok \
490+
-title "git-gui: fatal error" \
491+
-message "Cannot determine Git version:
536492
537493
$err
538494
@@ -541,7 +497,11 @@ $err
541497
}
542498
if {![regsub {^git version } $_git_version {} _git_version]} {
543499
catch {wm withdraw .}
544-
error_popup "Cannot parse Git version string:\n\n$_git_version"
500+
tk_messageBox \
501+
-icon error \
502+
-type ok \
503+
-title "git-gui: fatal error" \
504+
-message "Cannot parse Git version string:\n\n$_git_version"
545505
exit 1
546506
}
547507

@@ -619,14 +579,66 @@ proc git-version {args} {
619579

620580
if {[git-version < 1.5]} {
621581
catch {wm withdraw .}
622-
error_popup "[appname] requires Git 1.5.0 or later.
582+
tk_messageBox \
583+
-icon error \
584+
-type ok \
585+
-title "git-gui: fatal error" \
586+
-message "[appname] requires Git 1.5.0 or later.
623587
624588
You are using [git-version]:
625589
626590
[git --version]"
627591
exit 1
628592
}
629593

594+
######################################################################
595+
##
596+
## configure our library
597+
598+
set oguilib {@@GITGUI_LIBDIR@@}
599+
set oguirel {@@GITGUI_RELATIVE@@}
600+
if {$oguirel eq {1}} {
601+
set oguilib [file dirname [file dirname [file normalize $argv0]]]
602+
set oguilib [file join $oguilib share git-gui lib]
603+
} elseif {[string match @@* $oguirel]} {
604+
set oguilib [file join [file dirname [file normalize $argv0]] lib]
605+
}
606+
607+
set idx [file join $oguilib tclIndex]
608+
if {[catch {set fd [open $idx r]} err]} {
609+
catch {wm withdraw .}
610+
tk_messageBox \
611+
-icon error \
612+
-type ok \
613+
-title "git-gui: fatal error" \
614+
-message $err
615+
exit 1
616+
}
617+
if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
618+
set idx [list]
619+
while {[gets $fd n] >= 0} {
620+
if {$n ne {} && ![string match #* $n]} {
621+
lappend idx $n
622+
}
623+
}
624+
} else {
625+
set idx {}
626+
}
627+
close $fd
628+
629+
if {$idx ne {}} {
630+
set loaded [list]
631+
foreach p $idx {
632+
if {[lsearch -exact $loaded $p] >= 0} continue
633+
source [file join $oguilib $p]
634+
lappend loaded $p
635+
}
636+
unset loaded p
637+
} else {
638+
set auto_path [concat [list $oguilib] $auto_path]
639+
}
640+
unset -nocomplain oguirel idx fd
641+
630642
######################################################################
631643
##
632644
## feature option selection

0 commit comments

Comments
 (0)