Exemple #1
0
 /**
  * Diff
  *
  * Convenience function to run diff with the default settings
  * and immediately discard the object
  *
  * @access public
  * @static
  * @param string $fromFile source file
  * @param string $fromName source file display name
  * @param string $toFile destination file
  * @param string $toName destination file display name
  * @return string diff output
  */
 public static function Diff($fromFile = null, $fromName = null, $toFile = null, $toName = null)
 {
     $obj = new GitPHP_DiffExe();
     $ret = $obj->Execute($fromFile, $fromName, $toFile, $toName);
     unset($obj);
     return $ret;
 }
 /**
  * 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;
     }
 }