1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
5 require_once 'MTrack/SCMFile.php';
6 require_once 'MTrack/SCMAnnotation.php';
8 class MTrack_SCM_Git_File extends MTrackSCMFile
16 function __construct(MTrackSCM $repo, $name, $rev, $is_dir = false, $hash=false)
21 $this->is_dir = $is_dir;
25 public function getChangeEvent() // returns MTrackSCMEvent
28 // var_Dump($this->repoid);
29 $q = MTrackDB::q('SELECT * FROM clcache where
30 repoid = ? AND rev = ?' , $this->repo->repoid, $this->hash );
32 $ar = $q->fetchAll(PDO::FETCH_ASSOC);
34 require_once 'MTrack/SCM/Git/Event.php';
35 $ro = MTrack_SCM_Git_Event::newFromCommit($ar[0]['sobject'], $this->repo);
36 // var_dump("RETURNING FROM DB");
40 $ent = $this->repo->history($this->name, 1, 'rev', $this->rev);
43 MTrackDB::q('INSERT INTO clcache (repoid, rev, sobject) VALUES ( ? ,? ,? )',
44 $this->repo->repoid, $this->hash , $ent[0]->commit
51 return $ent ? $ent[0] : false;
56 // There may be a better way...
57 // ls-tree to determine the hash of the file from this change:
58 $fp = $this->repo->git('ls-tree', $this->rev, $this->name);
61 list($mode, $type, $hash, $name) = preg_split("/\s+/", $line);
63 // now we can cat that blob
64 return $this->repo->git('cat-file', 'blob', $hash);
67 function annotate($include_line_content = false)
69 /*if ($this->repo->gitdir == $this->repo->repopath) {
70 // For bare repos, we can't run annotate, so we need to make a clone
71 // with a work tree. This relies on local clones being a cheap operation
73 $wc = new MTrackWCGit($this->repo);
76 $fp = $wc->git('annotate', '-p', $this->rev, '--', $this->name,);
81 $fp = $this->repo->git('annotate', '-p', $this->rev, '--', $this->name);
87 while ($line = fgets($fp)) {
88 // echo htmlentities($line), "<br>\n";
89 if (!strncmp($line, "\t", 1)) {
90 $A = new MTrackSCMAnnotation;
92 $A->repo = $this->repo;
93 if (isset($meta['author-mail']) &&
94 strpos($meta['author-mail'], '@')
96 $A->changeby = $meta['author'] . ' ' . $meta['author-mail'];
98 $A->changeby = $meta['author'];
100 $A->rev = $meta['rev'];
101 if ($include_line_content) {
102 $A->line = substr($line, 1);
107 if (preg_match("/^([a-f0-9]+)\s[a-f0-9]+\s[a-f0-9]+\s[a-f0-9]+$/", $line, $M)) {
108 $meta['rev'] = $M[1];
109 } else if (preg_match("/^(\S+)\s*(.*)$/", $line, $M)) {
112 $meta[$name] = $value;