@matheusbsbs / matheus-bagliano / commits / 875b7c9368
Fork 0

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>

Shawn O. Pearce committed Aug 22, 2007 at 02:41 UTC 875b7c93686d16e083dcea8b544e4f204113d8de
1 file changed +63 -51
git-gui.sh
+63 -51
@@ -60,54 +60,6 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
60 }
61 }
62
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 -
63 ######################################################################
64 ##
65 ## read only globals
@@ -532,7 +484,11 @@ if {$_git eq {}} {
484
485 if {[catch {set _git_version [git --version]} err]} {
486 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:
492
493 $err
494
@@ -541,7 +497,11 @@ $err
497 }
498 if {![regsub {^git version } $_git_version {} _git_version]} {
499 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"
505 exit 1
506 }
507
@@ -619,7 +579,11 @@ proc git-version {args} {
579
580 if {[git-version < 1.5]} {
581 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.
587
588 You are using [git-version]:
589
@@ -627,6 +591,54 @@ You are using [git-version]:
591 exit 1
592 }
593
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 +
642 ######################################################################
643 ##
644 ## feature option selection