From: Michael M Slusarz Date: Fri, 23 Jan 2009 18:49:29 +0000 (-0700) Subject: Remove Horde_Vcs_[Annotate|Checkout|Revision]. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=abc2535ea6f8b5cf3860b4630329b854a946e385;p=horde.git Remove Horde_Vcs_[Annotate|Checkout|Revision]. All these functions are better off in Horde_Vcs. --- diff --git a/chora/annotate.php b/chora/annotate.php index ccf81e9a2..6c254b71a 100644 --- a/chora/annotate.php +++ b/chora/annotate.php @@ -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); } diff --git a/chora/browse.php b/chora/browse.php index 1597d52b0..9f5abf6f3 100644 --- a/chora/browse.php +++ b/chora/browse.php @@ -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); diff --git a/chora/co.php b/chora/co.php index 8e3fae117..4b97a73e8 100644 --- a/chora/co.php +++ b/chora/co.php @@ -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); } diff --git a/chora/diff.php b/chora/diff.php index 354e914f3..4f29a6b58 100644 --- a/chora/diff.php +++ b/chora/diff.php @@ -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); diff --git a/chora/history.php b/chora/history.php index 2f69f741b..8e382d6c1 100644 --- a/chora/history.php +++ b/chora/history.php @@ -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()); diff --git a/chora/templates/annotate/line.inc b/chora/templates/annotate/line.inc index a7824ae34..3e3dbbbc1 100644 --- a/chora/templates/annotate/line.inc +++ b/chora/templates/annotate/line.inc @@ -6,7 +6,7 @@ - abbrev($rev)) ?> + abbrev($rev)) ?> "> @@ -14,7 +14,7 @@ - abbrev($prev)) ?> + abbrev($prev)) ?> diff --git a/chora/templates/diff/hr/header.inc b/chora/templates/diff/hr/header.inc index 365c404da..70240b70d 100644 --- a/chora/templates/diff/hr/header.inc +++ b/chora/templates/diff/hr/header.inc @@ -51,7 +51,7 @@
  • - abbrev($val['rev'])) ?>: + abbrev($val['rev'])) ?>:
    diff --git a/chora/templates/directory/file.inc b/chora/templates/directory/file.inc index 67452b9ec..0169bf7c6 100644 --- a/chora/templates/directory/file.inc +++ b/chora/templates/directory/file.inc @@ -20,7 +20,7 @@ -abbrev($head)) ?> +abbrev($head)) ?> @@ -31,7 +31,7 @@ - abbrev($head)) ?> + abbrev($head)) ?> diff --git a/chora/templates/log/rev.inc b/chora/templates/log/rev.inc index 6bf793e41..24a6efb81 100644 --- a/chora/templates/log/rev.inc +++ b/chora/templates/log/rev.inc @@ -5,7 +5,7 @@ " onclick="Chora_RevLog.sdiff(this);"> - abbrev($rev)) ?> + abbrev($rev)) ?> $val))) . htmlspecialchars($val) ?> diff --git a/framework/Vcs/lib/Horde/Vcs.php b/framework/Vcs/lib/Horde/Vcs.php index fdf3747cc..1fbb81f86 100644 --- a/framework/Vcs/lib/Horde/Vcs.php +++ b/framework/Vcs/lib/Horde/Vcs.php @@ -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, - * - * @author Anil Madhavapeddy - * @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; - } - -} diff --git a/framework/Vcs/lib/Horde/Vcs/Cvs.php b/framework/Vcs/lib/Horde/Vcs/Cvs.php index 752fedc01..ee98b71b8 100644 --- a/framework/Vcs/lib/Horde/Vcs/Cvs.php +++ b/framework/Vcs/lib/Horde/Vcs/Cvs.php @@ -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, - * - * @author Anil Madhavapeddy - * @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, - * - * @author Anil Madhavapeddy - * @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 {} diff --git a/framework/Vcs/lib/Horde/Vcs/Git.php b/framework/Vcs/lib/Horde/Vcs/Git.php index aeef64f26..f724c82ce 100644 --- a/framework/Vcs/lib/Horde/Vcs/Git.php +++ b/framework/Vcs/lib/Horde/Vcs/Git.php @@ -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 - * - * @author Chuck Hagenbuch - * @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 - * - * @author Chuck Hagenbuch - * @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) . '[...]'; - } - -} diff --git a/framework/Vcs/lib/Horde/Vcs/Rcs.php b/framework/Vcs/lib/Horde/Vcs/Rcs.php index 4a36283d1..ddb22a948 100644 --- a/framework/Vcs/lib/Horde/Vcs/Rcs.php +++ b/framework/Vcs/lib/Horde/Vcs/Rcs.php @@ -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 } } } + } diff --git a/framework/Vcs/lib/Horde/Vcs/Svn.php b/framework/Vcs/lib/Horde/Vcs/Svn.php index 31c846f81..9e57710f7 100644 --- a/framework/Vcs/lib/Horde/Vcs/Svn.php +++ b/framework/Vcs/lib/Horde/Vcs/Svn.php @@ -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, - * - * @author Anil Madhavapeddy - * @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, - * - * @author Anil Madhavapeddy - * @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); + } + } /**