Move checking code to Vcs.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 7 Jan 2009 06:45:50 +0000 (23:45 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 8 Jan 2009 00:51:34 +0000 (17:51 -0700)
No longer do hackish checking of object type - use supportsFeature()
call of the object instead.

chora/browse.php
chora/cvsgraph.php
chora/history.php
chora/lib/Chora.php
chora/patchsets.php
framework/Vcs/lib/Horde/Vcs.php
framework/Vcs/lib/Horde/Vcs/Cvs.php
framework/Vcs/lib/Horde/Vcs/Svn.php

index 8e9878b..024a414 100644 (file)
@@ -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,
index 87485ec..2d6749c 100644 (file)
@@ -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;
 }
index 2a58ab7..dd5e0b0 100644 (file)
@@ -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;
 }
index c7d0e8e..955f644 100644 (file)
@@ -501,15 +501,16 @@ class Chora {
             ? '<em class="widget">' . _("Logs") . '</em>'
             : 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'
                 ? '<em class="widget">' . _("Patchsets") . '</em>'
                 : 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'
                     ? '<em class="widget">' . _("Branches") . '</em>'
index ea94f6c..c11a727 100644 (file)
@@ -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']) . '</a>';
         if ($member['from'] == 'INITIAL') {
             $file['from'] = '<ins>' . _("New File") . '</ins>';
index 3254b6d..e6b7ef0 100644 (file)
@@ -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.
index 22abb01..33a829d 100644 (file)
@@ -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.
index 097c127..be11af4 100644 (file)
@@ -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.