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
30 need to work out a 'sweet caching method'...
32 // var_Dump($this->id);
33 $q = MTrackDB::q('SELECT * FROM clcache where
34 id = ? AND rev = ?' , $this->repo->id, $this->hash );
36 $ar = $q->fetchAll(PDO::FETCH_ASSOC);
38 require_once 'MTrack/SCM/Git/Event.php';
39 $ro = MTrack_SCM_Git_Event::newFromCommit($ar[0]['sobject'], $this->repo);
40 // var_dump("RETURNING FROM DB");
45 $ent = $this->repo->history($this->name, 1, 'rev', $this->rev);
50 MTrackDB::q('INSERT INTO mtrack_clcache (id, rev, sobject) VALUES ( ? ,? ,? )',
51 $this->repo->id, $this->hash , $ent[0]->commit
58 return $ent ? $ent[0] : false;
63 // There may be a better way...
64 // ls-tree to determine the hash of the file from this change:
65 $fp = $this->repo->git('ls-tree', $this->rev, $this->name);
69 list($mode, $type, $hash, $name) = preg_split("/\s+/", $line);
71 // now we can cat that blob
72 return $this->repo->git('cat-file', 'blob', $hash);
75 function annotate($include_line_content = false)
77 /*if ($this->repo->gitdir == $this->repo->repopath) {
78 // For bare repos, we can't run annotate, so we need to make a clone
79 // with a work tree. This relies on local clones being a cheap operation
81 $wc = new MTrackWCGit($this->repo);
84 $fp = $wc->git('annotate', '-p', $this->rev, '--', $this->name,);
89 $fp = $this->repo->git('annotate', '-p', $this->rev, '--', $this->name);
95 while ($line = fgets($fp)) {
96 // echo htmlentities($line), "<br>\n";
97 if (!strncmp($line, "\t", 1)) {
98 $A = new MTrackSCMAnnotation;
100 $A->repo = $this->repo;
101 if (isset($meta['author-mail']) &&
102 strpos($meta['author-mail'], '@')
104 $A->changeby = $meta['author'] . ' ' . $meta['author-mail'];
106 $A->changeby = $meta['author'];
108 $A->rev = $meta['rev'];
109 if ($include_line_content) {
110 $A->line = substr($line, 1);
115 if (preg_match("/^([a-f0-9]+)\s[a-f0-9]+\s[a-f0-9]+\s[a-f0-9]+$/", $line, $M)) {
116 $meta['rev'] = $M[1];
117 } else if (preg_match("/^(\S+)\s*(.*)$/", $line, $M)) {
120 $meta[$name] = $value;