Esempio n. 1
0
 /**
  * GetDiff
  *
  * Gets the diff output
  *
  * @access public
  * @param string $file override the filename on the diff
  * @return string diff output
  */
 public function GetDiff($file = '', $readFileData = true, $explode = false)
 {
     if ($this->diffDataRead && $file == $this->diffDataName) {
         if ($explode) {
             return explode("\n", $this->diffData);
         } else {
             return $this->diffData;
         }
     }
     if (!$this->diffInfoRead && $readFileData) {
         $this->ReadDiffInfo();
     }
     $this->diffDataName = $file;
     $this->diffDataRead = true;
     if (!empty($this->status) && $this->status != 'A' && $this->status != 'D' && $this->status != 'M') {
         $this->diffData = '';
         return;
     }
     if (function_exists('xdiff_string_diff')) {
         $this->diffData = $this->GetXDiff(3, true, $file);
     } else {
         $tmpdir = GitPHP_TmpDir::GetInstance();
         $pid = 0;
         if (function_exists('posix_getpid')) {
             $pid = posix_getpid();
         } else {
             $pid = rand();
         }
         $fromTmpFile = null;
         $toTmpFile = null;
         $fromName = null;
         $toName = null;
         if (empty($this->status) || $this->status == 'D' || $this->status == 'M') {
             $fromBlob = $this->GetFromBlob();
             $fromTmpFile = 'gitphp_' . $pid . '_from';
             $tmpdir->AddFile($fromTmpFile, $fromBlob->GetData());
             $fromName = 'a/';
             if (!empty($file)) {
                 $fromName .= $file;
             } else {
                 if (!empty($this->fromFile)) {
                     $fromName .= $this->fromFile;
                 } else {
                     $fromName .= $this->fromHash;
                 }
             }
         }
         if (empty($this->status) || $this->status == 'A' || $this->status == 'M') {
             $toBlob = $this->GetToBlob();
             $toTmpFile = 'gitphp_' . $pid . '_to';
             $tmpdir->AddFile($toTmpFile, $toBlob->GetData());
             $toName = 'b/';
             if (!empty($file)) {
                 $toName .= $file;
             } else {
                 if (!empty($this->toFile)) {
                     $toName .= $this->toFile;
                 } else {
                     $toName .= $this->toHash;
                 }
             }
         }
         $this->diffData = GitPHP_DiffExe::Diff(empty($fromTmpFile) ? null : escapeshellarg($tmpdir->GetDir() . $fromTmpFile), $fromName, empty($toTmpFile) ? null : escapeshellarg($tmpdir->GetDir() . $toTmpFile), $toName);
         if (!empty($fromTmpFile)) {
             $tmpdir->RemoveFile($fromTmpFile);
         }
         if (!empty($toTmpFile)) {
             $tmpdir->RemoveFile($toTmpFile);
         }
     }
     if ($explode) {
         return explode("\n", $this->diffData);
     } else {
         return $this->diffData;
     }
 }
Esempio n. 2
0
 /**
  * __construct
  *
  * Constructor
  *
  * @access public
  */
 public function __construct()
 {
     $this->dir = GitPHP_Util::AddSlash(GitPHP_Config::GetInstance()->GetValue('gittmp'));
     if (empty($this->dir)) {
         $this->dir = GitPHP_TmpDir::SystemTmpDir();
     }
     if (empty($this->dir)) {
         throw new Exception(__('No tmpdir defined'));
     }
     if (file_exists($this->dir)) {
         if (is_dir($this->dir)) {
             if (!is_writeable($this->dir)) {
                 throw new Exception(sprintf(__('Specified tmpdir %1$s is not writable'), $this->dir));
             }
         } else {
             throw new Exception(sprintf(__('Specified tmpdir %1$s is not a directory'), $this->dir));
         }
     } else {
         if (!mkdir($this->dir, 0700)) {
             throw new Exception(sprintf(__('Could not create tmpdir %1$s'), $this->dir));
         }
     }
 }