From e5052ed38319744092d57ab66853cb66f5ff860c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 9 Apr 2007 05:22:05 +0000 Subject: [PATCH] We now can get revision information: - Added Revision::getRevisionInfo() - Revision now takes an optional subpath, which allows us to find the most recent change revision - Added FormatLogMessage() - Added FormatSvnDate() --- browse.php | 5 +-- includes/class_revision.php | 50 +++++++++++++++++++++- includes/functions.php | 77 ++++++++++++++++++++++++++++++++++ includes/svncommon.php | 80 ------------------------------------ templates/default/browse.tpl | 8 ++-- templates/default/view.tpl | 8 ++-- view.php | 8 +--- 7 files changed, 137 insertions(+), 99 deletions(-) diff --git a/browse.php b/browse.php index c892d22..2fb0eea 100644 --- a/browse.php +++ b/browse.php @@ -33,7 +33,7 @@ $navbar = ConstructNavbar(); // ################################################################### -$revision = new Revision($input->in['repos'], $input->in['rev']); +$revision = new Revision($input->in['repos'], $input->in['rev'], $input->in['path']); // ################################################################### @@ -43,8 +43,7 @@ $proplist = FormatPropList($props); // ################################################################### -// $revinfo['message_clean'] = SVNCommon::format_log_message($revinfo['message']); -// $revinfo['date'] = SVNCommon::format_date_string($revinfo['dateline']); +$revision->getRevisionInfo(); $listing = BSXml::Parse($lib->run('ls --xml -r' . $revision->revision . ' ' . $lib->arg($repos->fetchPath($input->in['repos']) . $input->in['path']), true)); diff --git a/includes/class_revision.php b/includes/class_revision.php index 02e8693..bec4459 100644 --- a/includes/class_revision.php +++ b/includes/class_revision.php @@ -44,23 +44,55 @@ class Revision */ private $repos; + /** + * The subpath inside the repository we're getting info for + * @var string + */ + private $subpath; + /** * The revision number * @var integer */ public $revision; + /** + * The commmit message for this revision + * @var string + */ + public $message; + + /** + * The unparsed/unformatted log message + * @var string + */ + public $messageClean; + + /** + * Author who committed the revision + * @var string + */ + public $author; + + /** + * The date and time this revision was made + * @var string + */ + public $datetime; + // ################################################################### /** * Creates a new revision for a given repository and revision * * @param string Repository * @param integer Revision to get; to get HEAD, specify 0 + * @param string Path inside the repository to get info for */ - public function __construct($repos, $rev = 0) + public function __construct($repos, $rev = 0, $subpath = null) { $this->path = BSRegister::Get('repos')->fetchPath($repos); $this->repos = $repos; + $this->subpath = $subpath; $this->_fetchRevision($rev); } @@ -95,6 +127,20 @@ class Revision return $proplist; } + // ################################################################### + /** + * Gets the revision information (commit message, author, date) for the + * revision + */ + public function getRevisionInfo() + { + $xml = BSXml::Parse(BSRegister::Get('lib')->run('log --xml -r' . $this->revision . ' ' . BSRegister::Get('lib')->arg($this->path), true)); + $this->message = FormatLogMessage($xml['log']['logentry']['msg']['value']); + $this->messasgeClean = $xml['log']['logentry']['msg']['value']; + $this->datetime = FormatSvnDate($xml['log']['logentry']['date']['value']); + $this->author = $xml['log']['logentry']['author']['value']; + } + // ################################################################### /** * Gets the desired XML revision information from the repository @@ -103,7 +149,7 @@ class Revision */ private function _fetchRevision($desired) { - $xml = BSXml::Parse(BSRegister::Get('lib')->run('info --xml ' . ($desired > 0 ? '-r' . intval($desired) . ' ' : '') . BSRegister::Get('lib')->arg($this->path), true)); + $xml = BSXml::Parse(BSRegister::Get('lib')->run('info --xml ' . ($desired > 0 ? '-r' . intval($desired) . ' ' : '') . BSRegister::Get('lib')->arg($this->path . $this->subpath), true)); $this->revision = intval($xml['info']['entry']['commit']['revision']); } } diff --git a/includes/functions.php b/includes/functions.php index ccdd8dc..808159f 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -69,6 +69,83 @@ function FormatPropList($props) return $proplist; } +// ################################################################### +/** +* Formats a SVN log message +* +* @param string Unformatted log message +* +* @return string Output-ready log message +*/ +function FormatLogMessage($message) +{ + global $viewsvn; + + $message = BSRegister::Get('input')->entityEncode($message); + + // TODO - fix the revision links + // $message = preg_replace('#r([0-9]+)#e', '"maincontrol->href_struct("diff.php" . Paths::fetch_rev_str(true, "\1", 0), "/") . "\">r\1"', $message); + + $list = false; + $lines = explode("\n", $message); + $message = ''; + foreach ($lines AS $line) + { + if (preg_match('#^\s*?(\*|\-)\s?(.*)#', $line, $matches)) + { + if ($list) + { + $message .= '
  • ' . $matches[2] . '
  • '; + } + else + { + $message .= ''; + $message .= $line; + } + else + { + $message .= $line; + $message .= '
    '; + } + $list = false; + } + + $message .= "\n"; + } + + if ($list) + { + $message .= ''; + } + + $message = preg_replace('#(
    )*$#', '', $message); + + return $message; +} + +// ################################################################### +/** +* Parses a date from SVN into something more human-friendly +* +* @param string Date string +* +* @return string Formatted and readable date string +*/ +function FormatSvnDate($string) +{ + // 2005-01-23T20:42:53.703057Z + return preg_replace('#(....)\-(..)\-(..)T(..):(..):(..).(.*)Z#e', 'gmdate("r", mktime(\4, \5, \6, \2, \3, \1))', $string); +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/includes/svncommon.php b/includes/svncommon.php index c7781ed..f9ffa8d 100644 --- a/includes/svncommon.php +++ b/includes/svncommon.php @@ -73,86 +73,6 @@ class SVNCommon return $string; } - // ################################################################### - /** - * Formats a SVN log message - * - * @access public - * - * @param string Unformatted log message - * - * @return string Output-ready log message - */ - function format_log_message($message) - { - global $viewsvn; - - $message = $viewsvn->entity_encode($message); - - $message = preg_replace('#r([0-9]+)#e', '"maincontrol->href_struct("diff.php" . Paths::fetch_rev_str(true, "\1", 0), "/") . "\">r\1"', $message); - - $list = false; - $lines = explode("\n", $message); - $message = ''; - foreach ($lines AS $line) - { - if (preg_match('#^\s*?(\*|\-)\s?(.*)#', $line, $matches)) - { - if ($list) - { - $message .= '
  • ' . $matches[2] . '
  • '; - } - else - { - $message .= ''; - $message .= $line; - } - else - { - $message .= $line; - $message .= '
    '; - } - $list = false; - } - - $message .= "\n"; - } - - if ($list) - { - $message .= ''; - } - - $message = preg_replace('#(
    )*$#', '', $message); - - 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 27c16d1..37274a5 100644 --- a/templates/default/browse.tpl +++ b/templates/default/browse.tpl @@ -9,10 +9,10 @@ $header
    {@"Revision Information"}
    -
    {@"Revision"}: $revinfo[revision]
    -
    {@"Author"}: $revinfo[author]
    -
    {@"Date"}: $revinfo[date]
    -
    {@"Message"}: $revinfo[message_clean]
    +
    {@"Revision"}: $revision->revision
    +
    {@"Author"}: $revision->author
    +
    {@"Date"}: $revision->datetime
    +
    {@"Message"}: $revision->message
    diff --git a/templates/default/view.tpl b/templates/default/view.tpl index e4f2401..b55337f 100644 --- a/templates/default/view.tpl +++ b/templates/default/view.tpl @@ -10,10 +10,10 @@ $header
    {@"Revision Information"}
    -
    {@"Revision"}: $logmsg[revision]
    -
    {@"Author"}: $logmsg[author]
    -
    {@"Date"}: $logmsg[date]
    -
    {@"Message"}: $logmsg[message_clean]
    +
    {@"Revision"}: $revision->revision
    +
    {@"Author"}: $revision->author
    +
    {@"Date"}: $revision->datetime
    +
    {@"Message"}: $revision->message
    diff --git a/view.php b/view.php index e45180f..4475bc8 100644 --- a/view.php +++ b/view.php @@ -32,15 +32,11 @@ $navbar = ConstructNavbar(); // ################################################################### -$revision = new Revision($input->in['repos'], $input->in['rev']); +$revision = new Revision($input->in['repos'], $input->in['rev'], $input->in['path']); // ################################################################### -/*$logmsg = $controller->cachev->fetch_revision($controller->revctx); -unset($logmsg['files']); - -$logmsg['message_clean'] = SVNCommon::format_log_message($logmsg['message']); -$logmsg['date'] = SVNCommon::format_date_string($logmsg['dateline']);*/ +$revision->getRevisionInfo(); $catdata = $lib->run('cat -r' . $revision->revision . ' ' . $lib->arg($repos->fetchPath($input->in['repos']) . $input->in['path']), true); -- 2.43.5