/**
  * Execute rev-list command
  *
  * @param GitPHP_Project $project project
  * @param string $hash hash to look back from
  * @param int $count number to return (0 for all)
  * @param int $skip number of items to skip
  * @param array $args extra arguments
  */
 public function RevList($project, $hash, $count, $skip = 0, $args = array())
 {
     if (!$project || empty($hash)) {
         return;
     }
     $canSkip = true;
     if ($skip > 0) {
         $canSkip = $this->exe->CanSkip();
     }
     $extraargs = array();
     if ($canSkip) {
         if ($count > 0) {
             $extraargs[] = '--max-count=' . $count;
         }
         if ($skip > 0) {
             $extraargs[] = '--skip=' . $skip;
         }
     } else {
         if ($count > 0) {
             $extraargs[] = '--max-count=' . ($count + $skip);
         }
     }
     $extraargs[] = $hash;
     if (count($args) > 0) {
         $endarg = array_search('--', $args);
         if ($endarg !== false) {
             array_splice($args, $endarg, 0, $extraargs);
         } else {
             $args = array_merge($args, $extraargs);
         }
     } else {
         $args = $extraargs;
     }
     $revlist = explode("\n", $this->exe->Execute($project->GetPath(), GIT_REV_LIST, $args));
     if (!$revlist[count($revlist) - 1]) {
         /* the last newline creates a null entry */
         array_splice($revlist, -1, 1);
     }
     if ($skip > 0 && !$canSkip) {
         if ($count > 0) {
             return array_slice($revlist, $skip, $count);
         } else {
             return array_slice($revlist, $skip);
         }
     }
     return $revlist;
 }
 /**
  * Loads the history data
  */
 protected function LoadData()
 {
     $this->dataLoaded = true;
     $args = array();
     $args[] = $this->hash;
     $args[] = '--no-merges';
     $canSkip = true;
     if ($this->skip > 0) {
         $canSkip = $this->exe->CanSkip();
     }
     if ($canSkip) {
         if ($this->limit > 0) {
             $args[] = '--max-count=' . $this->limit;
         }
         if ($this->skip > 0) {
             $args[] = '--skip=' . $this->skip;
         }
     } else {
         if ($this->limit > 0) {
             $args[] = '--max-count=' . ($this->limit + $this->skip);
         }
     }
     $args[] = '--';
     $args[] = $this->path;
     $args[] = '|';
     $args[] = $this->exe->GetBinary();
     $args[] = '--git-dir=' . escapeshellarg($this->project->GetPath());
     $args[] = GIT_DIFF_TREE;
     $args[] = '-r';
     $args[] = '--stdin';
     $args[] = '--';
     $args[] = $this->path;
     $historylines = explode("\n", $this->exe->Execute($this->project->GetPath(), GIT_REV_LIST, $args));
     $commitHash = null;
     foreach ($historylines as $line) {
         if (preg_match('/^([0-9a-fA-F]{40})/', $line, $regs)) {
             $commitHash = $regs[1];
         } else {
             if ($commitHash) {
                 try {
                     $this->history[] = array('diffline' => $line, 'commithash' => $commitHash);
                 } catch (Exception $e) {
                 }
                 $commitHash = null;
             }
         }
     }
     if ($this->skip > 0 && !$canSkip) {
         if ($this->limit > 0) {
             $this->history = array_slice($this->history, $this->skip, $this->limit);
         } else {
             $this->history = array_slice($this->history, $this->skip);
         }
     }
 }
Exemple #3
0
 /**
  * RevList
  *
  * Common code for using rev-list command
  *
  * @access private
  * @param string $hash hash to list from
  * @param integer $count number of results to get
  * @param integer $skip number of results to skip
  * @param array $args args to give to rev-list
  * @return array array of hashes
  */
 private function RevList($hash, $count = 50, $skip = 0, $args = array())
 {
     if ($count < 1) {
         return;
     }
     $exe = new GitPHP_GitExe($this);
     $canSkip = true;
     if ($skip > 0) {
         $canSkip = $exe->CanSkip();
     }
     if ($canSkip) {
         $args[] = '--max-count=' . $count;
         if ($skip > 0) {
             $args[] = '--skip=' . $skip;
         }
     } else {
         $args[] = '--max-count=' . ($count + $skip);
     }
     $args[] = $hash;
     $revlist = explode("\n", $exe->Execute(GIT_REV_LIST, $args));
     if (!$revlist[count($revlist) - 1]) {
         /* the last newline creates a null entry */
         array_splice($revlist, -1, 1);
     }
     if ($skip > 0 && !$exe->CanSkip()) {
         return array_slice($revlist, $skip, $count);
     }
     return $revlist;
 }