Skip to content

Commit

Permalink
First working commit of searching a local Git repository
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofgreen committed Dec 13, 2011
1 parent 91cd673 commit 7a20231
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/ReadGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,70 @@ class GitCommitAction extends CoderAction {

class ReadGit extends BaseReadClass {

protected $directory;

protected $authors;

public function __construct($configData = array()) {
if (get_class($configData) == 'DOMElement') {
$this->directory = $configData->getAttribute('Directory');
$list = $configData->getElementsByTagName('Author');
if ($list->length > 0) {
$this->authors = array();
for($pos=0; $pos<$list->length ; $pos++) {
$this->authors[] = $list->item($pos)->getAttribute('Email');
}
}
}
parent::__construct($configData);
}

public function process() {

$commits = array();

################# Find all commits
$out = array();
exec("cd ".$this->directory."; git branch", $out);

foreach($out as $line) {
$line = trim($line);
if (substr($line,0,1) == '*') $line = substr($line, 1);

$log = array();
exec("cd ".$this->directory."; git log ".$line, $log);

$lastCommit = $lastEmail = $lastDate = null;

foreach($log as $logLine) {
if (substr($logLine,0,7) == 'commit ') {
if ($lastCommit && $lastDate && $lastEmail) {
$commits[$lastCommit] = array('date'=>$lastDate,'email'=>$lastEmail);
}
$lastCommit = trim(substr($logLine, 8));
} else if (substr($logLine,0,7) == 'Author:') {
$bits = explode('<', $logLine);
$bits = explode('>', $bits[1]);
$lastEmail = $bits[0];
} else if (substr($logLine,0,5) == 'Date:') {
$lastDate = substr($logLine,5);
}

}

}

//var_dump($commits);

######### now push commits to data manager

foreach($commits as $commit) {
if (in_array($commit['email'], $this->authors)) {
$data = new GitCommitAction();
$data->setDateTime(new DateTime($commit['date']));
$this->dataManager->addData($data);
}
}

}

Expand Down

0 comments on commit 7a20231

Please sign in to comment.