Patchset page supports viewing of a specific patchset revision, independent of filena...
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 24 Aug 2009 21:43:29 +0000 (15:43 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 24 Aug 2009 21:43:29 +0000 (15:43 -0600)
chora/patchsets.php
chora/templates/patchsets/header.inc
framework/Vcs/lib/Horde/Vcs.php
framework/Vcs/lib/Horde/Vcs/Cvs.php
framework/Vcs/lib/Horde/Vcs/Git.php
framework/Vcs/lib/Horde/Vcs/Svn.php

index 0ac012b..277e1a9 100644 (file)
@@ -24,13 +24,18 @@ if (!$GLOBALS['VC']->hasFeature('patchsets')) {
 $ps_opts = array();
 if ($ps_id = Horde_Util::getFormData('ps')) {
     $ps_opts['range'] = array($ps_id);
-    $title = sprintf(_("Patchset (%s) for %s"), $ps_id, $where);
-} else {
-    $title = sprintf(_("Patchsets for %s"), $where);
+    $title = sprintf(_("Patchset %s"), $ps_id);
+}
+
+if ($where) {
+    $ps_opts['file'] = $where;
+    if (!isset($title)) {
+        $title = sprintf(_("Patchsets for %s"), $where);
+    }
 }
 
 try {
-    $ps = $VC->getPatchsetObject($where, $ps_opts);
+    $ps = $VC->getPatchsetObject($ps_opts);
     $patchsets = $ps->getPatchsets();
 } catch (Horde_Vcs_Exception $e) {
     Chora::fatal($e);
@@ -46,17 +51,18 @@ Horde::addScriptFile('tables.js', 'horde', true);
 
 // JS search not needed if showing a single patchset
 if ($ps_id) {
-    $full_ps_link = Horde::link(Chora::url('patchsets', $where)) . _("View All Patchsets for File") . '</a>';
-} else {
     Horde::addScriptFile('QuickFinder.js', 'horde', true);
 }
 
 require CHORA_TEMPLATES . '/common-header.inc';
 require CHORA_TEMPLATES . '/menu.inc';
-require CHORA_TEMPLATES . '/headerbar.inc';
-require CHORA_TEMPLATES . '/patchsets/header.inc';
 
-if (!$ps_id) {
+
+if ($ps_id) {
+    require CHORA_TEMPLATES . '/patchsets/header.inc';
+} else {
+    require CHORA_TEMPLATES . '/headerbar.inc';
+    require CHORA_TEMPLATES . '/patchsets/header.inc';
     require CHORA_TEMPLATES . '/patchsets/header_table.inc';
 }
 
index 540dbeb..17c3c5a 100644 (file)
@@ -1,10 +1,11 @@
-<div class="options">
- <span>
 <?php if ($ps_id): ?>
-  <?php echo $full_ps_link ?>
+<h1 class="header"><?php echo htmlspecialchars($title) ?></h1>
+<br />
 <?php else: ?>
+<div class="options">
+ <span>
   <?php echo _("Search Patchsets:") ?>
   <input type="text" for="patchsets_body" size="20" />
-<?php endif; ?>
  </span>
 </div>
+<?php endif; ?>
index a47663b..fdabf14 100644 (file)
@@ -552,27 +552,35 @@ class Horde_Vcs
 
     /**
      * TODO
+     *
+     * @param array $opts  Options:
+     * <pre>
+     * 'file' - (string) TODO
+     * 'range' - (array) TODO
+     * </pre>
+     *
+     * @return Horde_Vcs_Patchset  Patchset object.
      */
-    public function getPatchsetObject($filename, $opts = array())
+    public function getPatchsetObject($opts = array())
     {
         $class = 'Horde_Vcs_Patchset_' . $this->_driver;
 
         ksort($opts);
-        $cacheId = implode('|', array($class, $this->sourceroot(), $filename, serialize($opts), $this->_cacheVersion));
+        $cacheId = implode('|', array($class, $this->sourceroot(), serialize($opts), $this->_cacheVersion));
 
         if (!empty($this->_cache)) {
-            // TODO: Can't use filemtime() - Git bare repos contain no files
-            if (file_exists($filename)) {
-                $ctime = time() - filemtime($filename);
+            if (isset($opts['file']) && file_exists($opts['file'])) {
+                $ctime = time() - filemtime($opts['file']);
             } else {
                 $ctime = 60;
             }
+
             if ($this->_cache->exists($cacheId, $ctime)) {
                 return unserialize($this->_cache->get($cacheId, $ctime));
             }
         }
 
-        $ob = new $class($this, $filename, $opts);
+        $ob = new $class($this, $opts);
 
         if (!empty($this->_cache)) {
             $this->_cache->set($cacheId, serialize($ob));
index cfdb295..d961546 100644 (file)
@@ -694,15 +694,17 @@ class Horde_Vcs_Patchset_Cvs extends Horde_Vcs_Patchset
      * @param string $file    The filename to create a patchset for.
      * @param array $opts     Additional options.
      * <pre>
+     * 'file' - (string) The filename to process.
+     *          REQUIRED for this driver.
      * 'range' - (array) The patchsets to process.
      *           DEFAULT: None (all patchsets are processed).
      * </pre>
      *
      * @throws Horde_Vcs_Exception
      */
-    public function __construct($rep, $file, $opts = array())
+    public function __construct($rep, $opts = array())
     {
-        $file = $rep->sourceroot() . '/' . $file;
+        $file = $rep->sourceroot() . '/' . $opts['file'];
 
         /* Check that we are actually in the filesystem. */
         if (!$rep->isFile($file)) {
index cad8a43..4c8332c 100644 (file)
@@ -775,23 +775,29 @@ class Horde_Vcs_Patchset_Git extends Horde_Vcs_Patchset
      * Constructor
      *
      * @param Horde_Vcs $rep  A Horde_Vcs repository object.
-     * @param string $file    The filename to create patchsets for.
      * @param array $opts     Additional options.
      * <pre>
+     * 'file' - (string) The filename to produce patchsets for.
      * 'range' - (array) The patchsets to process.
      *           DEFAULT: None (all patchsets are processed).
      * </pre>
      */
-    public function __construct($rep, $file, $opts = array())
+    public function __construct($rep, $opts = array())
     {
-        $fileOb = $rep->getFileObject($file);
         $revs = array();
 
-        if (empty($opts['range'])) {
-            $revs = $fileOb->queryLogs();
-        } else {
+        if (isset($opts['file'])) {
+            $ob = $rep->getFileObject($file);
+            $revs = $ob->queryLogs();
+        } elseif (!empty($opts['range'])) {
             foreach ($opts['range'] as $val) {
-                $revs[$val] = $fileOb->queryLogs($val);
+                /* Grab a filename in the patchset to get log info. */
+                $cmd = $rep->getCommand() . ' diff-tree --name-only -r ' . escapeshellarg($val);
+                exec($cmd, $output);
+
+                /* The first line is the SHA1 hash. */
+                $ob = $rep->getFileObject($output[1]);
+                $revs[$val] = $ob->queryLogs($val);
             }
         }
 
index d855458..d1f00e8 100644 (file)
@@ -414,9 +414,10 @@ class Horde_Vcs_Patchset_Svn extends Horde_Vcs_Patchset
      * @param Horde_Vcs $rep  A Horde_Vcs repository object.
      * @param string $file    The filename to create patchsets for.
      */
-    public function __construct($rep, $file)
+    public function __construct($rep, $opts = array())
     {
-        $fileOb = $rep->getFileObject($file);
+        // TODO: Allow access via 'range'
+        $fileOb = $rep->getFileObject($opts['file']);
 
         foreach ($fileOb->logs as $rev => $log) {
             $this->_patchsets[$rev] = array(