require_once 'MTrack/Config.php';
require_once 'MTrack/Project.php';
require_once 'MTrack/SCMFileEvent.php';
-require_once 'MTrack/ACL.php';
-require_once 'MTrack/Changeset.php';
-require_once 'MTrack/Wiki.php';
+ //require_once 'MTrack/Changeset.php';
+//require_once 'MTrack/Wiki.php';
class MTrack_Repo extends MTrackSCM
{
- public $repoid = null;
+ public $id = null;
public $shortname = null;
public $scmtype = null;
public $repopath = null;
static function factory($ar)
{
- print_r($ar);
+ //print_r($ar);
$type = ucfirst($ar['scmtype']);
$fn = 'MTrack/SCM/'.$type .'/Repo.php';
$cls = 'MTrack_SCM_'.$type .'_Repo';
}
return $ret;
}
-
-
- /*static function loadById($id) {
- list($row) = MTrackDB::q(
- 'select repoid, scmtype from repos where repoid = ?',
- $id)->fetchAll();
- if (isset($row[0])) {
- $type = $row[1];
- if (isset(self::$scms[$type])) {
- $class = self::$scms[$type];
- return new $class($row[0]);
- }
- throw new Exception("unsupported repo type $type");
- }
- return null;
- }
- static function loadByName($name) {
- $bits = explode('/', $name);
- if (count($bits) > 1 && $bits[0] == 'default') {
- array_shift($bits);
- $name = $bits[0];
- }
- if (count($bits) > 1) {
- // wez/reponame -> per user repo
- $u = "user:$bits[0]";
- $p = "project:$bits[0]";
- $rows = MTrackDB::q(
- 'select repoid, scmtype from repos where shortname = ? and (parent = ? OR parent = ?)',
- $bits[1], $u, $p)->fetchAll();
- } else {
- $rows = MTrackDB::q(
- "select repoid, scmtype from repos where shortname = ? and parent =''",
- $name)->fetchAll();
- }
- if (is_array($rows) && isset($rows[0])) {
- $row = $rows[0];
- if (isset($row[0])) {
- $type = $row[1];
- if (isset(self::$scms[$type])) {
- $class = self::$scms[$type];
- return new $class($row[0]);
- }
- throw new Exception("unsupported repo type $type");
- }
- }
- return null;
- }
- static function loadByLocation($path)
- {
-
- // we have magic configuration - end users commit into SVN
- // backend is really git... - so pre-commit hooks have to be from svn
- list($row) = MTrackDB::q('select repoid, scmtype from repos where repopath = ?', $path)->fetchAll();
- if (isset($row[0])) {
- $type = $row[1];
- if (isset(self::$scms[$type])) {
- $class = self::$scms[$type];
- return new $class($row[0]);
- }
- throw new Exception("unsupported repo type $type");
- }
- return null;
- }
-
- static function loadByChangeSet($cs)
- {
-
- static $re = array();
- if (isset($re[$cs])) {
- return $re[$cs];
- }
- //using (repoid) ??
- $q = MTrackDB::q("
- select
- r.shortname as repo,
- p.shortname as proj
- from
- repos r
- left join
- project_repo_link l on r.repoid = l.repoid
- left join
- projects p on p.projid = r.projectid
- where
- (parent is null or length(parent) = 0)
- AND
- (
- ( ? like CONCAT(proj), '%')
- OR
- ( ? like CONCAT(repo), '%')
- )
- ");
- $ar = $q->fetchAll(PDO::FETCH_ASSOC);
- if ($ar) {
- $re[$cs] = self::loadByName($ar['repo']);
- return $re[$cs];
- }
- $re[$cs] = false;
- return $re[$cs];
- }
- */
- // methods
-
+
function __construct($ar = null) {
if (!is_array($ar)) {
function diff($path, $from = null, $to = null) {}
function getRelatedChanges($revision) {}
function getSCMMetaData() { return null; }
-
-/* -- where is this used?
-
- function projectFromPath($filename)
- {
- static $links = array();
- if (!isset($links[$this->repoid]) || $links[$this->repoid] === null) {
- $links[$this->repoid] = array();
- foreach (MTrackDB::q(
- 'select projid, repopathregex from project_repo_link where repoid = ?',
- $this->repoid) as $row) {
- $re = str_replace('/', '\\/', $row[1]);
- $links[$this->repoid][] = array($row[0], "/$re/");
- }
- }
- if (is_array($filename)) {
- $proj_incidence = array();
- foreach ($filename as $file) {
- $proj = $this->projectFromPath($file);
- if ($proj === null) continue;
- if (isset($proj_incidence[$proj])) {
- $proj_incidence[$proj]++;
- } else {
- $proj_incidence[$proj] = 1;
- }
- }
- $the_proj = null;
- $the_proj_count = 0;
- foreach ($proj_incidence as $proj => $count) {
- if ($count > $the_proj_count) {
- $the_proj_count = $count;
- $the_proj = $proj;
- }
- }
- return $the_proj;
- }
-
- if ($filename instanceof MTrackSCMFileEvent) {
- $filename = $filename->name;
- }
-
- // walk through the regexes; take the longest match as definitive
- $longest = null;
- $longest_id = null;
- if ($filename[0] != '/') {
- $filename = '/' . $filename;
- }
- foreach ($links[$this->repoid] as $link) {
- if (preg_match($link[1], $filename, $M)) {
- if (strlen($M[0]) > strlen($longest)) {
- $longest = $M[0];
- $longest_id = $link[0];
- }
- }
- }
- return $longest_id;
- }
- */
- function historyWithChangelog($path, $limit = null, $object = null, $ident = null)
- {
-
- $ents = $this->history($path, $limit, $object, $ident);
- $data = new StdClass;
- if (!count($ents)) {
- $data->ent = null;
- return $data;
- }
- $ent = $ents[0];
- $data->ent = $ent;
-
- // Determine project from the file list
- $the_proj = $this->projectFromPath($ent->files);
- if ($the_proj > 1) {
- $proj = MTrackProject::loadById($the_proj);
- $changelog = $proj->adjust_links($ent->changelog, true);
- } else {
- $changelog = $ent->changelog;
- }
- $data->changelog = $changelog;
-
- //if (is_array($ent->files)) foreach ($ent->files as $file) {
- // $file->diff = mtrack_diff($repo->diff($file, $ent->rev));
- //}
-
-
- return $data;
- }
- function historyWithChangelogAndDiff($path, $limit = null, $object = null, $ident = null)
- {
- $ret = $this->historyWithChangelog($path, $limit, $object, $ident);
- if (!$ret->ent) {
- return $ret;
- }
- if (!is_array($ret->ent->files)) {
- return $ret;
- }
- foreach ($ret->ent->files as $file) {
- // where is mtrack_diff...
- $file->diff = mtrack_diff($this->diff($file, $ret->ent->rev));
- }
-
-
- return $data;
- }
- // rendering..
-
- function displayName()
- {
- // fixme - this code needs to be in here.. rather than in SCM?
- return MTrackSCM::makeDisplayName($this);
- }
- function descriptionToHtml()
- {
- return MTrack_Wiki::format_to_html($this->description);
- }
-
- static function defaultRepo($cfg = null)
- {
- static $defrepo = null;
- if ($defrepo !== null) {
- return $defrepo; // already to it..
- }
-
- $defrepo = $cfg;
- if ($defrepo !== null) {
- $defrepo = strpos($defrepo, '/') === false ? 'default/' . $defrepo : $defrepo;
- return $defrepo;
- }
-
- $defrepo = '';
- $q = MTrackDB::q( 'select parent, shortname from repos order by shortname');
- foreach($q->fetchAll() as $row) {
- $defrepo = MTrackSCM::makeDisplayName($row);
- return $defrepo;
- }
- return '';
-
+ /**
+ * converts a commit log message (cached locally into a working object..)
+ * see Browse.php
+ */
+ function commitLogToEvent($str) {
+ throw new Exception("no implementation for commitLogToEvent");
}
-
}