Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add better method for getting branch commits, fix underscore stuff

  • Loading branch information...
commit 2b10fdee5c23f01ae3611f786db8bd7ecdee5f55 1 parent 4462e63
@EvanDotPro authored
Showing with 34 additions and 3 deletions.
  1. +1 −1  src/EdpGit/Commit.php
  2. +33 −2 src/EdpGit/Repo.php
View
2  src/EdpGit/Commit.php
@@ -1,5 +1,5 @@
<?php
-namespace Git;
+namespace EdpGit;
use DateTime;
class Commit
{
View
35 src/EdpGit/Repo.php
@@ -27,7 +27,6 @@ class Repo
public function __construct($parser, $cache = false)
{
$this->setParser($parser);
- $this->setCache($cache);
}
/**
@@ -106,10 +105,42 @@ public function getCommitsByBranch($limit = 5, $extra = '', $excludeRemotes = ar
return $this->commitsByBranch;
}
+ public function getBranchCommits($branch)
+ {
+ $commits = explode("\n", $this->getParser()->run('rev-list ^master ' . $branch));
+ $firstCommit = array_shift($commits);
+ $lastCommit = array_pop($commits);
+
+ $commits = $this->getParser()->run('log --pretty=format:\'</files>%n</commit>%n<commit>%n<json>%n{%n "commit": "%H",%n "tree": "%T",%n "parent": "%P",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "date": "%ai"%n },%n "committer": {%n "name": "%cN",%n "email": "%cE",%n "date": "%ci"%n }%n}%n</json>%n<message><![CDATA[%B]]></message>%n<files>\' --numstat ' . $firstCommit . '...' . $lastCommit);
+ $return = array();
+ $commits = simplexml_load_string('<commits>'.substr($commits,18).'</files></commit></commits>');
+ foreach ($commits->commit as $log) {
+ $details = json_decode($log->json);
+ $hash = (string)$details->commit;
+ if (!$this->getCommit($hash)) {
+ $commit = new Commit;
+ $commit->setHash($hash);
+ $commit->setTree((string)$details->tree);
+ $commit->setParents(explode(' ', $details->parent));
+ $commit->setAuthorName((string)$details->author->name);
+ $commit->setAuthorEmail((string)$details->author->email);
+ $commit->setAuthorTime((string)$details->author->date);
+ $commit->setCommitterName((string)$details->committer->name);
+ $commit->setCommitterEmail((string)$details->committer->email);
+ $commit->setCommitterTime((string)$details->committer->date);
+ $commit->setMessage((string)$log->message);
+ $commit->setFiles($this->parseFiles((string)$log->files));
+ $return[] = $commit;
+ $this->setCommit($commit->getHash(), $commit);
+ }
+ }
+ return $return;
+ }
+
protected function parseFiles($files)
{
$pattern = '/\s*(?P<insertions>\d+)\s(?P<deletions>\d+)\s+(?P<file>[^\s]+)/';
- pregmatchall($pattern, $files, $matches, PREGSETORDER);
+ preg_match_all($pattern, $files, $matches, PREG_SET_ORDER);
return $matches;
}
Please sign in to comment.
Something went wrong with that request. Please try again.