From 6175aac732657bde284369cd8861626672ea72b8 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 12 Jan 2006 07:16:57 +0000 Subject: [PATCH] Random pieces that don't work all quite yet. browse.php is getting there --- browse.php | 12 +++++--- includes/cachev.php | 58 ++++++++++++++++++++++++++++++++++-- includes/svnlib.php | 16 ++++++++++ templates/default/browse.tpl | 4 +-- 4 files changed, 81 insertions(+), 9 deletions(-) diff --git a/browse.php b/browse.php index 2903846..50e86ca 100644 --- a/browse.php +++ b/browse.php @@ -30,16 +30,19 @@ $navbar = $viewsvn->paths->construct_breadcrumb($viewsvn->paths->path); // ################################################################### +$node = preg_replace('#(^/|/$)#', '', ($viewsvn->paths->relpath == '' ? $viewsvn->paths->path : $viewsvn->paths->relpath)); +$latest = $cachev->fetch_latest_revision($node); + $link['log'] = $viewsvn->paths->out('log.php' . $viewsvn->paths->revstr, $viewsvn->paths->path); -$show['head'] = ($viewsvn->svn->common->fetch_head_rev($viewsvn->paths->path) != $viewsvn->paths->revnum AND $viewsvn->paths->revnum != 'HEAD'); +$show['head'] = ($latest['revnow'] != $viewsvn->paths->revnum AND $viewsvn->paths->revnum != 'HEAD'); if ($show['head']) { $link['gohead'] = $viewsvn->paths->out('browse.php' . $viewsvn->paths->fetch_rev_str(false, 'HEAD'), $viewsvn->paths->path); $link['diffhead'] = $viewsvn->paths->out('diff.php' . $viewsvn->paths->fetch_rev_str(true, 'HEAD', $viewsvn->paths->revnum), $viewsvn->paths->path); } -$show['prev'] = (($prev = $viewsvn->svn->common->fetch_prev_rev($viewsvn->paths->path, $viewsvn->paths->revnum)) != -1 ? true : false); +//$show['prev'] = (($prev = $cachev->fetch_prev_revision($viewsvn->paths->path, $viewsvn->paths->revnum)) != -1 ? true : false); if ($show['prev']) { $link['diffprev'] = $viewsvn->paths->out('diff.php' . $viewsvn->paths->fetch_rev_str(true, $viewsvn->paths->revnum, $prev), $viewsvn->paths->path); @@ -47,10 +50,11 @@ if ($show['prev']) // ################################################################### -$revinfo = $viewsvn->svn->common->fetch_log($viewsvn->paths->path, $viewsvn->paths->revnum); - +$revinfo = $cachev->fetch_revision($viewsvn->paths->revnum); $revinfo['message_clean'] = $viewsvn->svn->format_log_message($revinfo['message']); +$revinfo['date'] = $viewsvn->svn->format_date_string($revinfo['dateline']); + $listing = $viewsvn->svn->ls($viewsvn->paths->repos, $viewsvn->paths->relpath, $viewsvn->paths->revnum); $nodes = ''; diff --git a/includes/cachev.php b/includes/cachev.php index b21d738..f09af73 100644 --- a/includes/cachev.php +++ b/includes/cachev.php @@ -98,12 +98,64 @@ class cacheV { $revision = $this->registry->clean($revision, TYPE_UINT); - if (!isset($this->memcache["$revision"])) + if (!isset($this->memcache['revs']["$revision"])) { - $this->memcache["$revision"] = $this->registry->db->query_first("SELECT * FROM {$this->hash}_revs WHERE revision = $revision"); + $this->memcache['revs']["$revision"] = $this->registry->db->query_first("SELECT * FROM {$this->hash}_revs " . ($revision == 0 ? " ORDER BY revision DESC LIMIT 1" : "WHERE revision = $revision")); + $this->memcache['revs']["$revision"]['files'] = unserialize($this->memcache['revs']["$revision"]['files']); } - return $this->memcache["$revision"]; + return $this->memcache['revs']["$revision"]; + } + + // ################################################################### + /** + * Returns the revision entry before the specified one + * + * @access public + * + * @param integer Revision number + * + * @return array Complete revision/commit entry + */ + function fetch_prev_revision($revision) + { + static $prevrevs; + + $revision = $this->registry->clean($revision, TYPE_UINT); + + if (!isset($prevrevs["$revision"])) + { + $result = $this->registry->db->query_first("SELECT * FROM {$this->hash}_revs ORDER BY revision DESC LIMIT 1 WHERE revision < $revision"); + $revision = $result['revision']; + $this->memcache['revs']["$revision"] = $result; + $this->memcache['revs']["$revision"]['files'] = unserialize($this->memcache['revs']["$revision"]['files']); + } + else + { + $revision = $prevrevs["$revision"]; + } + + return $this->memcache['revs']["$revision"]; + } + + // ################################################################### + /** + * Fetches the latest revision for a given path + * + * @access public + * + * @param string Node path + * + * @return integer Latest revision; FALSE if none (not in HEAD) + */ + function fetch_latest_revision($node) + { + if (!isset($this->memcache['nodes']["$node"])) + { + $this->memcache['nodes']["$node"] = $this->registry->db->query_first("SELECT * FROM {$this->hash}_nodes WHERE name = '" . $this->registry->escape($node) . "'"); + } + + return $this->memcache['nodes']["$node"]; } // ################################################################### diff --git a/includes/svnlib.php b/includes/svnlib.php index 8ed39ba..3fd86ca 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -173,6 +173,22 @@ class SVNLib return $message; } + // ################################################################### + /** + * Parses a date from Xquery XML outut + * + * @access public + * + * @param string Date string + * + * @return string Formatted and readable date string + */ + function format_date_string($string) + { + // 2005-01-23T20:42:53.703057Z + return preg_replace('#(....)\-(..)\-(..)T(..):(..):(..).(.*)Z#e', 'gmdate("r", mktime(\4, \5, \6, \2, \3, \1))', $string); + } + /** * Counts the spaces and replaces two or more ones * diff --git a/templates/default/browse.tpl b/templates/default/browse.tpl index 14167da..c2c6c07 100644 --- a/templates/default/browse.tpl +++ b/templates/default/browse.tpl @@ -9,9 +9,9 @@ $header
{@"Revision Information"}
-
{@"Revision"}: $revinfo[rev]
+
{@"Revision"}: $revinfo[revision]
{@"Author"}: $revinfo[author]
-
{@"Date"}: $revinfo[date] $revinfo[timezone]
+
{@"Date"}: $revinfo[date]
{@"Message"}: $revinfo[message_clean]
-- 2.22.5