Faster, github-like revision log viewer for files.
authorChuck Hagenbuch <chuck@horde.org>
Mon, 10 Jan 2011 01:49:16 +0000 (20:49 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Mon, 10 Jan 2011 02:44:35 +0000 (21:44 -0500)
This definitely gives up a bit of functionality - and I'd like to find a way to
get the arbitrary diff links back - but I think on balance it's better. Faster,
too, though there's work to do there still.

chora/browsefile.php
chora/js/revlog.js
chora/templates/log/footer.inc [deleted file]
chora/templates/log/header.inc
chora/templates/log/rev.inc [deleted file]
framework/Vcs/lib/Horde/Vcs/File/Git.php

index 195413d..87f9645 100644 (file)
@@ -20,7 +20,7 @@ if ($atdir) {
     exit;
 }
 
-$onb = Horde_Util::getFormData('onb');
+$onb = Horde_Util::getFormData('onb', $VC->getDefaultBranch());
 try {
     $fl = $VC->getFileObject($where, array('branch' => $onb));
 } catch (Horde_Vcs_Exception $e) {
@@ -47,51 +47,23 @@ if ($VC->hasFeature('branches')) {
     }
 }
 
-Horde::addScriptFile('tables.js', 'horde');
-Horde::addScriptFile('quickfinder.js', 'horde');
 Horde::addScriptFile('revlog.js', 'chora');
 require $registry->get('templates', 'horde') . '/common-header.inc';
 require CHORA_TEMPLATES . '/menu.inc';
 require CHORA_TEMPLATES . '/headerbar.inc';
 require CHORA_TEMPLATES . '/log/header.inc';
 
-$i = 0;
-$diff_img = Horde::img('diff.png');
 reset($logs);
-while (list(,$lg) = each($logs)) {
-    $rev = $lg->queryRevision();
-    $branch_info = $lg->queryBranch();
-
-    $added = $deleted = null;
-    $fileinfo = $lg->queryFiles($where);
-    if ($fileinfo && isset($fileinfo['added'])) {
-        $added = $fileinfo['added'];
-        $deleted = $fileinfo['deleted'];
-    }
-
-    // TODO: Remove in favor of getting info from queryFiles()
-    $changedlines = $lg->queryChangedLines();
-
-    $textUrl = Chora::url('co', $where, array('r' => $rev));
-    $commitDate = Chora::formatDate($lg->queryDate());
-    $readableDate = Chora::readableTime($lg->queryDate(), true);
-
-    $author = Chora::showAuthorName($lg->queryAuthor(), true);
-    $tags = Chora::getTags($lg, $where);
-
-    if ($prevRevision = $fl->queryPreviousRevision($lg->queryRevision())) {
-        $diffUrl = Chora::url('diff', $where, array('r1' => $prevRevision, 'r2' => $rev));
-    } else {
-        $diffUrl = '';
-    }
-
-    $logMessage = Chora::formatLogMessage($lg->queryLog());
-
-    require CHORA_TEMPLATES . '/log/rev.inc';
-
-    if (($i++ > 100) && !Horde_Util::getFormData('all')) {
-        break;
+$view = $injector->createInstance('Horde_View');
+$currentDay = null;
+echo '<div class="commit-list">';
+foreach ($logs as $log) {
+    $day = date('Y-m-d', $log->queryDate());
+    if ($day != $currentDay) {
+        echo '<h3>' . $day . '</h3>';
+        $currentDay = $day;
     }
+    echo $view->renderPartial('app/views/logMessage', array('object' => $log));
 }
-require CHORA_TEMPLATES . '/log/footer.inc';
+echo '</div>';
 require $registry->get('templates', 'horde') . '/common-footer.inc';
index d25ba74..4b274d0 100644 (file)
@@ -8,13 +8,16 @@ var Chora_RevLog = {
 
     highlight: function()
     {
-        $('revlog_body').select('TR').each(function(tr) {
-            if (Prototype.Browser.IE) {
-                tr.observe('mouseover', this.rowover.bindAsEventListener(this, 'over'));
-                tr.observe('mouseover', this.rowover.bindAsEventListener(this, 'out'));
-            }
-            tr.observe('click', this.toggle.bindAsEventListener(this));
-        }, this);
+        revlog_body = $('revlog_body');
+        if (revlog_body) {
+            revlog_body.select('TR').each(function(tr) {
+                if (Prototype.Browser.IE) {
+                    tr.observe('mouseover', this.rowover.bindAsEventListener(this, 'over'));
+                    tr.observe('mouseover', this.rowover.bindAsEventListener(this, 'out'));
+                }
+                tr.observe('click', this.toggle.bindAsEventListener(this));
+            }, this);
+        }
     },
 
     rowover: function(e, type)
diff --git a/chora/templates/log/footer.inc b/chora/templates/log/footer.inc
deleted file mode 100644 (file)
index c738ce4..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-</tbody>
-</table>
-
-<?php if ($fl->revisionCount() > 100 && !Horde_Util::getFormData('all')): ?>
-<div class="options">
- <span>
-  <?php printf(_("Only showing the 100 latest revisions. %sShow all revisions?</a> (may take a while)."), Horde::link(Horde_Util::addParameter(Horde::selfUrl(true), 'all', 1))) ?>
- </span>
-</div>
-<?php endif ?>
index f3883d9..ad772f0 100644 (file)
@@ -1,9 +1,5 @@
 <div class="browsefileoptions">
- <div>
-  <?php echo _("Search Revisions:") ?>
-  <input type="text" for="revlog_body" size="20" />
- </div>
-
+<!--
  <div>
 <?php if (!$browser->hasFeature('javascript')): ?>
   <form method="get" action="diff.php">
 <?php endif; ?>
    <em><?php printf(_("%1\$s shows diffs to the previous revision. If you select a revision by clicking its row, %1\$s will show the differences to the selected row."), Horde::img('diff.png', _("Show Differences"))) ?></em>
  </div>
+-->
 
 <?php if (!empty($selAllBranches)): ?>
  <div>
   <form method="get" action="<?php echo Chora::url('browsefile', Horde_Util::getFormData('f')) ?>">
    <?php echo _("Show Branch:") ?>
    <select name="onb" onchange="this.form.submit()">
-    <option value="0"<?php if (!isset($onb) || !$onb) echo ' selected="selected"' ?>><?php echo _("All Branches") ?></option>
     <?php echo $selAllBranches ?>
    </select>
    <noscript><input class="button" type="submit" value="<?php echo _("View") ?>" /></noscript>
  </div>
 <?php endif; ?>
 </div>
-
-<table class="revlog striped sortable" id="revlog" cellspacing="0">
-<thead>
- <tr class="item leftAlign">
-  <th class="nosort">&nbsp;</th>
-  <th><?php echo _("Revision") ?></th>
-  <th class="sortup"><?php echo _("Date") ?></th>
-  <th><?php echo _("Author") ?></th>
-  <th class="nosort"><?php echo _("Log Message") ?></th>
- </tr>
-</thead>
-<tbody id="revlog_body">
diff --git a/chora/templates/log/rev.inc b/chora/templates/log/rev.inc
deleted file mode 100644 (file)
index 473f6d8..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<tr id="rev<?php echo $rev ?>">
- <td>
-  <?php if ($diffUrl): ?>
-  <a href="<?php echo $diffUrl ?>" class="pdiff" title="<?php echo _("Show changes to the previous revision") ?>"><?php echo $diff_img ?></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.sdiff(this);"><?php echo $diff_img ?></a>
- </td>
- <td><a href="<?php echo $textUrl ?>" title="<?php echo htmlspecialchars($rev) ?>"><?php echo htmlspecialchars($VC->abbrev($rev)) ?></a>
-<?php $branchlist = array_diff($branch_info, array($onb)); if (!empty($branchlist)): ?>
-  <span class="branch">
-<?php foreach ($branchlist as $val): ?>
-  <?php echo Chora::url('browsefile', $where, array('onb' => $val))->link() . htmlspecialchars($val) ?></a>
-<?php endforeach; ?>
-  </span>
-<?php endif; ?>
-<?php if (!empty($changedlines)): ?>
-  <small class="difflines">(<?php printf('%s lines', htmlspecialchars($changedlines)) ?>)</small>
-<?php elseif (!is_null($added)): ?>
-  <small class="difflines">(<span class="diffadd">+<?php echo $added ?></span>, <span class="diffdel">-<?php echo $deleted ?></span> <?php echo _("lines") ?>)</small>
-<?php endif; ?>
- </td>
- <td class="ago" sortval="<?php echo (int)$lg->queryDate() ?>"><a title="<?php echo $readableDate ?>"><?php echo $commitDate ?></a></td>
- <td class="author"><?php echo $author ?></td>
- <td class="log">
-  <p class="message"><?php echo $logMessage ?></p>
-<?php if ($tags): ?>
-  <p class="tags"><?php echo _("Tags") . ': ' . implode(', ', $tags) ?></p>
-<?php endif; ?>
- </td>
-</tr>
index 72cd84a..5e3cb3e 100644 (file)
@@ -43,13 +43,13 @@ class Horde_Vcs_File_Git extends Horde_Vcs_File
     {
         $log_list = null;
 
+        if (empty($this->_branch)) { $this->_branch = $this->_rep->getDefaultBranch(); }
+
         /* First, grab the master list of revisions. If quicklog is specified,
          * we don't need this master list - we are only concerned about the
          * most recent revision for the given branch. */
         if ($this->_quicklog) {
-            $branchlist = empty($this->_branch)
-                ? array($this->_rep->getDefaultBranch())
-                : array($this->_branch);
+            $branchlist = array($this->_branch);
         } else {
             if (version_compare($this->_rep->version, '1.6.0', '>=')) {
                 $cmd = $this->_rep->getCommand() . ' rev-list --branches -- ' . escapeshellarg($this->queryModulePath()) . ' 2>&1';
@@ -85,27 +85,21 @@ class Horde_Vcs_File_Git extends Horde_Vcs_File
             $branchlist = array_keys($this->queryBranches());
         }
 
-        /* Get the list of revisions. Need to get all revisions, not just
-         * those on $this->_branch, for branch determination reasons. */
-        foreach ($branchlist as $key) {
-            $revs = array();
-            $cmd = $this->_rep->getCommand() . ' rev-list ' . ($this->_quicklog ? '-n 1' : '') . ' ' . escapeshellarg($key) . ' -- ' . escapeshellarg($this->queryModulePath()) . ' 2>&1';
-            exec($cmd, $revs);
+        $revs = array();
+        $cmd = $this->_rep->getCommand() . ' rev-list' . ($this->_quicklog ? ' -n 1' : '') . ' ' . escapeshellarg($this->_branch) . ' -- ' . escapeshellarg($this->queryModulePath()) . ' 2>&1';
+        exec($cmd, $revs);
 
-            if (!empty($revs)) {
-                if (stripos($revs[0], 'fatal') === 0) {
-                    throw new Horde_Vcs_Exception(implode(', ', $revs));
-                }
+        if (!empty($revs)) {
+            if (stripos($revs[0], 'fatal') === 0) {
+                throw new Horde_Vcs_Exception(implode(', ', $revs));
+            }
 
-                $this->_revlist[$key] = $revs;
+            $this->_revlist[$this->_branch] = $revs;
 
-                if (!empty($this->_branch) && ($this->_branch == $key)) {
-                    $log_list = $revs;
-                }
+            $log_list = $revs;
 
-                if ($this->_quicklog) {
-                    $this->_revs[] = reset($revs);
-                }
+            if ($this->_quicklog) {
+                $this->_revs[] = reset($revs);
             }
         }