Various fixes to Chora/Vcs code.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 21 Jan 2009 20:51:38 +0000 (13:51 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 21 Jan 2009 20:51:38 +0000 (13:51 -0700)
chora/co.php
chora/diff.php
chora/lib/Chora.php
chora/templates/log/rev.inc
framework/Vcs/lib/Horde/Vcs.php

index cd1dca6..8019b7f 100644 (file)
@@ -92,7 +92,7 @@ $content = '';
 while ($line = fgets($checkOut)) {
     $content .= $line;
 }
-@fclose($checkOut);
+fclose($checkOut);
 
 // Get name.
 $filename = $file->queryName();
index 8fcc55c..fe5fba8 100644 (file)
@@ -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/') {
         "<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';
index 1c0d353..47c5838 100644 (file)
@@ -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 .= '/ <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;
     }
 
@@ -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)
     {
index c6b55e9..bbab6e0 100644 (file)
@@ -3,7 +3,7 @@
   <?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>
index b4a3055..360910a 100644 (file)
@@ -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.
      *