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 /** when this revision was committed */
20 /** files affected in this event; may be null, but otherwise
21 * will be an array of MTrackSCMFileEvent */
26 * this is based on the output from git --raw --numstat
28 static function newFromCommit($commit, $repo)
31 $ent = new MTrack_SCM_Git_Event;
32 $ent->commit = $commit;
34 $lines = explode("\n", $commit);
35 $line = array_shift($lines);
37 if (!preg_match("/^commit\s+(\S+)$/", $line, $M)) {
42 $ent->branches = array(); // FIXME
43 $ent->tags = array(); // FIXME
44 $ent->files = array();
46 while (count($lines)) {
47 $line = array_shift($lines);
51 if (preg_match("/^(\S+):\s+(.*)\s*$/", $line, $M)) {
61 $ent->ctime = MTrackDB::unixtime($ts);
69 if ($lines[0] == '') {
73 while (count($lines)) {
74 $line = array_shift($lines);
75 if (strncmp($line, ' ', 4)) {
76 array_unshift($lines, $line);
79 $line = substr($line, 4);
80 $ent->changelog .= $line . "\n";
83 if ($lines[0] == '') {
86 // this should only be the last set of lines..
88 foreach ($lines as $line) {
93 if (preg_match('#^:#', $line)) {
94 // it's our stat line..:
95 // :100755 100755 fde93abd1a71accd3aa7e97b29c1eecfb43095d7
96 // 3d71edf6512035846d8164c3b28818de0062335a M web/MTrackWeb/DataObjects/Changes.php
97 $info = preg_split('#\s+#', substr($line ,1), 6);
99 $f = new MTrackSCMFileEvent; //generic..
101 $f->oldperm = $info[0];
102 $f->newperm = $info[1];
103 $f->oldver = $info[2];
104 $f->newver = $info[3];
105 $f->status = $info[4];
106 $ent->files[$f->name] = $f;
110 $info = preg_split('#\s+#', substr($line ,1), 3);
113 $ent->files[$name]->added = $info[0];
114 $ent->files[$name]->removed = $info[1];
118 if (!count($ent->branches)) {
119 $ent->branches[] = 'master';
121 $ent->files_array = array_values($ent->files);