[pLog-svn] r5901 - in plog/branches/lifetype-1.2/class: misc test/tests/misc
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Tue Sep 4 01:00:41 EDT 2007
Author: jondaley
Date: 2007-09-04 01:00:41 -0400 (Tue, 04 Sep 2007)
New Revision: 5901
Modified:
plog/branches/lifetype-1.2/class/misc/version.class.php
plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php
Log:
version compare works better now, with revision numbers
Modified: plog/branches/lifetype-1.2/class/misc/version.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/misc/version.class.php 2007-09-04 04:10:07 UTC (rev 5900)
+++ plog/branches/lifetype-1.2/class/misc/version.class.php 2007-09-04 05:00:41 UTC (rev 5901)
@@ -112,8 +112,23 @@
// as it will make it easier for version_compare to work
$v1 = str_replace( "lifetype-", "", $v1 );
$v2 = str_replace( "lifetype-", "", $v2 );
-
- return( version_compare( $v1, $v2 ));
+
+ // version_compare doesn't like dashes/underscores at the end of a number
+ $v1 = str_replace( "_", "-", $v1 );
+ $v2 = str_replace( "_", "-", $v2 );
+
+ list($v1, $rev1) = explode("-r", $v1);
+ list($v2, $rev2) = explode("-r", $v2);
+
+ // compare major versions first
+ $res = version_compare( $v1, $v2 );
+
+ if($res == -1 || $res == 1)
+ return $res;
+
+ if(!$rev1) $rev1 = 0;
+ if(!$rev2) $rev2 = 0;
+ return (strcmp($rev1, $rev2));
}
/**
Modified: plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php 2007-09-04 04:10:07 UTC (rev 5900)
+++ plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php 2007-09-04 05:00:41 UTC (rev 5901)
@@ -43,7 +43,7 @@
function testVersionCompare()
{
foreach( $this->_data as $version ) {
- $this->assertEquals( Version::compare( $version[0], $version[1] ), $version[2],
+ $this->assertEquals( $version[2], Version::compare( $version[0], $version[1] ),
"Error comparing <b>$version[0]</b> with <b>$version[1]</b>" );
}
}
More information about the pLog-svn
mailing list