From a94c5ef72cee35023d43212e15957abb03245223 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 22 Jan 2006 23:00:19 +0000 Subject: [PATCH] Add contextual revision number which should be used EVERYWHERE :) --- includes/cachev.php | 48 +++++++++++++++++++++++++++++++++++++++++ includes/controller.php | 10 +++++++++ view.php | 8 +++---- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/includes/cachev.php b/includes/cachev.php index 7215739..30fc759 100644 --- a/includes/cachev.php +++ b/includes/cachev.php @@ -180,6 +180,54 @@ class cacheV return max(array_keys($data)); } + // ################################################################### + /** + * Returns the revision entry that it's in context with the node. For + * instance, if the version 50 was passed and this node only has 48 as + * it's max, 48 will be returned. + * + * @access public + * + * @param integer Target revision + * + * @return integer Contextual revision + */ + function fetch_revision_context($target) + { + $data = $this->fetch_node(); + $data = $data['history']; + + if (isset($data["$target"])) + { + return $this->fetch_revision($target); + } + + $keys = array_keys($data); + + $prev = 0; + foreach ($keys AS $id => $revnum) + { + if ($target > $revnum) + { + $prev = $revnum; + if ($prev > $rev) + { + $rev = $prev; + } + } + else if ($target < $revnum) + { + $rev = $prev; + } + else + { + $rev = $keys[0]; + } + } + + return $this->fetch_revision($rev); + } + // ################################################################### /** * Fetches the latest revision for a given path diff --git a/includes/controller.php b/includes/controller.php index f5d0337..9f022fd 100644 --- a/includes/controller.php +++ b/includes/controller.php @@ -105,6 +105,13 @@ class Controller */ var $revstr; + /** + * The revision number in context for this node. For instance, r40 may be passed, but the file only has revision 38 (and that's what this would be) + * @var integer + * @access public + */ + var $revctx; + // ################################################################### /** * Constructor @@ -141,6 +148,9 @@ class Controller require_once('./includes/cachev.php'); $this->cachev = new cacheV($this); + + $this->revctx = $this->cachev->fetch_revision_context($this->revnum); + $this->revctx = $this->revctx['revision']; } // ################################################################### diff --git a/view.php b/view.php index 0865d69..75ffd72 100644 --- a/view.php +++ b/view.php @@ -37,18 +37,18 @@ $show['head'] = ($latest['revision'] != $controller->revnum AND $controller->rev if ($show['head']) { $link['gohead'] = $controller->href_compound('view.php', null, Paths::fetch_rev_str(false, 'HEAD')); - $link['diffhead'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, 'HEAD', $controller->revnum)); + $link['diffhead'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, 'HEAD', $controller->revctx)); } -$show['prev'] = ($prev = $controller->cachev->fetch_prev_revision($controller->revnum)); +$show['prev'] = ($prev = $controller->cachev->fetch_prev_revision($controller->revctx)); if ($show['prev']) { - $link['diffprev'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, $controller->revnum, $prev['revision'])); + $link['diffprev'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, $controller->revctx, $prev['revision'])); } // ################################################################### -$logmsg = $controller->cachev->fetch_revision($controller->revnum); +$logmsg = $controller->cachev->fetch_revision($controller->revctx); unset($logmsg['files']); $logmsg['message_clean'] = SVNCommon::format_log_message($logmsg['message']); -- 2.43.5