@matheusbsbs / matheus-bagliano / commits / d696702209
Fork 0

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 <spearce@spearce.org>

Shawn O. Pearce committed Jul 8, 2007 at 18:48 UTC d696702209dd0d4c20d2b87b5bc10cae3d54e839
1 file changed +58 -15
git-gui.sh
+58 -15
@@ -308,33 +308,76 @@ proc tk_optionMenu {w varName args} {
308 ##
309 ## version check
310
311 -set req_maj 1
312 -set req_min 5
313 -
314 -if {[catch {set v [git --version]} err]} {
311 +if {[catch {set _git_version [git --version]} err]} {
312 catch {wm withdraw .}
313 error_popup "Cannot determine Git version:
314
315 $err
316
320 -[appname] requires Git $req_maj.$req_min or later."
317 +[appname] requires Git 1.5.0 or later."
318 + exit 1
319 +}
320 +if {![regsub {^git version } $_git_version {} _git_version]} {
321 + catch {wm withdraw .}
322 + error_popup "Cannot parse Git version string:\n\n$_git_version"
323 exit 1
324 }
323 -if {[regexp {^git version (\d+)\.(\d+)} $v _junk act_maj act_min]} {
324 - if {$act_maj < $req_maj
325 - || ($act_maj == $req_maj && $act_min < $req_min)} {
326 - catch {wm withdraw .}
327 - error_popup "[appname] requires Git $req_maj.$req_min or later.
325 +regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
326 +regsub {\.rc[0-9]+$} $_git_version {} _git_version
327
329 -You are using $v."
330 - exit 1
328 +proc git-version {args} {
329 + global _git_version
330 +
331 + switch [llength $args] {
332 + 0 {
333 + return $_git_version
334 }
332 -} else {
335 +
336 + 2 {
337 + set op [lindex $args 0]
338 + set vr [lindex $args 1]
339 + set cm [package vcompare $_git_version $vr]
340 + return [expr $cm $op 0]
341 + }
342 +
343 + 4 {
344 + set type [lindex $args 0]
345 + set name [lindex $args 1]
346 + set parm [lindex $args 2]
347 + set body [lindex $args 3]
348 +
349 + if {($type ne {proc} && $type ne {method})} {
350 + error "Invalid arguments to git-version"
351 + }
352 + if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
353 + error "Last arm of $type $name must be default"
354 + }
355 +
356 + foreach {op vr cb} [lrange $body 0 end-2] {
357 + if {[git-version $op $vr]} {
358 + return [uplevel [list $type $name $parm $cb]]
359 + }
360 + }
361 +
362 + return [uplevel [list $type $name $parm [lindex $body end]]]
363 + }
364 +
365 + default {
366 + error "git-version >= x"
367 + }
368 +
369 + }
370 +}
371 +
372 +if {[git-version < 1.5]} {
373 catch {wm withdraw .}
334 - error_popup "Cannot parse Git version string:\n\n$v"
374 + error_popup "[appname] requires Git 1.5.0 or later.
375 +
376 +You are using [git-version]:
377 +
378 +[git --version]"
379 exit 1
380 }
337 -unset -nocomplain v _junk act_maj act_min req_maj req_min
381
382 ######################################################################
383 ##