- Blame now works
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Apr 2007 06:42:09 +0000 (06:42 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 9 Apr 2007 06:42:09 +0000 (06:42 +0000)
- Added FormatCode() and it's helper _FormatSpaces()

blame.php
includes/functions.php
includes/svncommon.php
includes/svnlib.php
templates/default/blame_line.tpl

index bcb1b438d540d864561f9557b8297e1f3fd2f9e4..7aab44e7c39036bdb0aa980c0bb9740d1dcaface 100644 (file)
--- 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') . '";');
 }
 
index 21a9374e917eabc4e170a333c9cbd2b06ec3f190..cea236691ddf411ef68baf4aa702c29c955c2b7c 100644 (file)
@@ -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(' ', '&nbsp;', $string);
+       }
+       
+       // convert advanced diff
+       $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('<span class="diff_add_bit">', '<span class="diff_del_bit">'), $string);
+       $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '</span>', $string);
+       
+       // nl2br
+       $string = nl2br($string);
+       
+       return $string;
+}
+
+// ###################################################################
+/**
+* Counts the spaces and replaces two or more ones
+*
+* @param       string  Spaced string
+*
+* @return      string  &nbsp;'d string
+*/
+function _FormatSpaces($thestring)
+{
+       if (strlen($thestring) >= 2)
+       {
+               $thestring = str_replace(' ', '&nbsp;', $thestring);
+       }
+       
+       return $thestring;
+}
+
 /*=====================================================================*\
 || ###################################################################
 || # $HeadURL$
index f9ffa8d113967d0ff51e7b70dd6c645eeb11b252..8a128c2d7db06e5e570287825cbe5c5e02e41caa 100644 (file)
 * @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(' ', '&nbsp;', $string);
-               }
-               
-               // convert advanced diff
-               $string = str_replace(array('{@+' . '+}', '{@-' . '-}'), array('<span class="diff_add_bit">', '<span class="diff_del_bit">'), $string);
-               $string = str_replace(array('{/@+' . '+}', '{/@-' . '-}'), '</span>', $string);
-               
-               // nl2br
-               $string = nl2br($string);
-               
-               return $string;
-       }
-       
-       // ###################################################################
-       /**
-       * Counts the spaces and replaces two or more ones
-       *
-       * @access       private
-       *
-       * @param        string  Spaced string
-       *
-       * @return       string  &nbsp;'d string
-       */
-       function format_spaces($thestring)
-       {
-               if (strlen($thestring) >= 2)
-               {
-                       $thestring = str_replace(' ', '&nbsp;', $thestring);
-               }
-               
-               return $thestring;
-       }
-       
+{      
        // ###################################################################
        /**
        * Prints the file changed list
index 0827df0a03a40e46d7081ded2f5c669bdd0de63e..f2ab77fbe4e4711f8702cf486512ea953652f518 100644 (file)
@@ -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
 *
index a2d34a11335f8ce973ebfb6223678b261aa86ca6..949617c5689788fd42ce1bb4a55c65d147b4452b 100644 (file)
@@ -1,5 +1,5 @@
 <tr>
-       <td class="lineheader" style="border-width: 0px 1px 1px 1px; width: 1%"><a href="$entry[view_link]">$entry[rev]</a></td>
-       <td class="lineheader" style="border-width: 0px 1px 1px 0px; width: 1%">$entry[author]</td>
-       <td class="code" style="border-width: 0px 1px 1px 0px">$entry[line_clean]</td>
+       <td class="lineheader" style="border-width: 0px 1px 1px 1px; width: 1%"><a href="$view">$revision</a></td>
+       <td class="lineheader" style="border-width: 0px 1px 1px 0px; width: 1%">$author</td>
+       <td class="code" style="border-width: 0px 1px 1px 0px">$line</td>
 </tr>