4 // needs to be run from git-recieve (and it has to be the only thing run.
6 class MTrackWeb_Hook_Git_Bridge extends MTrackWeb_Hook_Bridge
13 var $commits = array();
14 var $fileActions = array(); // file=> delete / modify etc..
17 * fills up repo, files, log, commits by running log on the STDIN
19 function __construct($repo)
26 while (($line = fgets(STDIN)) !== false) {
28 list($old, $new, $ref) = explode(' ', trim($line), 3);
29 $this->commits[] = $new;
31 $fp = $this->repo->impl()->git('log', '--no-color', '--name-status',
32 '--date=rfc', $ref, "$old..$new");
37 if (!preg_match("/^commit\s+(\S+)$/", $line)) {
38 throw new Exception("unexpected output from git log: $line");
40 // read key: value properties like Author: / Date:
41 while (($line = fgets($fp)) !== false) {
43 if (!strlen($line)) break;
44 if (preg_match("/^(\S+):\s*(.*)\s*$/", $line, $M)) {
45 $props[$M[1]] = $M[2];
48 // read the commit log.
49 while (($line = fgets($fp)) !== false) {
51 if (strncmp($line, ' ', 4)) {
54 $this->log[] = substr($line, 4);
59 if (preg_match("/^(.+)\s+(\S+)\s*$/", $line, $M)) {
62 $this->files[$file] = $new;
63 $this->fileActions[$file] = $st;
66 } while (($line = fgets($fp)) !== false);
71 function enumChangedOrModifiedFileNames()
74 foreach($this->files as $f=>$com) {
75 if ($this->fileActions[$f] == 'D') {
83 function getCommitMessage()
85 $log = join("\n", $this->log);
86 $log = preg_replace('/\[([a-fA-F0-9]+)\]/',
87 "[changeset:" . $this->repo->getBrowseRootName() . ",\$1]", $log);
91 function getFileStream($path)
93 $rev = $this->files[$path];
95 // There may be a better way...
96 // ls-tree to determine the hash of the file from this change:
97 $fp = $this->repo->impl()->git('ls-tree', '-r', $rev, $path);
100 list($mode, $type, $hash, $name) = preg_split("/\s+/", $line);
101 // now we can cat that blob
102 return $this->repo->impl()->git('cat-file', 'blob', $hash);
105 function getChangesetDescriptor()
108 foreach ($this->commits as $ref) {
109 $cs[] = '[changeset:' . $this->repo->getBrowseRootName() . ",$ref]";
111 return join(", ", $cs);