From 64e84582037c3e24da5d8d3cb426dc01582b23e6 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 2 Feb 2009 23:13:04 -0700 Subject: [PATCH] Patchset page alows viewing a single commit. --- chora/docs/CHANGES | 1 + chora/patchsets.php | 16 ++++++++++++++-- chora/templates/patchsets/header.inc | 4 ++++ framework/Vcs/lib/Horde/Vcs.php | 14 ++++++++++---- framework/Vcs/lib/Horde/Vcs/Cvs.php | 13 +++++++++++-- framework/Vcs/lib/Horde/Vcs/Git.php | 19 +++++++++++++++++-- 6 files changed, 57 insertions(+), 10 deletions(-) diff --git a/chora/docs/CHANGES b/chora/docs/CHANGES index fe37b9af0..562d26420 100644 --- a/chora/docs/CHANGES +++ b/chora/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[mms] Patchset page supports viewing a single patchset. [mms] Add configuration option to disable caching. [mms] Move log entries in annotate screen to an AJAX request. [mms] Add support for git repositories. diff --git a/chora/patchsets.php b/chora/patchsets.php index 0bc40c77d..d8454f3eb 100644 --- a/chora/patchsets.php +++ b/chora/patchsets.php @@ -25,8 +25,13 @@ if (!$VC->isFile($fullname)) { Chora::fatal(sprintf(_("%s: no such file or directory"), $where), '404 Not Found'); } +$ps_opts = array(); +if ($ps_id = Util::getFormData('ps')) { + $ps_opts['range'] = array($ps_id); +} + try { - $ps = $VC->getPatchsetObject($where); + $ps = $VC->getPatchsetObject($where, $ps_opts); $patchsets = $ps->getPatchsets(); } catch (Horde_Vcs_Exception $e) { Chora::fatal($e); @@ -37,7 +42,14 @@ $extraLink = Chora::getFileViews($where, 'patchsets'); Horde::addScriptFile('prototype.js', 'horde', true); Horde::addScriptFile('tables.js', 'horde', true); -Horde::addScriptFile('QuickFinder.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'; diff --git a/chora/templates/patchsets/header.inc b/chora/templates/patchsets/header.inc index a040d0a67..e9a8c780e 100644 --- a/chora/templates/patchsets/header.inc +++ b/chora/templates/patchsets/header.inc @@ -1,8 +1,12 @@
+ + + +
diff --git a/framework/Vcs/lib/Horde/Vcs.php b/framework/Vcs/lib/Horde/Vcs.php index c3d770564..829d80896 100644 --- a/framework/Vcs/lib/Horde/Vcs.php +++ b/framework/Vcs/lib/Horde/Vcs.php @@ -536,11 +536,12 @@ class Horde_Vcs /** * TODO */ - public function getPatchsetObject($filename) + public function getPatchsetObject($filename, $opts = array()) { $class = 'Horde_Vcs_Patchset_' . $this->_driver; - $cacheId = implode('|', array($class, $this->sourceroot(), $filename, $this->_cacheVersion)); + ksort($opts); + $cacheId = implode('|', array($class, $this->sourceroot(), $filename, serialize($opts), $this->_cacheVersion)); if (!empty($this->_cache)) { // TODO: Can't use filemtime() - Git bare repos contain no files @@ -550,7 +551,7 @@ class Horde_Vcs } } - $ob = new $class($this, $filename); + $ob = new $class($this, $filename, $opts); if (!empty($this->_cache)) { $this->_cache->set($cacheId, serialize($ob)); @@ -1175,8 +1176,13 @@ abstract class Horde_Vcs_Patchset * * @param Horde_Vcs $rep A Horde_Vcs repository object. * @param string $file The filename to create patchsets for. + * @param array $opts Additional options: + *
+     * 'range' - (array) The patchsets to process.
+     *           DEFAULT: None (all patchsets are processed).
+     * 
*/ - abstract public function __construct($rep, $file); + abstract public function __construct($rep, $file, $opts = array()); /** * TODO diff --git a/framework/Vcs/lib/Horde/Vcs/Cvs.php b/framework/Vcs/lib/Horde/Vcs/Cvs.php index 43c4e8780..8a824dc6c 100644 --- a/framework/Vcs/lib/Horde/Vcs/Cvs.php +++ b/framework/Vcs/lib/Horde/Vcs/Cvs.php @@ -663,10 +663,15 @@ class Horde_Vcs_Patchset_Cvs extends Horde_Vcs_Patchset * * @param Horde_Vcs $rep A Horde_Vcs repository object. * @param string $file The filename to create a patchset for. + * @param array $opts Additional options. + *
+     * 'range' - (array) The patchsets to process.
+     *           DEFAULT: None (all patchsets are processed).
+     * 
* * @throws Horde_Vcs_Exception */ - public function __construct($rep, $file) + public function __construct($rep, $file, $opts = array()) { $file = $rep->sourceroot() . '/' . $file; @@ -681,8 +686,12 @@ class Horde_Vcs_Patchset_Cvs extends Horde_Vcs_Patchset 'HOME=' . escapeshellarg($cvsps_home) . ' ' : ''; + $rangecmd = empty($opts['range']) + ? '' + : ' -s ' . escapeshellarg(implode(',', $opts['range'])); + $ret_array = array(); - $cmd = $HOME . escapeshellcmd($rep->getPath('cvsps')) . ' -u --cvs-direct --root ' . escapeshellarg($rep->sourceroot()) . ' -f ' . escapeshellarg(basename($file)) . ' ' . escapeshellarg(dirname($file)); + $cmd = $HOME . escapeshellcmd($rep->getPath('cvsps')) . $rangecmd . ' -u --cvs-direct --root ' . escapeshellarg($rep->sourceroot()) . ' -f ' . escapeshellarg(basename($file)) . ' ' . escapeshellarg(dirname($file)); exec($cmd, $ret_array, $retval); if ($retval) { throw new Horde_Vcs_Exception('Failed to spawn cvsps to retrieve patchset information.'); diff --git a/framework/Vcs/lib/Horde/Vcs/Git.php b/framework/Vcs/lib/Horde/Vcs/Git.php index d91814946..f8742a592 100644 --- a/framework/Vcs/lib/Horde/Vcs/Git.php +++ b/framework/Vcs/lib/Horde/Vcs/Git.php @@ -593,12 +593,27 @@ class Horde_Vcs_Patchset_Git extends Horde_Vcs_Patchset * * @param Horde_Vcs $rep A Horde_Vcs repository object. * @param string $file The filename to create patchsets for. + * @param array $opts Additional options. + *
+     * 'range' - (array) The patchsets to process.
+     *           DEFAULT: None (all patchsets are processed).
+     * 
*/ - public function __construct($rep, $file) + public function __construct($rep, $file, $opts = array()) { $fileOb = $rep->getFileObject($file); + $revs = array(); + + if (empty($opts['range'])) { + $revs = $fileOb->queryLogs(); + } else { + foreach ($opts['range'] as $val) { + $revs[$val] = $fileOb->queryLogs($val); + } + } - foreach ($fileOb->queryLogs() as $rev => $log) { + reset($revs); + while(list($rev, $log) = each($revs)) { $this->_patchsets[$rev] = array( 'date' => $log->queryDate(), 'author' => $log->queryAuthor(), -- 2.11.0