while ($line = fgets($checkOut)) {
$content .= $line;
}
-@fclose($checkOut);
+fclose($checkOut);
// Get name.
$filename = $file->queryName();
$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');
/* 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()),
"<td><img src=\"$url2\" alt=\"" . htmlspecialchars($r2) . '" /></td></tr>';
} 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';
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 .= '/ <a href="' . Chora::url('', $wherePath) . '">'. Text::htmlallspaces($dir) . '</a> ';
+ $wherePath = str_replace('//', '/', $wherePath . '/' . $dir);
+ $bar .= '/ <a href="' . Chora::url('', $wherePath . ($i == $dir_count ? '' : '/')) . '">'. Text::htmlallspaces($dir) . '</a> ';
}
}
+
return $bar;
}
* 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.
*/
if ($lg->tags) {
foreach ($lg->tags as $tag) {
- $tags[] = htmlspecialchars($tag);
+ $tags[] = htmlspecialchars($tag);
}
}
* @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)
{
<?php if ($diffUrl): ?>
<a href="<?php echo $diffUrl ?>" class="pdiff" title="<?php echo _("Show changes to the previous revision") ?>"><?php echo Horde::img('diff.png') ?></a>
<?php endif ?>
- <a href="<?php echo Chora::url('diff', $where, array('r1' => 0, 'r2' => $rev)) ?>" class="sdiff" title="<?php echo _("Show changes to the selected revision") ?>" onclick="Chora_RevLog.revlog_sdiff(this);"><?php echo Horde::img('diff.png') ?></a>
+ <a href="<?php echo Chora::url('diff', $where, array('r1' => 0, 'r2' => $rev)) ?>" class="sdiff" title="<?php echo _("Show changes to the selected revision") ?>" onclick="Chora_RevLog.sdiff(this);"><?php echo Horde::img('diff.png') ?></a>
</td>
<td><a href="<?php echo $textUrl ?>" title="<?php echo htmlspecialchars($rev) ?>"><?php echo htmlspecialchars($rev_ob->abbrev($rev)) . '</a>'; if ($branchName) echo ' <span class="branch">' . Horde::link(Chora::url('', $where, array('onb' => $branchRev))) . htmlspecialchars($branchName) . '</a></span>'; if (!empty($lg->lines)) echo ' <small>(' . sprintf('%s lines', $lg->lines) . ')</small>'; ?></td>
<td class="ago" sortval="<?php echo (int)$lg->date ?>"><a title="<?php echo $readableDate ?>"><?php echo $commitDate ?></a></td>
}
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()
/**
* @package Horde_Vcs
*/
-class Horde_Vcs_Diff
+abstract class Horde_Vcs_Diff
{
/**
* The available diff types.
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.
*