From bfc281def48d99676f615cfe95ccd2c59a2f9eaf Mon Sep 17 00:00:00 2001
From: Robert Sesek <rsesek@bluestatic.org>
Date: Mon, 9 Apr 2007 06:28:02 +0000
Subject: [PATCH] Fixing log.php

---
 includes/svnlib.php            | 123 ---------------------------------
 log.php                        |  37 ++++------
 templates/default/log_node.tpl |   7 +-
 3 files changed, 16 insertions(+), 151 deletions(-)

diff --git a/includes/svnlib.php b/includes/svnlib.php
index b63b548..0827df0 100644
--- a/includes/svnlib.php
+++ b/includes/svnlib.php
@@ -282,129 +282,6 @@ class SVNBlame
 	}
 }
 
-/**
-* Log management system; creates a complex list of SVN log information
-*
-* @package	ViewSVN
-* @version	$Id$
-*/
-class SVNLog
-{
-	/**
-	* Array of logs
-	* @var	array
-	* @access	private
-	*/
-	var $logs = array();
-	
-	/**
-	* Raw "svn log" output
-	* @var	array
-	* @access	private
-	*/
-	var $rawoutput;
-	
-	// ###################################################################
-	/**
-	* Constructor: create log store for the given file
-	*
-	* @param	object	Controller
-	*/
-	function SVNLog(&$controller)
-	{
-		$this->rawoutput = $controller->library->command('log', null);
-		$this->process();
-	}
-	
-	// ###################################################################
-	/**
-	* Returns logs for display
-	*
-	* @access	public
-	*
-	* @return	array	Log data
-	*/
-	function fetch()
-	{
-		return $this->logs;
-	}
-	
-	// ###################################################################
-	/**
-	* Splits up the raw output into a usable log
-	*
-	* @access	private
-	*/
-	function process()
-	{
-		$lastrev = 0;
-		
-		for ($i = 1; $i <= sizeof($this->rawoutput) - 1; $i++)
-		{
-			$line = $this->rawoutput["$i"];
-			
-			if (preg_match('#^r([0-9]*) \| (.*?) \| (....-..-.. ..:..:..) ([0-9\-]*) \((.*?)\) \| ([0-9]*) lines?$#', $line, $matches))
-			{
-				if (isset($this->logs["$lastrev"]))
-				{
-					$this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
-				}
-				
-				$this->logs["$matches[1]"] = array(
-					'rev'		=> $matches[1],
-					'author'	=> $matches[2],
-					'date'		=> $matches[3],
-					'timezone'	=> $matches[4],
-					'lines'		=> $matches[6],
-					'message'	=> ''
-				);
-				
-				$lastrev = $matches[1];
-			}
-			else if (preg_match('#^\s+([ADMR])\s(.*)#', $line, $matches))
-			{
-				if (preg_match('#(.*) \(from (.*?)\)$#', $matches[2], $amatches))
-				{
-					$matches[2] = $amatches[1];
-				}
-				
-				$this->logs["$lastrev"]['files'][] = array(
-					'action'	=> $matches[1],
-					'file'		=> trim($matches[2]),
-					'from'		=> (isset($amatches[2]) ? $amatches[2] : '')
-				);
-			}
-			else
-			{
-				if (trim($line) != 'Changed paths:')
-				{
-					$this->logs["$lastrev"]['message'] .= $line . "\n";
-				}
-			}
-		}
-		
-		if (isset($this->logs["$lastrev"]))
-		{
-			$this->logs["$lastrev"]['message'] = $this->strip_last_line($this->logs["$lastrev"]['message']);
-		}
-	}
-	
-	// ###################################################################
-	/**
-	* Trims the last dash line off a message
-	*
-	* @access	private
-	*
-	* @param	string	Message with annoying-ass line
-	*
-	* @return	string	Clean string
-	*/
-	function strip_last_line($string)
-	{
-		return trim(preg_replace("#\n(.*?)\n$#", '', $string));
-	}
-}
-
 /**
 * Diff system; constructs a diff array that is ready for output
 *
diff --git a/log.php b/log.php
index 04371a4..86e0089 100644
--- a/log.php
+++ b/log.php
@@ -24,41 +24,30 @@ $fetchtemplates = array(
 	'log'
 );
 
+define('SVN', '$Id$');
+
 require_once('./global.php');
 
-$navbar = $controller->construct_breadcrumb();
+$navbar = ConstructNavbar();
 
 // ###################################################################
 
-// this is NOT supposed to allow for revision ranges
-$logs = new SVNLog($controller);
-
-$isdir = $controller->cachev->isdir();
+$logs = BSXml::Parse($lib->run('log --xml -v ' . $lib->arg($repos->fetchPath($input->in['repos']) . '/' . $input->in['path']), true));
 
 $nodes = '';
 
-foreach ($logs->fetch() AS $log)
+BSXml::UnifyNode($logs['log']['logentry']);
+
+foreach ($logs['log']['logentry'] AS $index => $log)
 {
-	$prev = $controller->cachev->fetch_prev_revision($log['rev']);
-	$prev = $prev['revision'];
+	$log['author'] = $log['author']['value'];
+	$log['date'] = FormatSvnDate($log['date']['value']);
+	$log['message_clean'] = FormatLogMessage($log['msg']['value']);
 	
-	$link['view'] = $controller->href_compound(($isdir ? 'browse.php' : 'view.php'), null, Paths::fetch_rev_str(false, $log['rev']));
-	$link['blame'] = $controller->href_compound('blame.php', null, Paths::fetch_rev_str(false, $log['rev']));
+	$link['view'] = ConstructLink('view', $input->in['repos'], $input->in['path'], $log['revision']);
+	$link['blame'] = ConstructLink('blame', $input->in['repos'], $input->in['path'], $log['revision']);
+	$link['diff'] = ConstructLink('diff', $input->in['repos'], $input->in['path'], $log['revision']);
 	
-	$show['diffhead'] = $controller->cachev->fetch_head_revision() != $log['rev'];
-	if ($show['diffhead'])
-	{
-		$link['diffhead'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, 'HEAD', $log['rev']));
-	}
-	
-	$show['diffprev'] = ($prev !== null);
-	if ($show['diffprev'])
-	{
-		$link['diffprev'] = $controller->href_compound('diff.php', null, Paths::fetch_rev_str(true, $log['rev'], $prev));
-	}
-	
-	$log['message_clean'] = SVNCommon::format_log_message($log['message']);
-
 	eval('$nodes .= "' . $template->fetch('log_node') . '";');
 }
 
diff --git a/templates/default/log_node.tpl b/templates/default/log_node.tpl
index 4a71f83..5690a94 100644
--- a/templates/default/log_node.tpl
+++ b/templates/default/log_node.tpl
@@ -1,10 +1,9 @@
 <div class="subhead" style="border-width: 0px 1px 0px 1px">
-	r$log[rev] ($log[author])
-	$log[date] $log[timezone]
+	r$log[revision] ($log[author])
+	$log[date]
 	- <a href="$link[view]">{@"View"}</a>
 	<if condition="!$isdir">- <a href="$link[blame]">{@"Blame"}</a></if>
-	<if condition="$show['diffhead']">- <a href="$link[diffhead]">{@"Diff to HEAD"}</a></if>
-	<if condition="$show['diffprev']">- <a href="$link[diffprev]">{@"Diff to PREV"}</a></if>
+	- <a href="$link[diff]">{@"Changes"}</a></if>
 </div>
 <div class="content" style="padding: 4px">
 $log[message_clean]
-- 
2.43.5