Overview

Packages

  • None
  • Vcs

Classes

  • Horde_Vcs
  • Horde_Vcs_Base
  • Horde_Vcs_Cvs
  • Horde_Vcs_Directory_Base
  • Horde_Vcs_Directory_Cvs
  • Horde_Vcs_Directory_Git
  • Horde_Vcs_Directory_Rcs
  • Horde_Vcs_Directory_Svn
  • Horde_Vcs_File_Base
  • Horde_Vcs_File_Cvs
  • Horde_Vcs_File_Git
  • Horde_Vcs_File_Rcs
  • Horde_Vcs_File_Svn
  • Horde_Vcs_Git
  • Horde_Vcs_Log_Base
  • Horde_Vcs_Log_Cvs
  • Horde_Vcs_Log_Git
  • Horde_Vcs_Log_Rcs
  • Horde_Vcs_Log_Svn
  • Horde_Vcs_Patchset
  • Horde_Vcs_Patchset_Base
  • Horde_Vcs_Patchset_Cvs
  • Horde_Vcs_Patchset_Git
  • Horde_Vcs_Patchset_Svn
  • Horde_Vcs_QuickLog_Base
  • Horde_Vcs_QuickLog_Cvs
  • Horde_Vcs_QuickLog_Git
  • Horde_Vcs_QuickLog_Rcs
  • Horde_Vcs_QuickLog_Svn
  • Horde_Vcs_Rcs
  • Horde_Vcs_Svn
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Subversion file class.
  4:  *
  5:  * @author  Anil Madhavapeddy <anil@recoil.org>
  6:  * @author  Michael Slusarz <slusarz@horde.org>
  7:  * @package Vcs
  8:  */
  9: class Horde_Vcs_File_Svn extends Horde_Vcs_File_Base
 10: {
 11:     /**
 12:      * The current driver.
 13:      *
 14:      * @var string
 15:      */
 16:     protected $_driver = 'Svn';
 17: 
 18:     /**
 19:      * @var resource
 20:      */
 21:     protected $_logpipe;
 22: 
 23:     protected function _init()
 24:     {
 25:         $cmd = $this->_rep->getCommand() . ' log -v '
 26:             . escapeshellarg($this->getPath()) . ' 2>&1';
 27:         $this->_logpipe = popen($cmd, 'r');
 28:         if (!$this->_logpipe) {
 29:             throw new Horde_Vcs_Exception('Failed to execute svn log: ' . $cmd);
 30:         }
 31: 
 32:         $header = fgets($this->_logpipe);
 33:         if (!strspn($header, '-')) {
 34:             throw new Horde_Vcs_Exception('Error executing svn log: ' . $header);
 35:         }
 36: 
 37:         while (!feof($this->_logpipe)) {
 38:             try {
 39:                 $log = $this->_getLog();
 40:                 $rev = $log->getRevision();
 41:                 $this->_logs[$rev] = $log;
 42:                 $this->_revs[] = $rev;
 43:             } catch (Horde_Vcs_Exception $e) {}
 44:         }
 45: 
 46:         pclose($this->_logpipe);
 47:     }
 48: 
 49:     /**
 50:      * Parses a single log entry from a svn log pipe.
 51:      *
 52:      * @param boolean $parse_files  Wether the log entries contain file
 53:      *                              listings (-v flag).
 54:      *
 55:      * @return array  A list of revision, author, message, date, size and files.
 56:      * @throws Horde_Vcs_Exception
 57:      */
 58:     public function parseLog($parse_files = true)
 59:     {
 60:         $line = fgets($this->_logpipe);
 61:         if (feof($this->_logpipe) || !$line) {
 62:             throw new Horde_Vcs_Exception('No more data');
 63:         }
 64: 
 65:         if (preg_match('/^r([0-9]*) \| (.*?) \| (.*) \(.*\) \| ([0-9]*) lines?$/', $line, $matches)) {
 66:             $rev = $matches[1];
 67:             $author = $matches[2];
 68:             $date = strtotime($matches[3]);
 69:             $size = $matches[4];
 70:         } else {
 71:             throw new Horde_Vcs_Exception('Unknown log format: ' . $line);
 72:         }
 73: 
 74:         fgets($this->_logpipe);
 75: 
 76:         $files = array();
 77:         if ($parse_files) {
 78:             while (($line = trim(fgets($this->_logpipe))) != '') {
 79:                 list($mode, $file) = explode(' ', trim($line));
 80:                 $files[ltrim($file, '/')] = array('status' => $mode);
 81:             }
 82:         }
 83: 
 84:         $log = '';
 85:         for ($i = 0; $i != $size; ++$i) {
 86:             $log .= rtrim(fgets($this->_logpipe)) . "\n";
 87:         }
 88:         $log = rtrim($log);
 89: 
 90:         fgets($this->_logpipe);
 91: 
 92:         return array($rev, $author, $log, $date, $size, $files);
 93:     }
 94: 
 95:     /**
 96:      * Returns name of the current file without the repository
 97:      * extensions (usually ,v).
 98:      *
 99:      * @return string  Filename without repository extension.
100:      */
101:     public function getFileName()
102:     {
103:         return preg_replace('/,v$/', '', $this->_name);
104:     }
105: 
106:     /**
107:      * Returns the revision before the specified revision.
108:      *
109:      * @param string $rev  A revision.
110:      *
111:      * @return string  The previous revision or null if the first revision.
112:      */
113:     public function getPreviousRevision($rev)
114:     {
115:         /* Shortcut for SVN's incrementing revisions. */
116:         $rev--;
117:         return $rev ? $rev : null;
118:     }
119: 
120:     /**
121:      * Returns a log object for the most recent log entry of this file.
122:      *
123:      * @return Horde_Vcs_QuickLog_Svn  Log object of the last entry in the file.
124:      * @throws Horde_Vcs_Exception
125:      */
126:     public function getLastLog()
127:     {
128:         $cmd = $this->_rep->getCommand() . ' log -l 1 ' . escapeshellarg($this->getPath()) . ' 2>&1';
129:         $this->_logpipe = popen($cmd, 'r');
130:         if (!$this->_logpipe) {
131:             throw new Horde_Vcs_Exception('Failed to execute svn log: ' . $cmd);
132:         }
133: 
134:         $header = fgets($this->_logpipe);
135:         if (!strspn($header, '-')) {
136:             throw new Horde_Vcs_Exception('Error executing svn log: ' . $header);
137:         }
138: 
139:         list($rev, $author, $log, $date) = $this->parseLog(false);
140:         pclose($this->_logpipe);
141: 
142:         return new Horde_Vcs_QuickLog_Svn($this->_rep, $rev, $date, $author, $log);
143:     }
144: }
145: 
API documentation generated by ApiGen