From adf294d0866e08d49b80fffa386d215886d963b2 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 28 Aug 2005 00:06:14 +0000 Subject: [PATCH] Blame stuff is done --- blame.php | 44 ++++++++++++++++++++++++ includes/svnlib.php | 81 +++++++++++++++++++++++++++++++++++++++++++++ log.php | 2 +- 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 blame.php diff --git a/blame.php b/blame.php new file mode 100644 index 0000000..9b66167 --- /dev/null +++ b/blame.php @@ -0,0 +1,44 @@ +paths->parse(); +$repos = $viewsvn->paths->fetch_repos($path); +$relpath = $viewsvn->paths->fetch_path($path); + +echo $viewsvn->paths->construct_breadcrumb($path, false); + +$blame = new SVNBlame($repos, $relpath, @$viewsvn->in['rev']); + +echo ''; + +foreach ($blame->fetch() AS $entry) +{ + echo ' + + + + + '; +} + +echo ' +
' . $entry['rev'] . '' . $entry['author'] . '' . str_replace(array(' ', "\t"), array(' ', '     '), htmlspecialchars($entry['line'])) . '
'; + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/includes/svnlib.php b/includes/svnlib.php index 4ba6cdd..dbea3b9 100644 --- a/includes/svnlib.php +++ b/includes/svnlib.php @@ -196,6 +196,87 @@ 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 + */ + var $blame = array(); + + /** + * Raw "svn blame" output + */ + var $rawoutput; + + /** + * Constructor: create blame and store data + * + * @param string Repository + * @param string Path + * @param integer Revision + */ + function SVNBlame($repos, $path, $revision) + { + global $viewsvn; + + $this->rawoutput = $viewsvn->svn->blame($repos, $path, $revision); + $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++ + ); + } + } + } +} + /** * Log management system; creates a complex list * of SVN log information diff --git a/log.php b/log.php index 3829e68..04cbabd 100644 --- a/log.php +++ b/log.php @@ -25,7 +25,7 @@ echo "\n"; foreach ($logs->fetch() AS $log) { - echo '
  • ' . $log['rev']; + echo '
  • ' . $log['rev'] . ' - Blame'; echo "\n"; echo '