From 7a222bdef86269c2ce47034fbc98494d26d70717 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 24 Aug 2009 15:43:29 -0600 Subject: [PATCH] Patchset page supports viewing of a specific patchset revision, independent of filename, for those backends that support such a thing --- chora/patchsets.php | 24 +++++++++++++++--------- chora/templates/patchsets/header.inc | 9 +++++---- framework/Vcs/lib/Horde/Vcs.php | 20 ++++++++++++++------ framework/Vcs/lib/Horde/Vcs/Cvs.php | 6 ++++-- framework/Vcs/lib/Horde/Vcs/Git.php | 20 +++++++++++++------- framework/Vcs/lib/Horde/Vcs/Svn.php | 5 +++-- 6 files changed, 54 insertions(+), 30 deletions(-) diff --git a/chora/patchsets.php b/chora/patchsets.php index 0ac012b64..277e1a94a 100644 --- a/chora/patchsets.php +++ b/chora/patchsets.php @@ -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") . ''; -} 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'; } diff --git a/chora/templates/patchsets/header.inc b/chora/templates/patchsets/header.inc index 540dbeb7b..17c3c5aa1 100644 --- a/chora/templates/patchsets/header.inc +++ b/chora/templates/patchsets/header.inc @@ -1,10 +1,11 @@ -
- - +

+
+
+ -
+ diff --git a/framework/Vcs/lib/Horde/Vcs.php b/framework/Vcs/lib/Horde/Vcs.php index a47663bf7..fdabf14d6 100644 --- a/framework/Vcs/lib/Horde/Vcs.php +++ b/framework/Vcs/lib/Horde/Vcs.php @@ -552,27 +552,35 @@ class Horde_Vcs /** * TODO + * + * @param array $opts Options: + *
+     * 'file' - (string) TODO
+     * 'range' - (array) TODO
+     * 
+ * + * @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)); diff --git a/framework/Vcs/lib/Horde/Vcs/Cvs.php b/framework/Vcs/lib/Horde/Vcs/Cvs.php index cfdb295c1..d961546bd 100644 --- a/framework/Vcs/lib/Horde/Vcs/Cvs.php +++ b/framework/Vcs/lib/Horde/Vcs/Cvs.php @@ -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. *
+     * 'file' - (string) The filename to process.
+     *          REQUIRED for this driver.
      * 'range' - (array) The patchsets to process.
      *           DEFAULT: None (all patchsets are processed).
      * 
* * @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)) { diff --git a/framework/Vcs/lib/Horde/Vcs/Git.php b/framework/Vcs/lib/Horde/Vcs/Git.php index cad8a43d6..4c8332c63 100644 --- a/framework/Vcs/lib/Horde/Vcs/Git.php +++ b/framework/Vcs/lib/Horde/Vcs/Git.php @@ -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. *
+     * 'file' - (string) The filename to produce patchsets for.
      * 'range' - (array) The patchsets to process.
      *           DEFAULT: None (all patchsets are processed).
      * 
*/ - 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); } } diff --git a/framework/Vcs/lib/Horde/Vcs/Svn.php b/framework/Vcs/lib/Horde/Vcs/Svn.php index d85545898..d1f00e83e 100644 --- a/framework/Vcs/lib/Horde/Vcs/Svn.php +++ b/framework/Vcs/lib/Horde/Vcs/Svn.php @@ -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( -- 2.11.0