/** * Retrieves the commits since the given revision and populates a set of Commit Models. * * By default the commit models are not saved unless the $save parameter is set to true. * * @param mixed $since the revision where to start retrieving objects * @param boolean $save * * @return array of Commit objects */ public function getCommits($since = null, $save = false) { // first, load the most recent version $this->pull(); // retrieve commits if (!is_null($since)) { $parameters = array($since . '..'); } else { $parameters = array(); } $cwd = getcwd(); chdir($this->getLocalRepoPath()); $content = $this->execute('log', $parameters, array('raw' => '')); chdir($cwd); $changes = $this->parseGitLogRawOutput($content); // generate commit objects with changes $commits = array(); foreach ($changes as $revision => $change) { $commit = new Commit(); $commit->setRevision($revision); $commit->setScmId($this->getScm()->getId()); $commit->setAuthor($change['author']); $commit->setTimestamp(date("Y-m-d H:i:s", strtotime($change['timestamp']))); $commit->setMessage($change['message']); foreach ($change['filechanges'] as $path => $action) { $change = new FileChange(); $change->setCommit($commit); $change->setFilePath($path); switch ($action) { case 'A': $change->setFileChangeTypeId(1); break; case 'M': $change->setFileChangeTypeId(2); break; case 'D': $change->setFileChangeTypeId(3); break; default: $change->setFileChangeTypeId(4); break; } $commit->getFileChange()->add($change); } if ($save) { $commit->save(); } echo '.'; $commits[] = $commit; } return $commits; }