From c994dc568e2985536dd1a836135848f823379e6c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 9 Apr 2007 06:42:09 +0000 Subject: [PATCH] - Blame now works - Added FormatCode() and it's helper _FormatSpaces() --- blame.php | 37 +++++--------- includes/functions.php | 55 +++++++++++++++++++++ includes/svncommon.php | 61 +----------------------- includes/svnlib.php | 82 -------------------------------- templates/default/blame_line.tpl | 6 +-- 5 files changed, 72 insertions(+), 169 deletions(-) diff --git a/blame.php b/blame.php index bcb1b43..7aab44e 100644 --- a/blame.php +++ b/blame.php @@ -24,39 +24,28 @@ $fetchtemplates = array( 'blame' ); +define('SVN', '$Id$'); + require_once('./global.php'); -$navbar = $controller->construct_breadcrumb(); +$navbar = ConstructNavbar(); // ################################################################### -$latest = $controller->cachev->fetch_node(); - -$link['log'] = $controller->href_compound('log.php'); - -$show['head'] = ($latest['revision'] != $controller->revctx); -if ($show['head']) -{ - $link['gohead'] = $controller->href_compound('blame.php', null, Paths::fetch_rev_str(false, 'HEAD')); - $link['diffhead'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, 'HEAD', $contoller->revctx)); -} - -$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->revctx, $prev)); -} - -// ################################################################### +$revision = new Revision($input->in['repos'], $input->in['rev'], $input->in['path']); -$blame = new SVNBlame($controller); +$blame = BSXml::Parse($lib->run('blame --xml -r' . $revision->revision . ' ' . $lib->arg($repos->fetchPath($input->in['repos']) . $input->in['path']), true)); +$blame = $blame['blame']['target']['entry']; +BSXml::UnifyNode($blame); -$lines = ''; +$catdata = $lib->run('cat -r' . $revision->revision . ' ' . $lib->arg($repos->fetchPath($input->in['repos']) . $input->in['path'])); -foreach ($blame->fetch() AS $entry) +foreach ($catdata AS $num => $line) { - $entry['view_link'] = $controller->href_compound('view.php', null, Paths::fetch_rev_str(false, $entry['rev'])); - $entry['line_clean'] = SVNCommon::format($entry['line']); + $revision = $blame[$num]['commit']['revision']; + $author = $blame[$num]['commit']['author']['value']; + $view = ConstructLink('view', $input->in['repos'], $input->in['path'], $revision); + $line = FormatCode($line); eval('$lines .= "' . $template->fetch('blame_line') . '";'); } diff --git a/includes/functions.php b/includes/functions.php index 21a9374..cea2366 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -171,6 +171,61 @@ function ConstructLink($action, $repos, $path, $rev) return BSRegister::Get('webpath') . '/' . $action . '/' . $repos . ':' . $path . ($rev > 0 ? '@' . $rev : ''); } +// ################################################################### +/** +* Prepares data for output +* +* @param string Standard data +* +* @return string Output-ready data +*/ +function FormatCode($string) +{ + // convert entities + $string = htmlspecialchars($string); + + // tabs to 5 spaces + $string = str_replace("\t", ' ', $string); + + // spaces to nbsp + if (true) + { + $string = preg_replace('#( +)#e', '_FormatSpaces("\1")', $string); + } + // no word wrap + else + { + $string = str_replace(' ', ' ', $string); + } + + // convert advanced diff + $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('', ''), $string); + $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '', $string); + + // nl2br + $string = nl2br($string); + + return $string; +} + +// ################################################################### +/** +* Counts the spaces and replaces two or more ones +* +* @param string Spaced string +* +* @return string  'd string +*/ +function _FormatSpaces($thestring) +{ + if (strlen($thestring) >= 2) + { + $thestring = str_replace(' ', ' ', $thestring); + } + + return $thestring; +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ diff --git a/includes/svncommon.php b/includes/svncommon.php index f9ffa8d..8a128c2 100644 --- a/includes/svncommon.php +++ b/includes/svncommon.php @@ -33,66 +33,7 @@ * @version $Id$ */ class SVNCommon -{ - // ################################################################### - /** - * Prepares data for output - * - * @access public - * - * @param string Standard data - * - * @return string Output-ready data - */ - function format($string) - { - // convert entities - $string = htmlspecialchars($string); - - // tabs to 5 spaces - $string = str_replace("\t", ' ', $string); - - // spaces to nbsp - if (true) - { - $string = preg_replace('#( +)#e', 'SVNCommon::format_spaces("\1")', $string); - } - // no word wrap - else - { - $string = str_replace(' ', ' ', $string); - } - - // convert advanced diff - $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('', ''), $string); - $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '', $string); - - // nl2br - $string = nl2br($string); - - return $string; - } - - // ################################################################### - /** - * Counts the spaces and replaces two or more ones - * - * @access private - * - * @param string Spaced string - * - * @return string  'd string - */ - function format_spaces($thestring) - { - if (strlen($thestring) >= 2) - { - $thestring = str_replace(' ', ' ', $thestring); - } - - return $thestring; - } - +{ // ################################################################### /** * Prints the file changed list diff --git a/includes/svnlib.php b/includes/svnlib.php index 0827df0..f2ab77f 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -200,88 +200,6 @@ class SVNLib } } -/** -* Annotation/blame system; constructs an array that is ready for output -* -* @package ViewSVN -* @version $Id$ -*/ -class SVNBlame -{ - /** - * Array of blame information - * @var array - * @access private - */ - var $blame = array(); - - /** - * Raw "svn blame" output - * @var array - * @access private - */ - var $rawoutput; - - // ################################################################### - /** - * Constructor: create blame and store data - * - * @param object Controller - */ - function SVNBlame(&$controller) - { - $this->rawoutput = $controller->library->command('blame'); - $this->process(); - } - - // ################################################################### - /** - * Returns blame for display - * - * @access public - * - * @return array Blame data - */ - function fetch() - { - return $this->blame; - } - - // ################################################################### - /** - * Parses the blame data - * - * @access private - */ - function process() - { - $lineno = 1; - - foreach ($this->rawoutput AS $line) - { - if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)\s(.*)$#', $line, $matches)) - { - $this->blame[] = array( - 'rev' => $matches[1], - 'author' => $matches[2], - 'line' => $matches[3], - 'lineno' => $lineno++ - ); - } - // a blank line - else if (preg_match('#^\s+([0-9]+)\s+([\w\.\-_]+)$#', $line, $matches)) - { - $this->blame[] = array( - 'rev' => $matches[1], - 'author' => $matches[2], - 'line' => '', - 'lineno' => $lineno++ - ); - } - } - } -} - /** * Diff system; constructs a diff array that is ready for output * diff --git a/templates/default/blame_line.tpl b/templates/default/blame_line.tpl index a2d34a1..949617c 100644 --- a/templates/default/blame_line.tpl +++ b/templates/default/blame_line.tpl @@ -1,5 +1,5 @@ - $entry[rev] - $entry[author] - $entry[line_clean] + $revision + $author + $line -- 2.43.5