From 7a20231fc7065ea9f409b1d6b77d8db016bbe51f Mon Sep 17 00:00:00 2001 From: James Date: Tue, 13 Dec 2011 23:08:58 +0000 Subject: [PATCH] First working commit of searching a local Git repository --- src/ReadGit.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/ReadGit.php b/src/ReadGit.php index de80de8..4291a8c 100644 --- a/src/ReadGit.php +++ b/src/ReadGit.php @@ -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); + } + } }