From 2e7460b4f526a75b19a79eac5fb8eea925acd97d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 6 Jan 2009 23:45:50 -0700 Subject: [PATCH] Move checking code to Vcs. No longer do hackish checking of object type - use supportsFeature() call of the object instead. --- chora/browse.php | 12 +++-------- chora/cvsgraph.php | 2 +- chora/history.php | 2 +- chora/lib/Chora.php | 7 +++--- chora/patchsets.php | 7 +++--- framework/Vcs/lib/Horde/Vcs.php | 43 +++++++++++++++++++++++++++++++++++++ framework/Vcs/lib/Horde/Vcs/Cvs.php | 14 ++++++++++++ framework/Vcs/lib/Horde/Vcs/Svn.php | 7 ++++++ 8 files changed, 77 insertions(+), 17 deletions(-) diff --git a/chora/browse.php b/chora/browse.php index 8e9878b66..024a414c0 100644 --- a/chora/browse.php +++ b/chora/browse.php @@ -32,15 +32,9 @@ if ($atdir) { ? $conf['options']['introTitle'] : sprintf(_("Source Directory of /%s"), $where); - $extraLink = ''; - if (is_a($VC, 'VC_cvs')) { - $extraLink = Horde::widget(Chora::url( - '', $where . '/', array('sa' => ($acts['sa'] ? 0 : 1))), - $acts['sa'] ? _("Hide Deleted Files") : _("Show Deleted Files"), - 'widget', '', '', - $acts['sa'] ? _("Hide _Deleted Files") : _("Show _Deleted Files") - ); - } + $extraLink = $VC->supportsFeature('deleted') + ? Horde::widget(Chora::url('', $where . '/', array('sa' => ($acts['sa'] ? 0 : 1))), $acts['sa'] ? _("Hide Deleted Files") : _("Show Deleted Files"), 'widget', '', '', $acts['sa'] ? _("Hide _Deleted Files") : _("Show _Deleted Files")) + : ''; $umap = array( 'age' => Horde_Vcs::SORT_AGE, diff --git a/chora/cvsgraph.php b/chora/cvsgraph.php index 87485ec15..2d6749ca8 100644 --- a/chora/cvsgraph.php +++ b/chora/cvsgraph.php @@ -15,7 +15,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; // Exit if cvsgraph isn't active or it's not supported. -if (empty($conf['paths']['cvsgraph']) || is_a($VC, 'VC_svn')) { +if (empty($conf['paths']['cvsgraph']) || !$VC->supportsFeature('branches')) { header('Location: ' . Chora::url('', $where)); exit; } diff --git a/chora/history.php b/chora/history.php index 2a58ab7c4..dd5e0b0d9 100644 --- a/chora/history.php +++ b/chora/history.php @@ -12,7 +12,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; /* Exit if it's not supported. */ -if (is_a($VC, 'VC_svn')) { +if (!$VC->supportsFeature('branches')) { header('Location: ' . Chora::url('browse', $where)); exit; } diff --git a/chora/lib/Chora.php b/chora/lib/Chora.php index c7d0e8e16..955f644ba 100644 --- a/chora/lib/Chora.php +++ b/chora/lib/Chora.php @@ -501,15 +501,16 @@ class Chora { ? '' . _("Logs") . '' : Horde::widget(Chora::url('', $where), _("Logs"), 'widget', '', '', _("_Logs")); - // Subversion supports patchsets natively. + if (!empty($GLOBALS['conf']['paths']['cvsps']) || - is_a($GLOBALS['VC'], 'VC_svn')) { + $GLOBALS['VC']->supportsFeature('patchsets')) { $views[] = $current == 'patchsets' ? '' . _("Patchsets") . '' : Horde::widget(Chora::url('patchsets', $where), _("Patchsets"), 'widget', '', '', _("_Patchsets")); } - if (!is_a($GLOBALS['VC'], 'VC_svn')) { + + if ($GLOBALS['VC']->supportsFeature('branches')) { if (empty($GLOBALS['conf']['paths']['cvsgraph'])) { $views[] = $current == 'history' ? '' . _("Branches") . '' diff --git a/chora/patchsets.php b/chora/patchsets.php index ea94f6cb1..c11a7275b 100644 --- a/chora/patchsets.php +++ b/chora/patchsets.php @@ -13,7 +13,8 @@ require_once dirname(__FILE__) . '/lib/base.php'; // Exit if cvsps isn't active or it's not a subversion repository. -if (empty($conf['paths']['cvsps']) && !is_a($VC, 'VC_svn')) { +if (empty($conf['paths']['cvsps']) && + !$GLOBALS['VC']->supportsFeature('patchsets')) { header('Location: ' . Chora::url('', $where)); exit; } @@ -46,7 +47,7 @@ foreach ($patchsets as $id => $patchset) { $commitDate = Chora::formatTime($patchset['date']); $readableDate = Chora::readableTime($patchset['date'], true); $author = Chora::showAuthorName($patchset['author'], true); - if (is_a($VC, 'VC_svn')) { + if ($VC->supportsFeature('patchsets')) { // The diff should be from the top of the source tree so as to // get all files. $topDir = substr($where, 0, strpos($where, '/', 1)); @@ -63,7 +64,7 @@ foreach ($patchsets as $id => $patchset) { $dir = dirname($where); foreach ($patchset['members'] as $member) { $file = array(); - $mywhere = is_a($VC, 'VC_svn') ? $member['file'] : $dir . '/' . $member['file']; + $mywhere = ($VC->supportsFeature('patchsets')) ? $member['file'] : $dir . '/' . $member['file']; $file['file'] = Horde::link(Chora::url('patchsets', $mywhere)) . htmlspecialchars($member['file']) . ''; if ($member['from'] == 'INITIAL') { $file['from'] = '' . _("New File") . ''; diff --git a/framework/Vcs/lib/Horde/Vcs.php b/framework/Vcs/lib/Horde/Vcs.php index 3254b6d05..e6b7ef0cd 100644 --- a/framework/Vcs/lib/Horde/Vcs.php +++ b/framework/Vcs/lib/Horde/Vcs.php @@ -64,6 +64,27 @@ class Horde_Vcs protected $_cached = array(); /** + * Does driver support deleted files? + * + * @var boolean + */ + protected $_deleted = false; + + /** + * Does driver support patchsets? + * + * @var boolean + */ + protected $_patchsets = false; + + /** + * Does driver support branches? + * + * @var boolean + */ + protected $_branches = false; + + /** * Attempts to return a concrete Horde_Vcs instance based on $driver. * * @param mixed $driver The type of concrete Horde_Vcs subclass to return. @@ -123,6 +144,28 @@ class Horde_Vcs } /** + * Does this driver support the given feature + * + * @return boolean True if driver supports the given feature. + */ + public function supportsFeature($feature) + { + switch ($feature) { + case 'branches': + return $this->_branches; + + case 'deleted': + return $this->_deleted; + + case 'patchsets': + return $this->_patchsets; + + default: + return false; + } + } + + /** * Return the source root for this repository, with no trailing / * * @return string Source root for this repository. diff --git a/framework/Vcs/lib/Horde/Vcs/Cvs.php b/framework/Vcs/lib/Horde/Vcs/Cvs.php index 22abb0193..33a829d39 100644 --- a/framework/Vcs/lib/Horde/Vcs/Cvs.php +++ b/framework/Vcs/lib/Horde/Vcs/Cvs.php @@ -16,6 +16,20 @@ require_once dirname(__FILE__) . '/rcs.php'; class Horde_Vcs_cvs extends Horde_Vcs_rcs { /** + * Does driver support deleted files? + * + * @var boolean + */ + protected $_deleted = true; + + /** + * Does driver support branches? + * + * @var boolean + */ + protected $_branches = true; + + /** * Constructor. * * @param array $params Any parameter the class expects. diff --git a/framework/Vcs/lib/Horde/Vcs/Svn.php b/framework/Vcs/lib/Horde/Vcs/Svn.php index 097c12750..be11af4af 100644 --- a/framework/Vcs/lib/Horde/Vcs/Svn.php +++ b/framework/Vcs/lib/Horde/Vcs/Svn.php @@ -30,6 +30,13 @@ class Horde_Vcs_svn extends Horde_Vcs protected $_password = ''; /** + * Does driver support patchsets? + * + * @var boolean + */ + protected $_patchsets = true; + + /** * Constructor. * * @param array $params Any parameter the class expects. -- 2.11.0