From: Shawn O. Pearce Date: Sun, 8 Jul 2007 22:48:08 +0000 (-0400) Subject: git-gui: New Git version check support routine X-Git-Tag: v1.5.3-rc1~16^2~35 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d696702209dd0d4c20d2b87b5bc10cae3d54e839;p=git.git git-gui: New Git version check support routine Some newer features of git-gui want to rely on features that are new to Git 1.5.3. Since they were added as part of the 1.5.3 development series we cannot use those features with versions of Git that are older than 1.5.3, such as from the stable 1.5.2 series. We introduce [git-version >= 1.5.3] to allow the caller to get a response of 0 if the current version of git is < 1.5.3 and 1 if the current version of git is >= 1.5.3. This makes it easy to setup conditional code based upon the version of Git available to us at runtime. Instead of parsing the version text by hand we now use the Tcl [package vcompare] subcommand to compare the two version strings. This works nicely, as Tcl as already done all of the hard work of doing version comparsions. But we do have to remove the Git specific components such as the Git commit SHA-1, commit count and release candidate suffix (rc) as we want only the final release version number. Signed-off-by: Shawn O. Pearce --- diff --git a/git-gui.sh b/git-gui.sh index 0096f4913..c36a986b7 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -308,33 +308,76 @@ proc tk_optionMenu {w varName args} { ## ## version check -set req_maj 1 -set req_min 5 - -if {[catch {set v [git --version]} err]} { +if {[catch {set _git_version [git --version]} err]} { catch {wm withdraw .} error_popup "Cannot determine Git version: $err -[appname] requires Git $req_maj.$req_min or later." +[appname] requires Git 1.5.0 or later." + exit 1 +} +if {![regsub {^git version } $_git_version {} _git_version]} { + catch {wm withdraw .} + error_popup "Cannot parse Git version string:\n\n$_git_version" exit 1 } -if {[regexp {^git version (\d+)\.(\d+)} $v _junk act_maj act_min]} { - if {$act_maj < $req_maj - || ($act_maj == $req_maj && $act_min < $req_min)} { - catch {wm withdraw .} - error_popup "[appname] requires Git $req_maj.$req_min or later. +regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version +regsub {\.rc[0-9]+$} $_git_version {} _git_version -You are using $v." - exit 1 +proc git-version {args} { + global _git_version + + switch [llength $args] { + 0 { + return $_git_version } -} else { + + 2 { + set op [lindex $args 0] + set vr [lindex $args 1] + set cm [package vcompare $_git_version $vr] + return [expr $cm $op 0] + } + + 4 { + set type [lindex $args 0] + set name [lindex $args 1] + set parm [lindex $args 2] + set body [lindex $args 3] + + if {($type ne {proc} && $type ne {method})} { + error "Invalid arguments to git-version" + } + if {[llength $body] < 2 || [lindex $body end-1] ne {default}} { + error "Last arm of $type $name must be default" + } + + foreach {op vr cb} [lrange $body 0 end-2] { + if {[git-version $op $vr]} { + return [uplevel [list $type $name $parm $cb]] + } + } + + return [uplevel [list $type $name $parm [lindex $body end]]] + } + + default { + error "git-version >= x" + } + + } +} + +if {[git-version < 1.5]} { catch {wm withdraw .} - error_popup "Cannot parse Git version string:\n\n$v" + error_popup "[appname] requires Git 1.5.0 or later. + +You are using [git-version]: + +[git --version]" exit 1 } -unset -nocomplain v _junk act_maj act_min req_maj req_min ###################################################################### ##