Copyright 2008-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Exemple #1
0
 /**
  * Obtain the differences between two revisions of a file.
  *
  * @param Horde_Vcs_File_Cvs $file  The desired file.
  * @param string $rev1              Original revision number to compare
  *                                  from.
  * @param string $rev2              New revision number to compare against.
  * @param array $opts               The following optional options:
  *                                  - 'num': (integer) DEFAULT: 3
  *                                  - 'type': (string) DEFAULT: 'unified'
  *                                  - 'ws': (boolean) DEFAULT: true
  *
  * @return string|boolean  False on failure, or a string containing the
  *                         diff on success.
  */
 protected function _diff(Horde_Vcs_File_Base $file, $rev1, $rev2, $opts)
 {
     $fullName = $file->getPath();
     $diff = array();
     $flags = '-kk ';
     if (!$opts['ws']) {
         $flags .= ' -bB ';
     }
     switch ($opts['type']) {
         case 'context':
             $flags .= '-p --context=' . escapeshellarg((int) $opts['num']);
             break;
         case 'unified':
             $flags .= '-p --unified=' . escapeshellarg((int) $opts['num']);
             break;
         case 'column':
             $flags .= '--side-by-side --width=120';
             break;
         case 'ed':
             $flags .= '-e';
             break;
     }
     // Windows versions of cvs always return $where with forwards slashes.
     if (VC_WINDOWS) {
         $fullName = str_replace(DIRECTORY_SEPARATOR, '/', $fullName);
     }
     // TODO: add options for $hr options - however these may not be
     // compatible with some diffs.
     $command = escapeshellcmd($this->getPath('rcsdiff')) . ' ' . $flags . ' -r' . escapeshellarg($rev1) . ' -r' . escapeshellarg($rev2) . ' ' . escapeshellarg($fullName) . ' 2>&1';
     if (VC_WINDOWS) {
         $command .= ' < ' . escapeshellarg(__FILE__);
     }
     exec($command, $diff, $retval);
     return $retval > 0 ? $diff : array();
 }
Exemple #2
0
 /**
  * Return the name of this file relative to its sourceroot.
  *
  * @return string  Pathname relative to the sourceroot.
  */
 public function getSourcerootPath()
 {
     return substr(parent::getSourcerootPath(), 0, -2);
 }
Exemple #3
0
 /**
  * Obtain the differences between two revisions of a file.
  *
  * @param Horde_Vcs_File_Svn $file  The desired file.
  * @param string $rev1              Original revision number to compare
  *                                  from.
  * @param string $rev2              New revision number to compare against.
  * @param array $opts               The following optional options:
  *                                  - 'num': (integer) DEFAULT: 3
  *                                  - 'type': (string) DEFAULT: 'unified'
  *                                  - 'ws': (boolean) DEFAULT: true
  *
  * @return string|boolean  False on failure, or a string containing the
  *                         diff on success.
  */
 protected function _diff(Horde_Vcs_File_Base $file, $rev1, $rev2, $opts)
 {
     $diff = array();
     $flags = '';
     if (!$opts['ws']) {
         $flags .= ' -bB ';
     }
     switch ($opts['type']) {
         case 'context':
             $flags .= '--context=' . (int) $opts['num'];
             break;
         case 'unified':
             $flags .= '-p --unified=' . (int) $opts['num'];
             break;
         case 'column':
             $flags .= '--side-by-side --width=120';
             break;
         case 'ed':
             $flags .= '-e';
             break;
     }
     // TODO: add options for $hr options - however these may not
     // be compatible with some diffs.
     $command = $this->getCommand() . " diff --diff-cmd " . $this->getPath('diff') . ' -r ' . escapeshellarg($rev1 . ':' . $rev2) . ' -x ' . escapeshellarg($flags) . ' ' . escapeshellarg($file->getPath()) . ' 2>&1';
     exec($command, $diff);
     return $diff;
 }
Exemple #4
0
 /**
  * Obtain the differences between two revisions of a file.
  *
  * @param Horde_Vcs_File_Git $file  The desired file.
  * @param string $rev1              Original revision number to compare
  *                                  from.
  * @param string $rev2              New revision number to compare against.
  * @param array $opts               The following optional options:
  *                                  - 'num': (integer) DEFAULT: 3
  *                                  - 'type': (string) DEFAULT: 'unified'
  *                                  - 'ws': (boolean) DEFAULT: true
  *
  * @return string  The diff text.
  */
 protected function _diff(Horde_Vcs_File_Base $file, $rev1, $rev2, $opts)
 {
     $diff = array();
     $flags = '';
     if (!$opts['ws']) {
         $flags .= ' -b -w ';
     }
     if (!$rev1) {
         $command = $this->getCommand() . ' show --oneline ' . escapeshellarg($rev2) . ' -- ' . escapeshellarg($file->getSourcerootPath()) . ' 2>&1';
     } else {
         switch ($opts['type']) {
             case 'unified':
                 $flags .= '--unified=' . escapeshellarg((int) $opts['num']);
                 break;
         }
         // @TODO: add options for $hr options - however these may not
         // be compatible with some diffs.
         $command = $this->getCommand() . ' diff -M -C ' . $flags . ' --no-color ' . escapeshellarg($rev1 . '..' . $rev2) . ' -- ' . escapeshellarg($file->getSourcerootPath()) . ' 2>&1';
     }
     exec($command, $diff);
     return $diff;
 }
Exemple #5
0
 /**
  * TODO
  */
 public function revisionCount()
 {
     if (empty($this->_branch)) {
         return parent::revisionCount();
     }
     $this->_ensureInitialized();
     return count($this->_revlist[$this->_branch]);
 }