From 29dcc016dc9954e072b34bc696f8b63c9aa4c596 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 29 Jan 2009 13:28:04 -0700 Subject: [PATCH] Various Cleanup/fixes. --- framework/Vcs/lib/Horde/Vcs/Rcs.php | 43 +++++++++++++++---------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/framework/Vcs/lib/Horde/Vcs/Rcs.php b/framework/Vcs/lib/Horde/Vcs/Rcs.php index ff80b8720..136141f12 100644 --- a/framework/Vcs/lib/Horde/Vcs/Rcs.php +++ b/framework/Vcs/lib/Horde/Vcs/Rcs.php @@ -30,14 +30,21 @@ class Horde_Vcs_Rcs extends Horde_Vcs */ public function getRevisionRange($file, $r1, $r2) { - if ($this->cmp($r1, $r2) == 1) { + switch ($this->cmp($r1, $r2)) { + case 0: + return array(); + + case 1: $curr = $this->prev($r1); $stop = $this->prev($r2); $flip = true; - } else { + break; + + case -1: $curr = $r2; $stop = $r1; $flip = false; + break; } $ret_array = array(); @@ -45,10 +52,10 @@ class Horde_Vcs_Rcs extends Horde_Vcs do { $ret_array[] = $curr; $curr = $this->prev($curr); - if ($curr == $stop) { + if ($curr === $stop) { return ($flip) ? array_reverse($ret_array) : $ret_array; } - } while ($this->cmp($curr, $stop) != -1); + } while (!is_null($curr) && ($this->cmp($curr, $stop) != -1)); return array(); } @@ -271,21 +278,6 @@ class Horde_Vcs_Rcs extends Horde_Vcs } /** - * The size of a revision number is the number of portions it has. - * For example, 1,2.3.4 is of size 4. - * - * @param string $val Revision number to determine size of. - * - * @return integer Size of revision number. - */ - public function sizeof($val) - { - return $this->isValidRevision($val) - ? (substr_count($val, '.') + 1) - : 0; - } - - /** * Given two revision numbers, this figures out which one is * greater than the other by stepping along the decimal points * until a difference is found, at which point a sign comparison @@ -299,7 +291,7 @@ class Horde_Vcs_Rcs extends Horde_Vcs */ public function cmp($rev1, $rev2) { - return version_compare($rev1, $rev2); + return strnatcasecmp($rev1, $rev2); } /** @@ -310,8 +302,7 @@ class Horde_Vcs_Rcs extends Horde_Vcs * * @param string $rev Revision number to decrement. * - * @return string|boolean Revision number, or false if none could be - * determined. + * @return string Revision number, or null if none could be determined. */ public function prev($rev) { @@ -321,12 +312,12 @@ class Horde_Vcs_Rcs extends Horde_Vcs if (--$val > 0) { return substr($rev, 0, $last_dot) . $val; } else { - $last_dot--; + --$last_dot; while (--$last_dot) { if ($rev[$last_dot] == '.') { - return substr($rev, 0, $last_dot); - } elseif ($rev[$last_dot] == null) { - return false; + return substr($rev, 0, $last_dot); + } elseif (is_null($rev[$last_dot])) { + return null; } } } -- 2.11.0