Blame stuff is done
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 28 Aug 2005 00:06:14 +0000 (00:06 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 28 Aug 2005 00:06:14 +0000 (00:06 +0000)
blame.php [new file with mode: 0644]
includes/svnlib.php
log.php

diff --git a/blame.php b/blame.php
new file mode 100644 (file)
index 0000000..9b66167
--- /dev/null
+++ b/blame.php
@@ -0,0 +1,44 @@
+<?php
+/*=====================================================================*\
+|| ################################################################### ||
+|| # ViewSVN [#]version[#]
+|| # --------------------------------------------------------------- # ||
+|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
+|| # This file may not be reproduced in any way without permission.  # ||
+|| # --------------------------------------------------------------- # ||
+|| # User License Agreement at http://www.iris-studios.com/license/  # ||
+|| ################################################################### ||
+\*=====================================================================*/
+
+require_once('./global.php');
+
+$path = $viewsvn->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 '<table cellspacing="1" cellpadding="1" style="background-color: #EFEFEF" width="100%">';
+
+foreach ($blame->fetch() AS $entry)
+{
+       echo '
+       <tr style="background-color: white">
+               <td>' . $entry['rev'] . '</td>
+               <td>' . $entry['author'] . '</td>
+               <td>' . str_replace(array(' ', "\t"), array('&nbsp;', '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'), htmlspecialchars($entry['line'])) . '</td>
+       </tr>';
+}
+
+echo '
+</table>';
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file
index 4ba6cdd813ed5c9f943cefeb48684d93ecb4927a..dbea3b9ccd160d0df85f7d50b1f99f60b303b347 100644 (file)
@@ -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 3829e68a513d43b41351fc1362a17ba2db67d228..04cbabd51aaef68c3c33a057c5f9d852fe272a9f 100644 (file)
--- a/log.php
+++ b/log.php
@@ -25,7 +25,7 @@ echo "\n";
 
 foreach ($logs->fetch() AS $log)
 {
-       echo '<li>' . $log['rev'];
+       echo '<li>' . $log['rev'] . ' - <a href="/viewsvn/' . $viewsvn->paths->out('blame.php?rev=' . $log['rev'], $path) . '">Blame</a>';
        echo "\n";
        echo '<ul>';
        echo "\n";