3 require_once 'MTrack/SCMEvent.php';
4 class MTrack_SCM_Git_Event extends MTrackSCMEvent
8 /** Revision or changeset identifier for this particular file */
11 /** commit message associated with this revision */
14 /** who committed this revision */
17 /** branch for this revision */
19 /** when this revision was committed */
22 /** files affected in this event; may be null, but otherwise
23 * will be an array of MTrackSCMFileEvent */
28 * this is based on the output from git --raw --numstat
30 static function newFromCommit($commit, $repo)
33 $ent = new MTrack_SCM_Git_Event;
34 $ent->commit = $commit;
36 $lines = explode("\n", $commit);
37 $line = array_shift($lines);
39 if (!preg_match("/^commit\s+(\S+)\s+(\S+)$/", $line, $M)) {
43 $ent->branch = $M[2] ;
44 $ent->tags = array(); // FIXME
45 $ent->files = array();
47 while (count($lines)) {
48 $line = array_shift($lines);
52 if (preg_match("/^(\S+):\s+(.*)\s*$/", $line, $M)) {
62 $ent->ctime = MTrackDB::unixtime($ts);
70 if ($lines[0] == '') {
74 while (count($lines)) {
75 $line = array_shift($lines);
76 if (strncmp($line, ' ', 4)) {
77 array_unshift($lines, $line);
80 $line = substr($line, 4);
81 $ent->changelog .= $line . "\n";
84 if ($lines[0] == '') {
87 // this should only be the last set of lines..
89 foreach ($lines as $line) {
94 if (preg_match('#^:#', $line)) {
95 // it's our stat line..:
96 // :100755 100755 fde93abd1a71accd3aa7e97b29c1eecfb43095d7
97 // 3d71edf6512035846d8164c3b28818de0062335a M web/MTrackWeb/DataObjects/Changes.php
98 $info = preg_split('#\s+#', substr($line ,1), 6);
100 $f = new MTrackSCMFileEvent; //generic..
102 $f->oldperm = $info[0];
103 $f->newperm = $info[1];
104 $f->oldver = $info[2];
105 $f->newver = $info[3];
106 $f->status = $info[4];
107 $ent->files[$f->name] = $f;
111 $info = preg_split('#\s+#', substr($line ,1), 3);
114 if (!isset($ent->files[$name])) {
115 $ent->files[$name] = new stdClass; // ??
118 $ent->files[$name]->added = $info[0];
119 $ent->files[$name]->removed = $info[1];
122 //if (!count($ent->branches)) {
123 // $ent->branches[] = $this->branch; //'master';
125 $ent->files_array = array_values($ent->files);