From c0a31e58550e2101ad4c6105bc489600d55dacd9 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Sat, 27 Nov 2010 23:02:16 -0500 Subject: [PATCH] Split subversion support files as well --- framework/Vcs/lib/Horde/Vcs/Directory/Svn.php | 56 ++++++ framework/Vcs/lib/Horde/Vcs/File/Svn.php | 80 ++++++++ framework/Vcs/lib/Horde/Vcs/Log/Svn.php | 55 ++++++ framework/Vcs/lib/Horde/Vcs/Patchset/Svn.php | 59 ++++++ framework/Vcs/lib/Horde/Vcs/Svn.php | 255 -------------------------- framework/Vcs/package.xml | 8 + 6 files changed, 258 insertions(+), 255 deletions(-) create mode 100644 framework/Vcs/lib/Horde/Vcs/Directory/Svn.php create mode 100644 framework/Vcs/lib/Horde/Vcs/File/Svn.php create mode 100644 framework/Vcs/lib/Horde/Vcs/Log/Svn.php create mode 100644 framework/Vcs/lib/Horde/Vcs/Patchset/Svn.php diff --git a/framework/Vcs/lib/Horde/Vcs/Directory/Svn.php b/framework/Vcs/lib/Horde/Vcs/Directory/Svn.php new file mode 100644 index 000000000..a127eb1d9 --- /dev/null +++ b/framework/Vcs/lib/Horde/Vcs/Directory/Svn.php @@ -0,0 +1,56 @@ + + * @author Michael Slusarz + * @package Horde_Vcs + */ +class Horde_Vcs_Directory_Svn extends Horde_Vcs_Directory +{ + /** + * Create a Directory object to store information about the files in a + * single directory in the repository. + * + * @param Horde_Vcs $rep The Repository object this directory is part of. + * @param string $dn Path to the directory. + * @param array $opts TODO + */ + public function __construct($rep, $dn, $opts = array()) + { + parent::__construct($rep, $dn, $opts); + + $cmd = $rep->getCommand() . ' ls ' . escapeshellarg($rep->sourceroot() . $this->queryDir()) . ' 2>&1'; + + $dir = popen($cmd, 'r'); + if (!$dir) { + throw new Horde_Vcs_Exception('Failed to execute svn ls: ' . $cmd); + } + + /* Create two arrays - one of all the files, and the other of + * all the dirs. */ + $errors = array(); + while (!feof($dir)) { + $line = chop(fgets($dir, 1024)); + if (!strlen($line)) { + continue; + } + + if (substr($line, 0, 4) == 'svn:') { + $errors[] = $line; + } elseif (substr($line, -1) == '/') { + $this->_dirs[] = substr($line, 0, -1); + } else { + $this->_files[] = $rep->getFileObject($this->queryDir() . '/' . $line, array('quicklog' => !empty($opts['quicklog']))); + } + } + + pclose($dir); + + if (empty($errors)) { + return true; + } + + throw new Horde_Vcs_Exception(implode("\n", $errors)); + } +} diff --git a/framework/Vcs/lib/Horde/Vcs/File/Svn.php b/framework/Vcs/lib/Horde/Vcs/File/Svn.php new file mode 100644 index 000000000..724d40394 --- /dev/null +++ b/framework/Vcs/lib/Horde/Vcs/File/Svn.php @@ -0,0 +1,80 @@ + + * @author Michael Slusarz + * @package Horde_Vcs + */ +class Horde_Vcs_File_Svn extends Horde_Vcs_File +{ + /** + * @var resource + */ + public $logpipe; + + /** + * Have we initalized logs and revisions? + * + * @var boolean + */ + private $_initialized = false; + + protected function _ensureRevisionsInitialized() + { + if (!$this->_initialized) { $this->_init(); } + $this->_initialized = true; + } + + protected function _ensureLogsInitialized() + { + if (!$this->_initialized) { $this->_init(); } + $this->_initialized = true; + } + + protected function _init() + { + // This doesn't work; need to find another way to simply + // request the most recent revision: + // + // $flag = $this->_quicklog ? '-r HEAD ' : ''; + + $cmd = $this->_rep->getCommand() . ' log -v ' . escapeshellarg($this->queryFullPath()) . ' 2>&1'; + $pipe = popen($cmd, 'r'); + if (!$pipe) { + throw new Horde_Vcs_Exception('Failed to execute svn log: ' . $cmd); + } + + $header = fgets($pipe); + if (!strspn($header, '-')) { + throw new Horde_Vcs_Exception('Error executing svn log: ' . $header); + } + + $this->logpipe = $pipe; + while (!feof($pipe)) { + try { + $log = $this->_rep->getLogObject($this, null); + $rev = $log->queryRevision(); + $this->logs[$rev] = $log; + $this->_revs[] = $rev; + } catch (Horde_Vcs_Exception $e) {} + + if ($this->_quicklog) { + break; + } + } + + pclose($pipe); + } + + /** + * Returns name of the current file without the repository + * extensions (usually ,v). + * + * @return string Filename without repository extension. + */ + public function queryName() + { + return preg_replace('/,v$/', '', $this->_name); + } +} diff --git a/framework/Vcs/lib/Horde/Vcs/Log/Svn.php b/framework/Vcs/lib/Horde/Vcs/Log/Svn.php new file mode 100644 index 000000000..ae737008c --- /dev/null +++ b/framework/Vcs/lib/Horde/Vcs/Log/Svn.php @@ -0,0 +1,55 @@ + + * @package Horde_Vcs + */ +class Horde_Vcs_Log_Svn extends Horde_Vcs_Log +{ + /** + * TODO + */ + protected $_files = array(); + + /** + * Constructor. + */ + protected function _init() + { + $line = fgets($this->_file->logpipe); + if (feof($this->_file->logpipe) || !$line) { + throw new Horde_Vcs_Exception('No more data'); + } + + if (preg_match('/^r([0-9]*) \| (.*?) \| (.*) \(.*\) \| ([0-9]*) lines?$/', $line, $matches)) { + $this->_rev = $matches[1]; + $this->_author = $matches[2]; + $this->_date = strtotime($matches[3]); + $size = $matches[4]; + } else { + throw new Horde_Vcs_Exception('SVN Error'); + } + + fgets($this->_file->logpipe); + + while (($line = trim(fgets($this->_file->logpipe))) != '') { + $this->_files[] = $line; + } + + for ($i = 0; $i != $size; ++$i) { + $this->_log = $this->_log . chop(fgets($this->_file->logpipe)) . "\n"; + } + + $this->_log = chop($this->_log); + fgets($this->_file->logpipe); + } + + /** + * TODO + */ + public function queryFiles() + { + return $this->_files; + } +} diff --git a/framework/Vcs/lib/Horde/Vcs/Patchset/Svn.php b/framework/Vcs/lib/Horde/Vcs/Patchset/Svn.php new file mode 100644 index 000000000..70d29a7ab --- /dev/null +++ b/framework/Vcs/lib/Horde/Vcs/Patchset/Svn.php @@ -0,0 +1,59 @@ + + * @author Michael Slusarz + * @package Horde_Vcs + */ +class Horde_Vcs_Patchset_Svn extends Horde_Vcs_Patchset +{ + /** + * Constructor + * + * @param Horde_Vcs $rep A Horde_Vcs repository object. + * @param string $file The filename to create patchsets for. + */ + public function __construct($rep, $opts = array()) + { + // TODO: Allow access via 'range' + $fileOb = $rep->getFileObject($opts['file']); + + foreach ($fileOb->logs as $rev => $log) { + $this->_patchsets[$rev] = array( + 'author' => $log->queryAuthor(), + 'branch' => '', + 'date' => $log->queryDate(), + 'log' => $log->queryLog(), + 'members' => array(), + 'tag' => '' + ); + + foreach ($log->queryFiles() as $file) { + $action = substr($file, 0, 1); + $file = preg_replace('/.*?\s(.*?)(\s|$).*/', '\\1', $file); + $to = $rev; + $status = self::MODIFIED; + if ($action == 'A') { + $from = null; + $status = self::ADDED; + } elseif ($action == 'D') { + $from = $to; + $to = null; + $status = self::DELETED; + } else { + // This technically isn't the previous revision, + // but it works for diffing purposes. + $from = $to - 1; + } + + $this->_patchsets[$rev]['members'][] = array('file' => $file, + 'from' => $from, + 'to' => $to, + 'status' => $status); + } + } + + return true; + } +} diff --git a/framework/Vcs/lib/Horde/Vcs/Svn.php b/framework/Vcs/lib/Horde/Vcs/Svn.php index 338f8d5fd..f1bf8f282 100644 --- a/framework/Vcs/lib/Horde/Vcs/Svn.php +++ b/framework/Vcs/lib/Horde/Vcs/Svn.php @@ -207,259 +207,4 @@ class Horde_Vcs_Svn extends Horde_Vcs exec($command, $diff, $retval); return $diff; } - -} - -/** - * Horde_Vcs_Svn directory class. - * - * @author Anil Madhavapeddy - * @author Michael Slusarz - * @package Horde_Vcs - */ -class Horde_Vcs_Directory_Svn extends Horde_Vcs_Directory -{ - /** - * Create a Directory object to store information about the files in a - * single directory in the repository. - * - * @param Horde_Vcs $rep The Repository object this directory is part of. - * @param string $dn Path to the directory. - * @param array $opts TODO - */ - public function __construct($rep, $dn, $opts = array()) - { - parent::__construct($rep, $dn, $opts); - - $cmd = $rep->getCommand() . ' ls ' . escapeshellarg($rep->sourceroot() . $this->queryDir()) . ' 2>&1'; - - $dir = popen($cmd, 'r'); - if (!$dir) { - throw new Horde_Vcs_Exception('Failed to execute svn ls: ' . $cmd); - } - - /* Create two arrays - one of all the files, and the other of - * all the dirs. */ - $errors = array(); - while (!feof($dir)) { - $line = chop(fgets($dir, 1024)); - if (!strlen($line)) { - continue; - } - - if (substr($line, 0, 4) == 'svn:') { - $errors[] = $line; - } elseif (substr($line, -1) == '/') { - $this->_dirs[] = substr($line, 0, -1); - } else { - $this->_files[] = $rep->getFileObject($this->queryDir() . '/' . $line, array('quicklog' => !empty($opts['quicklog']))); - } - } - - pclose($dir); - - if (empty($errors)) { - return true; - } - - throw new Horde_Vcs_Exception(implode("\n", $errors)); - } - -} - -/** - * Horde_Vcs_Svn file class. - * - * @author Anil Madhavapeddy - * @author Michael Slusarz - * @package Horde_Vcs - */ -class Horde_Vcs_File_Svn extends Horde_Vcs_File -{ - /** - * @var resource - */ - public $logpipe; - - /** - * Have we initalized logs and revisions? - * - * @var boolean - */ - private $_initialized = false; - - protected function _ensureRevisionsInitialized() - { - if (!$this->_initialized) { $this->_init(); } - $this->_initialized = true; - } - - protected function _ensureLogsInitialized() - { - if (!$this->_initialized) { $this->_init(); } - $this->_initialized = true; - } - - protected function _init() - { - // This doesn't work; need to find another way to simply - // request the most recent revision: - // - // $flag = $this->_quicklog ? '-r HEAD ' : ''; - - $cmd = $this->_rep->getCommand() . ' log -v ' . escapeshellarg($this->queryFullPath()) . ' 2>&1'; - $pipe = popen($cmd, 'r'); - if (!$pipe) { - throw new Horde_Vcs_Exception('Failed to execute svn log: ' . $cmd); - } - - $header = fgets($pipe); - if (!strspn($header, '-')) { - throw new Horde_Vcs_Exception('Error executing svn log: ' . $header); - } - - $this->logpipe = $pipe; - while (!feof($pipe)) { - try { - $log = $this->_rep->getLogObject($this, null); - $rev = $log->queryRevision(); - $this->logs[$rev] = $log; - $this->_revs[] = $rev; - } catch (Horde_Vcs_Exception $e) {} - - if ($this->_quicklog) { - break; - } - } - - pclose($pipe); - } - - /** - * Returns name of the current file without the repository - * extensions (usually ,v). - * - * @return string Filename without repository extension. - */ - public function queryName() - { - return preg_replace('/,v$/', '', $this->_name); - } - -} - -/** - * Horde_Vcs_Svn log class. - * - * @author Anil Madhavapeddy - * @package Horde_Vcs - */ -class Horde_Vcs_Log_Svn extends Horde_Vcs_Log -{ - /** - * TODO - */ - protected $_files = array(); - - /** - * Constructor. - */ - protected function _init() - { - $line = fgets($this->_file->logpipe); - if (feof($this->_file->logpipe) || !$line) { - throw new Horde_Vcs_Exception('No more data'); - } - - if (preg_match('/^r([0-9]*) \| (.*?) \| (.*) \(.*\) \| ([0-9]*) lines?$/', $line, $matches)) { - $this->_rev = $matches[1]; - $this->_author = $matches[2]; - $this->_date = strtotime($matches[3]); - $size = $matches[4]; - } else { - throw new Horde_Vcs_Exception('SVN Error'); - } - - fgets($this->_file->logpipe); - - while (($line = trim(fgets($this->_file->logpipe))) != '') { - $this->_files[] = $line; - } - - for ($i = 0; $i != $size; ++$i) { - $this->_log = $this->_log . chop(fgets($this->_file->logpipe)) . "\n"; - } - - $this->_log = chop($this->_log); - fgets($this->_file->logpipe); - } - - /** - * TODO - */ - public function queryFiles() - { - return $this->_files; - } - -} - -/** - * Horde_Vcs_Svn Patchset class. - * - * @author Anil Madhavapeddy - * @author Michael Slusarz - * @package Horde_Vcs - */ -class Horde_Vcs_Patchset_Svn extends Horde_Vcs_Patchset -{ - /** - * Constructor - * - * @param Horde_Vcs $rep A Horde_Vcs repository object. - * @param string $file The filename to create patchsets for. - */ - public function __construct($rep, $opts = array()) - { - // TODO: Allow access via 'range' - $fileOb = $rep->getFileObject($opts['file']); - - foreach ($fileOb->logs as $rev => $log) { - $this->_patchsets[$rev] = array( - 'author' => $log->queryAuthor(), - 'branch' => '', - 'date' => $log->queryDate(), - 'log' => $log->queryLog(), - 'members' => array(), - 'tag' => '' - ); - - foreach ($log->queryFiles() as $file) { - $action = substr($file, 0, 1); - $file = preg_replace('/.*?\s(.*?)(\s|$).*/', '\\1', $file); - $to = $rev; - $status = self::MODIFIED; - if ($action == 'A') { - $from = null; - $status = self::ADDED; - } elseif ($action == 'D') { - $from = $to; - $to = null; - $status = self::DELETED; - } else { - // This technically isn't the previous revision, - // but it works for diffing purposes. - $from = $to - 1; - } - - $this->_patchsets[$rev]['members'][] = array('file' => $file, - 'from' => $from, - 'to' => $to, - 'status' => $status); - } - } - - return true; - } - } diff --git a/framework/Vcs/package.xml b/framework/Vcs/package.xml index b79720b4f..e1daa073a 100644 --- a/framework/Vcs/package.xml +++ b/framework/Vcs/package.xml @@ -45,18 +45,22 @@ + + + + @@ -110,12 +114,16 @@ + + + + -- 2.11.0