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 */
36 * this is based on the output from git --raw --numstat
38 static function newFromCommit($commit, $repo)
41 $ent = new MTrack_SCM_Git_Event;
42 $ent->commit = $commit;
44 $lines = explode("\n", $commit);
45 $line = array_shift($lines);
47 if (!preg_match("/^commit\s+(\S+)\s+(\S+)$/", $line, $M)) {
51 $ent->branch = $M[2] ;
52 $ent->tags = array(); // FIXME
53 $ent->files = array();
55 while (count($lines)) {
56 $line = array_shift($lines);
60 if (preg_match("/^(\S+):\s+(.*)\s*$/", $line, $M)) {
70 $ent->ctime = MTrackDB::unixtime($ts);
78 if ($lines[0] == '') {
82 while (count($lines)) {
83 $line = array_shift($lines);
84 if (strncmp($line, ' ', 4)) {
85 array_unshift($lines, $line);
88 $line = substr($line, 4);
89 $ent->changelog .= $line . "\n";
92 if ($lines[0] == '') {
95 // this should only be the last set of lines..
97 foreach ($lines as $line) {
102 if (preg_match('#^:#', $line)) {
103 // it's our stat line..:
104 // :100755 100755 fde93abd1a71accd3aa7e97b29c1eecfb43095d7
105 // 3d71edf6512035846d8164c3b28818de0062335a M web/MTrackWeb/DataObjects/Changes.php
106 $info = preg_split('#\s+#', substr($line ,1), 6);
108 $f = new MTrackSCMFileEvent; //generic..
110 $f->oldperm = $info[0];
111 $f->newperm = $info[1];
112 $f->oldver = $info[2];
113 $f->newver = $info[3];
114 $f->status = $info[4];
115 $ent->files[$f->name] = $f;
119 $info = preg_split('#\s+#', substr($line ,1), 3);
122 if (!isset($ent->files[$name])) {
123 $ent->files[$name] = new stdClass; // ??
126 $ent->files[$name]->added = $info[0];
127 $ent->files[$name]->removed = $info[1];
130 //if (!count($ent->branches)) {
131 // $ent->branches[] = $this->branch; //'master';
133 $ent->files_array = array_values($ent->files);