From 3c963a0e22e9f271b49a61f28f17d996245fc0fc Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 21 Jan 2009 13:51:38 -0700 Subject: [PATCH] Various fixes to Chora/Vcs code. --- chora/co.php | 2 +- chora/diff.php | 24 +++--------------------- chora/lib/Chora.php | 20 ++++++++------------ chora/templates/log/rev.inc | 2 +- framework/Vcs/lib/Horde/Vcs.php | 25 ++++++++++++++++++++++--- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/chora/co.php b/chora/co.php index cd1dca65f..8019b7fb8 100644 --- a/chora/co.php +++ b/chora/co.php @@ -92,7 +92,7 @@ $content = ''; while ($line = fgets($checkOut)) { $content .= $line; } -@fclose($checkOut); +fclose($checkOut); // Get name. $filename = $file->queryName(); diff --git a/chora/diff.php b/chora/diff.php index 8fcc55cbe..fe5fba8ff 100644 --- a/chora/diff.php +++ b/chora/diff.php @@ -20,23 +20,6 @@ $rev_ob = $VC->getRevisionObject(); $r1 = Util::getFormData('r1'); $r2 = Util::getFormData('r2'); -/* If we are in a SVN repository (or another VC system that doesn't - * always use consecutive revision numbers from change-to-change - * per-file) and we compare against an older version that does not - * exist, then we search for the newest version older than the given - * old version. */ -if (!isset($fl->logs[$r1]) && isset($fl->logs[$r2]) && $r1 < $r2) { - $rn = 0; - foreach (array_keys($fl->logs) as $r) { - if ($r > $rn && $r < $r1) { - $rn = $r; - } - } - if ($rn) { - $r1 = $rn; - } -} - /* Ensure that we have valid revision numbers. */ if (!$VC->isValidRevision($r1) || !$VC->isValidRevision($r2)) { Chora::fatal(_("Malformed Query"), '500 Internal Server Error'); @@ -74,11 +57,10 @@ $title = sprintf(_("Diff for %s between version %s and %s"), /* Format log entries. */ $log = &$fl->logs; $log_messages = array(); -$range = $VC->getRevisionRange($fl, $r1, $r2); -foreach ($range as $val) { +foreach ($VC->getRevisionRange($fl, $r1, $r2) as $val) { if (isset($log[$val])) { list($branchname, $branchrev) = Chora::getBranch($fl, $val); - $clog = &$log[$val]; + $clog = $log[$val]; $log_messages[] = array( 'rev' => $val, 'msg' => Chora::formatLogMessage($clog->queryLog()), @@ -111,7 +93,7 @@ if (substr($mime_type, 0, 6) == 'image/') { "\""'; } else { /* Retrieve the tree of changes. */ - $lns = VC_Diff::humanReadable($VC->getDiff($fl, $r1, $r2, 'unified', $num, $ws)); + $lns = $VC->getDiff($fl, $r1, $r2, 'unified', $num, $ws, true); if (!$lns) { /* Is the diff empty? */ require CHORA_TEMPLATES . '/diff/hr/nochange.inc'; diff --git a/chora/lib/Chora.php b/chora/lib/Chora.php index 1c0d3533b..47c5838c6 100644 --- a/chora/lib/Chora.php +++ b/chora/lib/Chora.php @@ -199,20 +199,16 @@ class Chora global $where, $atdir; $bar = $wherePath = ''; - $i = 0; $dirs = explode('/', $where); - $last = count($dirs) - 1; + $dir_count = count($dirs) - 1; - foreach ($dirs as $dir) { - $wherePath .= '/' . $dir; - if (!$atdir && $i++ == $last) { - $wherePath .= '/'; - } - $wherePath = str_replace('//', '/', $wherePath); + foreach ($dirs as $i => $dir) { if (!empty($dir) && ($dir != 'Attic')) { - $bar .= '/ '. Text::htmlallspaces($dir) . ' '; + $wherePath = str_replace('//', '/', $wherePath . '/' . $dir); + $bar .= '/ '. Text::htmlallspaces($dir) . ' '; } } + return $bar; } @@ -562,7 +558,7 @@ class Chora * Return a list of tags for a given log entry. * * @param Horde_Vcs_Log $lg The Horde_Vcs_Log object. - * @param string $where The filename. + * @param string $where The filename. * * @return array An array of linked tags. */ @@ -576,7 +572,7 @@ class Chora if ($lg->tags) { foreach ($lg->tags as $tag) { - $tags[] = htmlspecialchars($tag); + $tags[] = htmlspecialchars($tag); } } @@ -589,7 +585,7 @@ class Chora * @param Horde_Vcs_File $fl The Horde_Vcs_File object. * @param string $rev The filename. * - * @return array An 2-member array - branch name and branch revision. + * @return array A 2-member array - branch name and branch revision. */ static public function getBranch($fl, $rev) { diff --git a/chora/templates/log/rev.inc b/chora/templates/log/rev.inc index c6b55e973..bbab6e06e 100644 --- a/chora/templates/log/rev.inc +++ b/chora/templates/log/rev.inc @@ -3,7 +3,7 @@ "> - " onclick="Chora_RevLog.revlog_sdiff(this);"> + " onclick="Chora_RevLog.sdiff(this);"> abbrev($rev)) . ''; if ($branchName) echo ' ' . Horde::link(Chora::url('', $where, array('onb' => $branchRev))) . htmlspecialchars($branchName) . ''; if (!empty($lg->lines)) echo ' (' . sprintf('%s lines', $lg->lines) . ')'; ?> diff --git a/framework/Vcs/lib/Horde/Vcs.php b/framework/Vcs/lib/Horde/Vcs.php index b4a3055da..360910a66 100644 --- a/framework/Vcs/lib/Horde/Vcs.php +++ b/framework/Vcs/lib/Horde/Vcs.php @@ -274,13 +274,14 @@ class Horde_Vcs } public function getDiff($file, $rev1, $rev2, $type = 'unified', $num = 3, - $ws = true) + $ws = true, $human = false) { if (!isset($this->_cache['diff'])) { $class = 'Horde_Vcs_Diff_' . $this->_driver; $this->_cache['diff'] = new $class(); } - return $this->_cache['diff']->get($this, $file, $rev1, $rev2, $type, $num, $ws); + $diff = $this->_cache['diff']->get($this, $file, $rev1, $rev2, $type, $num, $ws); + return $human ? $this->_cache['diff']->humanReadable($diff) : $diff; } public function availableDiffTypes() @@ -372,7 +373,7 @@ abstract class Horde_Vcs_Checkout /** * @package Horde_Vcs */ -class Horde_Vcs_Diff +abstract class Horde_Vcs_Diff { /** * The available diff types. @@ -382,6 +383,24 @@ class Horde_Vcs_Diff protected $_diffTypes = array('column', 'context', 'ed', 'unified'); /** + * Obtain the differences between two revisions of a file. + * + * @param Horde_Vcs $rep A repository object. + * @param Horde_Vcs_File $file The desired file. + * @param string $rev1 Original revision number to compare from. + * @param string $rev2 New revision number to compare against. + * @param string $type The type of diff (e.g. 'unified'). + * @param integer $num Number of lines to be used in context and + * unified diffs. + * @param boolean $ws Show whitespace in the diff? + * + * @return string|boolean False on failure, or a string containing the + * diff on success. + */ + abstract public function get($rep, $file, $rev1, $rev2, $type = 'context', + $num = 3, $ws = true); + + /** * Obtain a tree containing information about the changes between * two revisions. * -- 2.11.0