Remove Horde_Vcs_[Annotate|Checkout|Revision].
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Jan 2009 18:49:29 +0000 (11:49 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Jan 2009 19:32:12 +0000 (12:32 -0700)
All these functions are better off in Horde_Vcs.

14 files changed:
chora/annotate.php
chora/browse.php
chora/co.php
chora/diff.php
chora/history.php
chora/templates/annotate/line.inc
chora/templates/diff/hr/header.inc
chora/templates/directory/file.inc
chora/templates/log/rev.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/Rcs.php
framework/Vcs/lib/Horde/Vcs/Svn.php

index ccf81e9..6c254b7 100644 (file)
@@ -17,7 +17,6 @@ try {
 } catch (Horde_Vcs_Exception $e) {
     Chora::fatal($e);
 }
-$rev_ob = $VC->getRevisionObject();
 
 /* Retrieve the desired revision from the GET variable. */
 $rev = Util::getFormData('rev');
@@ -36,9 +35,8 @@ case 'log':
     exit;
 }
 
-$ann = $VC->getAnnotateObject($fl);
 try {
-    $lines = $ann->doAnnotate($rev);
+    $lines = $VC->annotate($fl, $rev);
 } catch (Horde_Vcs_Exception $e) {
     Chora::fatal($e);
 }
index 1597d52..9f5abf6 100644 (file)
@@ -16,8 +16,6 @@ if (!$atdir && !$VC->isFile($fullname)) {
     Chora::fatal(sprintf(_("$fullname: no such file or directory"), $where), '404 Not Found');
 }
 
-$rev_ob = $VC->getRevisionObject();
-
 if ($atdir) {
     try {
         $dir = $VC->queryDir($where);
index 8e3fae1..4b97a73 100644 (file)
@@ -46,7 +46,7 @@ if (!$VC->isValidRevision($r)) {
 
 /* Retrieve the actual checkout. */
 try {
-    $checkOut = $VC->getCheckout($file, $r);
+    $checkOut = $VC->checkout($file, $r);
 } catch (Horde_Vcs_Exception $e) {
     Chora::fatal($e);
 }
index 354e914..4f29a6b 100644 (file)
@@ -17,7 +17,6 @@ try {
 } catch (Horde_Vcs_Exception $e) {
     Chora::fatal($e);
 }
-$rev_ob = $VC->getRevisionObject();
 
 /* Initialise the form variables correctly. */
 $r1 = Util::getFormData('r1');
@@ -52,8 +51,8 @@ if ($type != 'colored') {
 }
 
 /* Human-Readable diff. */
-$abbrev_r1 = $rev_ob->abbrev($r1);
-$abbrev_r2 = $rev_ob->abbrev($r2);
+$abbrev_r1 = $VC->abbrev($r1);
+$abbrev_r2 = $VC->abbrev($r2);
 $title = sprintf(_("Diff for %s between version %s and %s"),
                  Text::htmlallspaces($where), $abbrev_r1, $abbrev_r2);
 
index 2f69f74..8e382d6 100644 (file)
@@ -23,7 +23,6 @@ try {
 } catch (Horde_Vcs_Exception $e) {
     Chora::fatal($e);
 }
-$rev_ob = $VC->getRevisionObject();
 
 $colset = array('#ccdeff', '#ecf', '#fec', '#efc', '#cfd', '#dcdba0');
 $branch_colors = $colStack = array();
@@ -42,9 +41,9 @@ foreach ($branches as $brrev => $brcont) {
  * Calling this function on every revision of the trunk is enough to
  * render out the whole tree.
  */
-function _populateGrid($row, $col, $rev_ob)
+function _populateGrid($row, $col)
 {
-    global $grid, $branches;
+    global $branches, $grid, $VC;
 
     /* Figure out the starting revision this function uses. */
     $rev = $grid[$row][$col];
@@ -59,7 +58,7 @@ function _populateGrid($row, $col, $rev_ob)
         $brrev = $brkeys[$a];
         $brcont = $branches[$brrev];
         /* Check to see if current point matches a branch point. */
-        if (!strcmp($rev, $rev_ob->strip($brrev, 1))) {
+        if (!strcmp($rev, $VC->strip($brrev, 1))) {
             /* If it does, figure out how many rows we have to add. */
             $numRows = sizeof($brcont);
             /* Check rows in columns to the right, until one is
@@ -96,7 +95,7 @@ function _populateGrid($row, $col, $rev_ob)
             /* For each value just set, check for sub-branches, - but
              * in reverse (VERY IMPORTANT!). */
             for ($i = $numRows - 1; $i >= 0 ; --$i) {
-                _populateGrid(1 + $i + $row, $insCol, $rev_ob);
+                _populateGrid(1 + $i + $row, $insCol);
             }
         }
     }
@@ -108,7 +107,7 @@ function _populateGrid($row, $col, $rev_ob)
  * populating the grid with branch revisions. */
 for ($row = sizeof($trunk) - 1; $row >= 0; $row--) {
     $grid[$row][0] = $trunk[$row];
-    _populateGrid($row, 0, $rev_ob);
+    _populateGrid($row, 0);
 }
 
 /* Sort the grid array into row order, and determine the maximum
@@ -145,7 +144,7 @@ foreach ($grid as $row) {
         /* Otherwise, this cell has content; determine what it is. */
         $rev = $row[$i];
 
-        if ($VC->isValidRevision($rev) && ($rev_ob->sizeof($rev) % 2)) {
+        if ($VC->isValidRevision($rev) && ($VC->sizeof($rev) % 2)) {
             /* This is a branch point, so put the info out. */
             $bg = isset($branch_colors[$rev]) ? $branch_colors[$rev] : '#e9e9e9';
             $symname = $fl->branches[$rev];
@@ -154,13 +153,13 @@ foreach ($grid as $row) {
         } elseif (preg_match('|^:|', $rev)) {
             /* This is a continuation cell, so render it with the
              * branch colour. */
-            $bgbr = $rev_ob->strip(preg_replace('|^\:|', '', $rev), 1);
+            $bgbr = $VC->strip(preg_replace('|^\:|', '', $rev), 1);
             $bg = isset($branch_colors[$bgbr]) ? $branch_colors[$bgbr] : '#e9e9e9';
             require CHORA_TEMPLATES . '/history/blank.inc';
 
         } elseif ($VC->isValidRevision($rev)) {
             /* This cell contains a revision, so render it. */
-            $bgbr = $rev_ob->strip($rev, 1);
+            $bgbr = $VC->strip($rev, 1);
             $bg = isset($branch_colors[$bgbr]) ? $branch_colors[$bgbr] : '#e9e9e9';
             $log = $fl->logs[$rev];
             $author = Chora::showAuthorName($log->queryAuthor());
index a7824ae..3e3dbbb 100644 (file)
@@ -6,7 +6,7 @@
     <?php echo $author ?>
   </td>
   <td class="rev">
-    <a rev="<?php echo htmlspecialchars($rev) ?>" href="<?php echo Chora::url('co', $where, array('r' => $rev)) ?>" title="<?php echo htmlspecialchars($rev) ?>"><?php echo htmlspecialchars($rev_ob->abbrev($rev)) ?></a>
+    <a rev="<?php echo htmlspecialchars($rev) ?>" href="<?php echo Chora::url('co', $where, array('r' => $rev)) ?>" title="<?php echo htmlspecialchars($rev) ?>"><?php echo htmlspecialchars($VC->abbrev($rev)) ?></a>
 <?php if ($prev): ?>
     <a href="<?php echo Chora::url('diff', $where, array('r1' => $prev, 'r2' => $rev)) ?>" title="<?php echo sprintf(_("Diff to %s"), htmlspecialchars($prev)) ?>"><?php echo Horde::img('diff.png') ?></a>
     <span class="logdisplay"><?php echo Horde::img('log.png') ?></span>
@@ -14,7 +14,7 @@
   </td>
   <td class="rev">
 <?php if ($prev): ?>
-    <a rev="<?php echo htmlspecialchars($prev) ?>" href="<?php echo Chora::url('annotate', $where, array('rev' => $prev)) . '#l' . $lineno ?>" title="<?php echo htmlspecialchars($prev) ?>"><?php echo htmlspecialchars($rev_ob->abbrev($prev)) ?></a>
+    <a rev="<?php echo htmlspecialchars($prev) ?>" href="<?php echo Chora::url('annotate', $where, array('rev' => $prev)) . '#l' . $lineno ?>" title="<?php echo htmlspecialchars($prev) ?>"><?php echo htmlspecialchars($VC->abbrev($prev)) ?></a>
 <?php endif; ?>
   </td>
   <td class="item<?php echo $style ?>">
index 365c404..70240b7 100644 (file)
@@ -51,7 +51,7 @@
 <?php endif; ?>
    <?php if (!empty($val['tags'])): ?><li class="tags"><?php echo _("Tags:") ?> <?php echo implode(', ', $val['tags']) ?></li><?php endif; ?>
   </ul>
-  <a href="<?php echo Chora::url('co', $where, array('r' => $val['rev'])) ?>" title="<?php echo htmlspecialchars($val['rev']) ?>"><?php echo htmlspecialchars($rev_ob->abbrev($val['rev'])) ?></a>: <?php echo $val['msg'] ?>
+  <a href="<?php echo Chora::url('co', $where, array('r' => $val['rev'])) ?>" title="<?php echo htmlspecialchars($val['rev']) ?>"><?php echo htmlspecialchars($VC->abbrev($val['rev'])) ?></a>: <?php echo $val['msg'] ?>
   <div class="diffclear"></div>
  </div>
 <?php endforeach; ?>
index 67452b9..0169bf7 100644 (file)
@@ -20,7 +20,7 @@
 <?php else: ?>
     <a href="<?php echo $url ?>" title="<?php echo htmlspecialchars($head) ?>">
 <?php endif; ?>
-<?php echo htmlspecialchars($rev_ob->abbrev($head)) ?></a></strong>
+<?php echo htmlspecialchars($VC->abbrev($head)) ?></a></strong>
   </td>
 <?php else: ?>
   <td>
@@ -31,7 +31,7 @@
 <?php endif; ?>
    <?php echo $name ?>
   </td>
-  <td><strong><?php echo htmlspecialchars($rev_ob->abbrev($head)) ?></strong></td>
+  <td><strong><?php echo htmlspecialchars($VC->abbrev($head)) ?></strong></td>
 <?php endif; ?>
   <td><?php echo $author ?></td>
   <td sortval="<?php echo (int)$date ?>">
index 6bf793e..24a6efb 100644 (file)
@@ -5,7 +5,7 @@
   <?php endif ?>
   <a href="<?php echo Chora::url('diff', $where, array('r1' => 0, 'r2' => $rev)) ?>" class="sdiff" title="<?php echo _("Show changes to the selected revision") ?>" onclick="Chora_RevLog.sdiff(this);"><?php echo Horde::img('diff.png') ?></a>
  </td>
- <td><a href="<?php echo $textUrl ?>" title="<?php echo htmlspecialchars($rev) ?>"><?php echo htmlspecialchars($rev_ob->abbrev($rev)) ?></a>
+ <td><a href="<?php echo $textUrl ?>" title="<?php echo htmlspecialchars($rev) ?>"><?php echo htmlspecialchars($VC->abbrev($rev)) ?></a>
 <?php foreach (array_diff($branch_info, array($onb)) as $val): ?>
   <span class="branch"><?php echo Horde::link(Chora::url('', $where, array('onb' => $val))) . htmlspecialchars($val) ?></a></span>
 <?php endforeach; ?>
index fdf3747..1fbb81f 100644 (file)
@@ -94,8 +94,8 @@ class Horde_Vcs
      * @param array $params  A hash containing any additional configuration
      *                       or  parameters a subclass might need.
      *
-     * @return Horde_Vcs  The newly created concrete instance, or PEAR_Error on
-     *                   failure.
+     * @return Horde_Vcs  The newly created concrete instance.
+     * @throws Horde_Vcs_Exception
      */
     static public function factory($driver, $params = array())
     {
@@ -271,15 +271,6 @@ class Horde_Vcs
         return new $class($this, $where);
     }
 
-    public function getCheckout($file, $rev)
-    {
-        if (!isset($this->_cache['co'])) {
-            $class = 'Horde_Vcs_Checkout_' . $this->_driver;
-            $this->_cache['co'] = new $class();
-        }
-        return $this->_cache['co']->get($this, $file->queryFullPath(), $rev);
-    }
-
     public function getDiff($file, $rev1, $rev2, $type = 'unified', $num = 3,
                             $ws = true, $human = false)
     {
@@ -301,6 +292,21 @@ class Horde_Vcs
     }
 
     /**
+     * Function which returns a file pointing to the head of the requested
+     * revision of an SVN file.
+     *
+     * @param string $fullname  Fully qualified pathname of the desired file
+     *                          to checkout
+     * @param string $rev       Revision number to check out
+     *
+     * @return resource  A stream pointer to the head of the checkout.
+     */
+    public function checkout($fullname, $rev)
+    {
+        return null;
+    }
+
+    /**
      * $opts:
      * 'cache' - (boolean)
      * 'quicklog' - (boolean)
@@ -333,12 +339,6 @@ class Horde_Vcs
         return $fileOb;
     }
 
-    public function getAnnotateObject($filename)
-    {
-        $class = 'Horde_Vcs_Annotate_' . $this->_driver;
-        return new $class($this, $filename);
-    }
-
     public function getPatchsetObject($filename, $cache = null)
     {
         $class = 'Horde_Vcs_Patchset_' . $this->_driver;
@@ -346,61 +346,82 @@ class Horde_Vcs
         return $vc_patchset->getPatchsetObject();
     }
 
-    public function getRevisionObject()
+    /**
+     * TODO
+     */
+    public function annotate($fileob, $rev)
     {
-        if (!isset($this->_cache['rev'])) {
-            $class = 'Horde_Vcs_Revision_' . $this->_driver;
-            $this->_cache['rev'] = new $class();
-        }
-        return $this->_cache['rev'];
+        return array();
     }
-}
 
-/**
- * Horde_Vcs annotate class.
- *
- * @package Horde_Vcs
- */
-abstract class Horde_Vcs_Annotate
-{
-    protected $_file;
-    protected $_rep;
+    /**
+     * Given a revision string, remove a given number of portions from
+     * it. For example, if we remove 2 portions of 1.2.3.4, we are
+     * left with 1.2.
+     *
+     * @param string $val      Input revision string.
+     * @param integer $amount  Number of portions to strip.
+     *
+     * @return string  Stripped revision string.
+     */
+    public function strip($val, $amount = 1)
+    {
+        return $val;
+    }
 
     /**
-     * Constructor
+     * The size of a revision number is the number of portions it has.
+     * For example, 1,2.3.4 is of size 4.
      *
-     * TODO
+     * @param string $val  Revision number to determine size of
+     *
+     * @return integer  Size of revision number
      */
-    public function __construct($rep, $file)
+    public function sizeof($val)
     {
-        $this->_rep = $rep;
-        $this->_file = $file;
+        return 1;
     }
 
     /**
-     * TODO
+     * Given two revisions, this figures out which one is greater than the
+     * the other.
+     *
+     * @param string $rev1  Revision string.
+     * @param string $rev2  Second revision string.
+     *
+     * @return integer  1 if the first is greater, -1 if the second if greater,
+     *                  and 0 if they are equal
      */
-    abstract public function doAnnotate($rev);
-}
+    public function cmp($rev1, $rev2)
+    {
+        return strcasecmp($rev1, $rev2);
+    }
 
-/**
- * @package Horde_Vcs
- */
-abstract class Horde_Vcs_Checkout
-{
     /**
-     * Function which returns a file pointing to the head of the requested
-     * revision of an SVN file.
+     * Return the logical revision before this one.
      *
-     * @param Horde_Vcs $rep     A repository object
-     * @param string $fullname  Fully qualified pathname of the desired file
-     *                          to checkout
-     * @param string $rev       Revision number to check out
+     * @param string $rev  Revision string to decrement.
      *
-     * @return resource|object  Either a PEAR_Error object, or a stream
-     *                          pointer to the head of the checkout.
+     * @return string|boolean  Revision string, or false if none could be
+     *                         determined.
      */
-    abstract function get($rep, $fullname, $rev);
+    public function prev($rev)
+    {
+        return false;
+    }
+
+    /**
+     * Returns an abbreviated form of the revision, for display.
+     *
+     * @param string $rev  The revision string.
+     *
+     * @return string  The abbreviated string.
+     */
+    public function abbrev($rev)
+    {
+        return $rev;
+    }
+
 }
 
 /**
@@ -558,11 +579,9 @@ abstract class Horde_Vcs_Diff
      */
     public function getRevisionRange($rep, $file, $r1, $r2)
     {
-        $rev_ob = $rep->getRevisionObject();
-
-        if ($rev_ob->cmp($r1, $r2) == 1) {
-            $curr = $rev_ob->prev($r1);
-            $stop = $rev_ob->prev($r2);
+        if ($rev->cmp($r1, $r2) == 1) {
+            $curr = $rev->prev($r1);
+            $stop = $rev->prev($r2);
             $flip = true;
         } else {
             $curr = $r2;
@@ -574,11 +593,11 @@ abstract class Horde_Vcs_Diff
 
         do {
             $ret_array[] = $curr;
-            $curr = $rev_ob->prev($curr);
+            $curr = $rev->prev($curr);
             if ($curr == $stop) {
                 return ($flip) ? array_reverse($ret_array) : $ret_array;
             }
-        } while ($rev_ob->cmp($curr, $stop) != -1);
+        } while ($rev->cmp($curr, $stop) != -1);
 
         return array();
     }
@@ -715,7 +734,6 @@ abstract class Horde_Vcs_Directory
             break;
 
         case Horde_Vcs::SORT_REV:
-            $this->_revob = $this->_rep->getRevisionObject();
             usort($fileList, array($this, 'fileRevSort'));
             break;
 
@@ -761,7 +779,7 @@ abstract class Horde_Vcs_Directory
      */
     public function fileRevSort($a, $b)
     {
-        return $this->_revob->cmp($a->queryHead(), $b->queryHead());
+        return $this->_rep->cmp($a->queryHead(), $b->queryHead());
     }
 
 }
@@ -781,7 +799,6 @@ class Horde_Vcs_File
     public $symrev = array();
     public $revsym = array();
     public $branches = array();
-    public $revob;
 
     /**
      * TODO
@@ -834,19 +851,15 @@ class Horde_Vcs_File
         return $this->revs[0];
     }
 
+    /**
+     * TODO
+     */
     public function queryPreviousRevision($rev)
     {
-        $last = false;
-        foreach ($this->revs as $entry) {
-            if ($last) {
-                return $entry;
-            }
-            if ($entry == $rev) {
-                $last = true;
-            }
-        }
-
-        return false;
+        $key = array_search($rev, $this->revs);
+        return (($key !== false) && isset($this->revs[$key + 1]))
+            ? $this->revs[$key + 1]
+            : false;
     }
 
     /**
@@ -892,7 +905,6 @@ class Horde_Vcs_File
 
         case Horde_Vcs::SORT_REV:
         default:
-            $this->revob = $this->rep->getRevisionObject();
             $func = 'Revision';
             break;
         }
@@ -906,7 +918,7 @@ class Horde_Vcs_File
      */
     public function sortByRevision($a, $b)
     {
-        return $this->revob->cmp($b->rev, $a->rev);
+        return $this->rep->cmp($b->rev, $a->rev);
     }
 
     public function sortByAge($a, $b)
@@ -1083,83 +1095,3 @@ abstract class Horde_Vcs_Patchset
         $this->_rep = $rep;
     }
 }
-
-/**
- * Horde_Vcs revisions class.
- *
- * Copyright Anil Madhavapeddy, <anil@recoil.org>
- *
- * @author  Anil Madhavapeddy <anil@recoil.org>
- * @package Horde_VC
- */
-class Horde_Vcs_Revision
-{
-    /**
-     * Given a revision string, remove a given number of portions from
-     * it. For example, if we remove 2 portions of 1.2.3.4, we are
-     * left with 1.2.
-     *
-     * @param string $val      Input revision string.
-     * @param integer $amount  Number of portions to strip.
-     *
-     * @return string  Stripped revision string.
-     */
-    public function strip($val, $amount = 1)
-    {
-        return $val;
-    }
-
-    /**
-     * The size of a revision number is the number of portions it has.
-     * For example, 1,2.3.4 is of size 4.
-     *
-     * @param string $val  Revision number to determine size of
-     *
-     * @return integer  Size of revision number
-     */
-    public function sizeof($val)
-    {
-        return 1;
-    }
-
-    /**
-     * Given two revisions, this figures out which one is greater than the
-     * the other.
-     *
-     * @param string $rev1  Revision string.
-     * @param string $rev2  Second revision string.
-     *
-     * @return integer  1 if the first is greater, -1 if the second if greater,
-     *                  and 0 if they are equal
-     */
-    public function cmp($rev1, $rev2)
-    {
-        return strcasecmp($rev1, $rev2);
-    }
-
-    /**
-     * Return the logical revision before this one.
-     *
-     * @param string $rev  Revision string to decrement.
-     *
-     * @return string|boolean  Revision string, or false if none could be
-     *                         determined.
-     */
-    public function prev($rev)
-    {
-        return false;
-    }
-
-    /**
-     * Returns an abbreviated form of the revision, for display.
-     *
-     * @param string $rev  The revision string.
-     *
-     * @return string  The abbreviated string.
-     */
-    public function abbrev($rev)
-    {
-        return $rev;
-    }
-
-}
index 752fedc..ee98b71 100644 (file)
@@ -74,80 +74,43 @@ class Horde_Vcs_Cvs extends Horde_Vcs_Rcs
     /**
      * TODO
      */
-    public function getAnnotateObject($filename)
-    {
-        return new Horde_Vcs_Annotate_Cvs($this, $filename);
-    }
-
-    /**
-     * TODO
-     */
     public function getPatchsetObject($filename, $cache = null)
     {
         return parent::getPatchsetObject($this->sourceroot() . '/' . $filename, $cache);
     }
-}
-
-/**
- * Horde_Vcs_Cvs annotate class.
- *
- * Anil Madhavapeddy, <anil@recoil.org>
- *
- * @author  Anil Madhavapeddy <anil@recoil.org>
- * @package Horde_Vcs
- */
-class Horde_Vcs_Annotate_Cvs extends Horde_Vcs_Annotate
-{
-    /**
-     * Temporary filename.
-     *
-     * @var string
-     */
-    protected $_tmpfile;
 
     /**
-     * Constructor.
-     *
      * TODO
      */
-    public function __construct($rep, $file)
+    public function annotate($fileob, $rev)
     {
-        $this->_tmpfile = Util::getTempFile('vc', true, $rep->getTempPath());
-        parent::__construct($rep, $file);
-    }
-
-    /**
-     * TODO
-     */
-    public function doAnnotate($rev)
-    {
-        if (!$this->_rep->isValidRevision($rev)) {
+        if (!$this->isValidRevision($rev)) {
             return false;
         }
 
-        $where = $this->_file->queryModulePath();
-        $sourceroot = $this->_rep->sourceroot();
+        $tmpfile = Util::getTempFile('vc', true, $this->getTempPath());
+        $where = $fileob->queryModulePath();
 
-        $pipe = popen($this->_rep->getPath('cvs') . ' -n server > ' . $this->_tmpfile, VC_WINDOWS ? 'wb' : 'w');
+        $pipe = popen($this->getPath('cvs') . ' -n server > ' . escapeshellarg($tmpfile), VC_WINDOWS ? 'wb' : 'w');
 
         $out = array(
-            "Root $sourceroot",
+            'Root ' . $this->sourceroot(),
             'Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E',
             'UseUnchanged',
             'Argument -r',
-            "Argument $rev",
-            "Argument $where"
+            'Argument ' . $rev,
+            'Argument ' . $where
         );
 
         $dirs = explode('/', dirname($where));
         while (count($dirs)) {
             $out[] = 'Directory ' . implode('/', $dirs);
-            $out[] = "$sourceroot/" . implode('/', $dirs);
+            $out[] = $this->sourceroot() . '/' . implode('/', $dirs);
             array_pop($dirs);
         }
 
         $out[] = 'Directory .';
-        $out[] = $sourceroot;
+        $out[] = $this->sourceroot();
         $out[] = 'annotate';
 
         foreach ($out as $line) {
@@ -155,7 +118,7 @@ class Horde_Vcs_Annotate_Cvs extends Horde_Vcs_Annotate
         }
         pclose($pipe);
 
-        if (!($fl = fopen($this->_tmpfile, VC_WINDOWS ? 'rb' : 'r'))) {
+        if (!($fl = fopen($tmpfile, VC_WINDOWS ? 'rb' : 'r'))) {
             return false;
         }
 
@@ -192,36 +155,23 @@ class Horde_Vcs_Annotate_Cvs extends Horde_Vcs_Annotate
         return $lines;
     }
 
-}
-
-/**
- * Horde_Vcs_cvs checkout class.
- *
- * Anil Madhavapeddy, <anil@recoil.org>
- *
- * @author  Anil Madhavapeddy <anil@recoil.org>
- * @package Horde_Vcs
- */
-class Horde_Vcs_Checkout_Cvs extends Horde_Vcs_Checkout
-{
     /**
-     * Static function which returns a file pointing to the head of the
-     * requested revision of an RCS file.
+     * Returns a file pointing to the head of the requested revision of a
+     * file.
      *
-     * @param Horde_Vcs_Cvs $rep  A repository object.
-     * @param string $fullname    Fully qualified pathname of the desired file
-     *                            to checkout.
-     * @param string $rev         Revision number to check out.
+     * @param string $fullname  Fully qualified pathname of the desired file
+     *                          to checkout.
+     * @param string $rev       Revision number to check out.
      *
      * @return resource  A stream pointer to the head of the checkout.
      */
-    public function get($rep, $fullname, $rev)
+    public function checkout($fullname, $rev)
     {
         if (!$rep->isValidRevision($rev)) {
             throw new Horde_Vcs_Exception('Invalid revision number');
         }
 
-        if (!($RCS = popen($rep->getPath('co') . " -p$rev " . escapeshellarg($fullname) . " 2>&1", VC_WINDOWS ? 'rb' : 'r'))) {
+        if (!($RCS = popen($this->getPath('co') . ' ' . escapeshellarg('-p' . $rev) . ' ' . escapeshellarg($fullname) . " 2>&1", VC_WINDOWS ? 'rb' : 'r'))) {
             throw new Horde_Vcs_Exception('Couldn\'t perform checkout of the requested file');
         }
 
@@ -230,7 +180,7 @@ class Horde_Vcs_Checkout_Cvs extends Horde_Vcs_Checkout
          * and we check that this is the case and error otherwise
          */
         $co = fgets($RCS, 1024);
-        if (!preg_match('/^([\S ]+),v\s+-->\s+st(andar)?d ?out(put)?\s*$/', $co, $regs) ||
+        if (!preg_match('/^([\S ]+,v)\s+-->\s+st(andar)?d ?out(put)?\s*$/', $co, $regs) ||
             ($regs[1] != $fullname)) {
             throw new Horde_Vcs_Exception('Unexpected output from checkout: ' . $co);
         }
@@ -456,7 +406,6 @@ class Horde_Vcs_File_Cvs extends Horde_Vcs_File
         }
 
         $accum = $revsym = $symrev = array();
-        $rev_ob = $this->rep->getRevisionObject();
         $state = 'init';
 
         foreach ($return_array as $line) {
@@ -503,7 +452,7 @@ class Horde_Vcs_File_Cvs extends Horde_Vcs_File
                     $branch = $log->queryBranch();
                     if (empty($this->_branch) ||
                         in_array($this->_branch, $log->queryBranch()) ||
-                        (($rev_ob->cmp($rev, $this->branches[$this->_branch]) === -1) &&
+                        (($this->rep->cmp($rev, $this->branches[$this->_branch]) === -1) &&
                          (empty($branch) ||
                           in_array('HEAD', $branch) ||
                           (strpos($this->branches[$this->_branch], $rev) === 0)))) {
@@ -541,15 +490,6 @@ class Horde_Vcs_File_Cvs extends Horde_Vcs_File
     }
 
     /**
-     * TODO
-     */
-    public function queryPreviousRevision($rev)
-    {
-        $ob = $this->rep->getRevisionObject();
-        return $ob->prev($rev);
-    }
-
-    /**
      * Return the HEAD (most recent) revision number for this file.
      *
      * @return string  HEAD revision number
@@ -734,12 +674,9 @@ class Horde_Vcs_Log_Cvs extends Horde_Vcs_Log
         }
 
         $key = array_keys($this->file->branches, $this->rev);
-        if (!empty($key)) {
-            return $key;
-        }
-
-        $rev_ob = $this->file->rep->getRevisionObject();
-        return array_keys($this->file->branches, $rev_ob->strip($this->rev, 1));
+        return empty($key)
+            ? array_keys($this->file->branches, $this->rep->strip($this->rev, 1))
+            : $key;
     }
 
 }
@@ -880,5 +817,3 @@ class Horde_Vcs_Patchset_Cvs extends Horde_Vcs_Patchset
     }
 
 }
-
-class Horde_Vcs_Revision_Cvs extends Horde_Vcs_Revision_Rcs {}
index aeef64f..f724c82 100644 (file)
@@ -54,39 +54,22 @@ class Horde_Vcs_Git extends Horde_Vcs
         return ($data[1] == 'blob');
     }
 
+    /**
+     * TODO
+     */
     public function getCommand()
     {
         return $this->getPath('git') . ' --git-dir=' . escapeshellarg($this->_sourceroot);
     }
 
-    public function getCheckout($file, $rev)
-    {
-        if (!isset($this->_cache['co'])) {
-            $this->_cache['co'] = new Horde_Vcs_Checkout_Git();
-        }
-        return $this->_cache['co']->get($this, $file->queryModulePath(), $rev);
-    }
-
-}
-
-/**
- * Horde_Vcs_Git annotate class.
- *
- * Chuck Hagenbuch <chuck@horde.org>
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_Vcs
- */
-class Horde_Vcs_Annotate_Git extends Horde_Vcs_Annotate
-{
     /**
      * TODO
      */
-    public function doAnnotate($rev)
+    public function annotate($fileob, $rev)
     {
-        $this->_rep->assertValidRevision($rev);
+        $this->assertValidRevision($rev);
 
-        $command = $this->_rep->getCommand() . ' blame -p ' . $rev . ' -- ' . escapeshellarg($this->_file->queryModulePath()) . ' 2>&1';
+        $command = $this->getCommand() . ' blame -p ' . escapeshellarg($rev) . ' -- ' . escapeshellarg($fileob->queryModulePath()) . ' 2>&1';
         $pipe = popen($command, 'r');
         if (!$pipe) {
             throw new Horde_Vcs_Exception('Failed to execute git annotate: ' . $command);
@@ -134,42 +117,41 @@ class Horde_Vcs_Annotate_Git extends Horde_Vcs_Annotate
         return $lines;
     }
 
-}
-
-/**
- * Horde_Vcs_Git checkout class.
- *
- * Chuck Hagenbuch <chuck@horde.org>
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Horde_Vcs
- */
-class Horde_Vcs_Checkout_Git extends Horde_Vcs_Checkout
-{
     /**
      * Function which returns a file pointing to the head of the requested
      * revision of a file.
      *
-     * @param Horde_Vcs $rep    A repository object
      * @param string $fullname  Fully qualified pathname of the desired file
      *                          to checkout
      * @param string $rev       Revision number to check out
      *
      * @return resource  A stream pointer to the head of the checkout.
      */
-    function get($rep, $file, $rev)
+    public function checkout($file, $rev)
     {
-        $rep->assertValidRevision($rev);
+        $this->assertValidRevision($rev);
 
-        $file_ob = $rep->getFileObject($file);
+        $file_ob = $this->getFileObject($file);
 
-        if ($pipe = popen($rep->getCommand() . ' cat-file blob ' . $file_ob->getHashForRevision($rev) . ' 2>&1', VC_WINDOWS ? 'rb' : 'r')) {
+        if ($pipe = popen($this->getCommand() . ' cat-file blob ' . $file_ob->getHashForRevision($rev) . ' 2>&1', VC_WINDOWS ? 'rb' : 'r')) {
             return $pipe;
         }
 
         throw new Horde_Vcs_Exception('Couldn\'t perform checkout of the requested file');
     }
 
+    /**
+     * Returns an abbreviated form of the revision, for display.
+     *
+     * @param string $rev  The revision string.
+     *
+     * @return string  The abbreviated string.
+     */
+    public function abbrev($rev)
+    {
+        return substr($rev, 0, 7) . '[...]';
+    }
+
 }
 
 /**
@@ -251,13 +233,13 @@ class Horde_Vcs_Diff_Git extends Horde_Vcs_Diff
         return $revs;
     }
 
-    private function _getRevisionRange($rep, $file, $r1, $r2)
+    protected function _getRevisionRange($rep, $file, $r1, $r2)
     {
         $cmd = $rep->getCommand() . ' rev-list ' . escapeshellarg($r1) . '..' . escapeshellarg($r2) . ' -- ' . escapeshellarg($file->queryModulePath());
         $revs = array();
 
         exec($cmd, $revs);
-        return array_map($revs, 'trim');
+        return array_map('trim', $revs);
     }
 }
 
@@ -653,28 +635,3 @@ class Horde_Vcs_Patchset_Git extends Horde_Vcs_Patchset
     }
 
 }
-
-class Horde_Vcs_Revision_Git extends Horde_Vcs_Revision
-{
-    /**
-     * Validation function to ensure that a revision number is of the right
-     * form.
-     *
-     * @param mixed $rev  The purported revision number.
-     *
-     * @return boolean  True if it is a revision number.
-     */
-
-    /**
-     * Returns an abbreviated form of the revision, for display.
-     *
-     * @param string $rev  The revision string.
-     *
-     * @return string  The abbreviated string.
-     */
-    public function abbrev($rev)
-    {
-        return substr($rev, 0, 7) . '[...]';
-    }
-
-}
index 4a36283..ddb22a9 100644 (file)
@@ -222,10 +222,6 @@ class Horde_Vcs_Rcs extends Horde_Vcs
         }
     }
 
-}
-
-class Horde_Vcs_Revision_Rcs extends Horde_Vcs_Revision
-{
     /**
      * Given a revision number, remove a given number of portions from
      * it. For example, if we remove 2 portions of 1.2.3.4, we are
@@ -238,14 +234,14 @@ class Horde_Vcs_Revision_Rcs extends Horde_Vcs_Revision
      */
     public function strip($val, $amount = 1)
     {
-        //if (!Horde_Vcs_Revision::valid($val)) {
-        //    return false;
-        //}
+        if (!$this->isValidRevision($val)) {
+            return false;
+        }
         $pos = 0;
         while ($amount-- > 0 && ($pos = strrpos($val, '.')) !== false) {
             $val = substr($val, 0, $pos);
         }
-        return $pos !== false ? $val : false;
+        return ($pos !== false) ? $val : false;
     }
 
     /**
@@ -258,12 +254,9 @@ class Horde_Vcs_Revision_Rcs extends Horde_Vcs_Revision
      */
     public function sizeof($val)
     {
-        //@TODO This concept is broken beyond CVS
-        //if (!Horde_Vcs_Revision::valid($val)) {
-        //    return false;
-        //}
-
-        return (substr_count($val, '.') + 1);
+        return $this->isValidRevision($val)
+            ? (substr_count($val, '.') + 1)
+            : false;
     }
 
     /**
@@ -312,4 +305,5 @@ class Horde_Vcs_Revision_Rcs extends Horde_Vcs_Revision
             }
         }
     }
+
 }
index 31c846f..9e57710 100644 (file)
@@ -78,32 +78,16 @@ class Horde_Vcs_Svn extends Horde_Vcs
         return $command;
     }
 
-    public function isValidRevision($rev)
-    {
-        return $rev && is_numeric($rev);
-    }
-}
-
-/**
- * Horde_Vcs_Svn annotate class.
- *
- * Anil Madhavapeddy, <anil@recoil.org>
- *
- * @author  Anil Madhavapeddy <anil@recoil.org>
- * @package Horde_Vcs
- */
-class Horde_Vcs_Annotate_Svn extends Horde_Vcs_Annotate
-{
     /**
      * TODO
      */
-    public function doAnnotate($rev)
+    public function annotate($fileob, $rev)
     {
-        if (!$this->_rep->isValidRevision($rev)) {
+        if (!$this->isValidRevision($rev)) {
             return false;
         }
 
-        $command = $this->_rep->getCommand() . ' annotate -r 1:' . $rev . ' ' . escapeshellarg($this->_file->queryFullPath()) . ' 2>&1';
+        $command = $this->getCommand() . ' annotate -r ' . escapeshellarg('1:' . $rev) . ' ' . escapeshellarg($fileob->queryFullPath()) . ' 2>&1';
         $pipe = popen($command, 'r');
         if (!$pipe) {
             throw new Horde_Vcs_Exception('Failed to execute svn annotate: ' . $command);
@@ -129,40 +113,35 @@ class Horde_Vcs_Annotate_Svn extends Horde_Vcs_Annotate
         return $lines;
     }
 
-}
-
-/**
- * Horde_Vcs_Svn checkout class.
- *
- * Anil Madhavapeddy, <anil@recoil.org>
- *
- * @author  Anil Madhavapeddy <anil@recoil.org>
- * @package Horde_Vcs
- */
-class Horde_Vcs_Checkout_Svn extends Horde_Vcs_Checkout
-{
     /**
      * Function which returns a file pointing to the head of the requested
      * revision of a file.
      *
-     * @param Horde_Vcs $rep    A repository object
      * @param string $fullname  Fully qualified pathname of the desired file
      *                          to checkout
      * @param string $rev       Revision number to check out
      *
      * @return resource  A stream pointer to the head of the checkout.
      */
-    public function get($rep, $fullname, $rev)
+    public function checkout($fullname, $rev)
     {
         if (!$rep->isValidRevision($rev)) {
             throw new Horde_Vcs_Exception('Invalid revision number');
         }
 
-        return ($RCS = popen($rep->getCommand() . ' cat -r ' . $rev . ' ' . escapeshellarg($fullname) . ' 2>&1', VC_WINDOWS ? 'rb' : 'r'))
+        return ($RCS = popen($this->getCommand() . ' cat -r ' . escapeshellarg($rev) . ' ' . escapeshellarg($fullname) . ' 2>&1', VC_WINDOWS ? 'rb' : 'r'))
             ? $RCS
             : throw new Horde_Vcs_Exception('Couldn\'t perform checkout of the requested file');
     }
 
+    /**
+     * TODO
+     */
+    public function isValidRevision($rev)
+    {
+        return $rev && is_numeric($rev);
+    }
+
 }
 
 /**