-<?php
-require_once 'Interface/CommitHookBridge.php';
-require_once 'Repo.php';
+<?php
+require_once 'MTrack/Interface/CommitHookBridge.php';
+require_once 'MTrack/Repo.php';
// needs to be run from git-recieve (and it has to be the only thing run.
class MTrack_SCM_Git_CommitHookBridge extends IMTrackCommitHookBridge
{
- static public $GIT;
+
var $repo;
+
var $files = array();
var $log = array();
var $commits = array();
var $fileActions = array(); // file=> delete / modify etc..
+
+
/**
* fills up repo, files, log, commits by running log on the STDIN
*/
-
-
- function __construct(MTrack_Repo $repo, $hooks)
+ function __construct($repo)
{
- self::$GIT = MTrackConfig::get('tools', 'git');
- $this->repo = $repo;
+ $this->repo = $repo->impl();
while (($line = fgets(STDIN)) !== false) {
-
- list($old, $new, $ref) = explode(' ', trim($line), 3);
- $this->commits[] = $new;
-
- $fp = $this->run(self::$GIT, 'log', '--no-color', '--name-status',
- '--date=rfc', $ref, "$old..$new");
-
-
- $props = array();
- $line = fgets($fp);
- if (!preg_match("/^commit\s+(\S+)$/", $line)) {
- throw new Exception("unexpected output from git log: $line");
- }
- // read key: value properties like Author: / Date:
- while (($line = fgets($fp)) !== false) {
- $line = rtrim($line);
- if (!strlen($line)) break;
- if (preg_match("/^(\S+):\s*(.*)\s*$/", $line, $M)) {
- $props[$M[1]] = $M[2];
+ echo "got: $line\n";
+ list($old, $new, $ref) = explode(' ', trim($line), 3);
+ $this->commits[] = $new;
+
+ $fp = $this->repo->git(
+ 'log', '--no-color', '--name-status',
+ '--date=rfc', "$old..$new"); //$ref, used to be in here?? - but it breaks stuff...
+
+
+ $props = array();
+ $line = fgets($fp);
+ if (!preg_match("/^commit\s+(\S+)$/", $line)) {
+ throw new Exception("unexpected output from git log: $line");
}
- }
- // read the commit log.
- while (($line = fgets($fp)) !== false) {
- $line = rtrim($line);
- if (strncmp($line, ' ', 4)) {
- break;
+
+ // read key: value properties like Author: / Date:
+ while (($line = fgets($fp)) !== false) {
+ $line = rtrim($line);
+ if (!strlen($line)) break;
+ if (preg_match("/^(\S+):\s*(.*)\s*$/", $line, $M)) {
+ $props[$M[1]] = $M[2];
+ }
}
- $this->log[] = substr($line, 4);
- }
-
-
- do {
- if (preg_match("/^(.+)\s+(\S+)\s*$/", $line, $M)) {
- $st = $M[1];
- $file = $M[2];
- $this->files[$file] = $new;
- $this->fileActions[$file] = $st;
+ // read the commit log.
+ while (($line = fgets($fp)) !== false) {
+ $line = rtrim($line);
+ if (strncmp($line, ' ', 4)) {
+ break;
+ }
+ $this->log[] = substr($line, 4);
}
- } while (($line = fgets($fp)) !== false);
+
+ do {
+ if (preg_match("/^(.+)\s+(\S+)\s*$/", $line, $M)) {
+ $st = $M[1];
+ $file = $M[2];
+ $this->files[$file] = $new;
+ $this->fileActions[$file] = $st;
+ }
+
+ } while (($line = fgets($fp)) !== false);
}
+ print_r($this);exit;
}
// There may be a better way...
// ls-tree to determine the hash of the file from this change:
- $fp = $this->run(self::$GIT, 'ls-tree', '-r', $rev, $path);
+ $fp = $this->repo->git( 'ls-tree', '-r', $rev, $path);
$line = fgets($fp);
$fp = null;
list($mode, $type, $hash, $name) = preg_split("/\s+/", $line);
// now we can cat that blob
- return $this->run(self::$GIT, 'cat-file', 'blob', $hash);
+ return $this->repo->git( 'cat-file', 'blob', $hash);
}
function getChangesetDescriptor()