/** * 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(); }
/** * 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; }