1 var XObject = imports.XObject.XObject;
3 var GLib = imports.gi.GLib;
4 var File = imports.File.File;
5 // mix of SCM and Repo class from mtrack.
7 //var SCM = imports.SCM.SCM;
9 _abstract = function() {
10 throw "abstract function not implemented";
13 Repo = XObject.define(
16 if (typeof(cfg) != 'object') {
36 links_to_remove : false,
43 /** Returns an array keyed by possible branch names.
44 * The data associated with the branches is implementation
46 * If the SCM does not have a concept of first-class branch
47 * objects, this function returns null */
48 getBranches : _abstract,
50 /** Returns an array keyed by possible tag names.
51 * The data associated with the tags is implementation
53 * If the SCM does not have a concept of first-class tag
54 * objects, this function returns null */
57 /** Enumerates the files/dirs that are present in the specified
58 * location of the repository that match the specified revision,
59 * branch or tag information. If no revision, branch or tag is
60 * specified, then the appropriate default is assumed.
62 * The second and third parameters are optional; the second
63 * parameter is one of 'rev', 'branch', or 'tag', and if specifed
64 * the third parameter must be the corresponding revision, branch
67 * The return value is an array of MTrackSCMFile objects present
68 * at that location/revision of the repository.
72 /** Queries information on a specific file in the repository.
74 * Parameters are as for readdir() above.
76 * This function returns a single MTrackSCMFile for the location
81 /** Queries history for a particular location in the repo.
83 * Parameters are as for readdir() above, except that path can be
84 * left unspecified to query the history for the entire repo.
86 * The limit parameter limits the number of entries returned; it it is
87 * a number, it specifies the number of events, otherwise it is assumed
88 * to be a date in the past; only events since that date will be returned.
90 * Returns an array of MTrackSCMEvent objects.
94 /** Obtain the diff text representing a change to a file.
96 * You may optionally provide one or two revisions as context.
98 * If no revisions are passed in, then the change associated
99 * with the location will be assumed.
101 * If one revision is passed, then the change associated with
102 * that event will be assumed.
104 * If two revisions are passed, then the difference between
105 * the two events will be assumed.
109 /** Determine the next and previous revisions for a given
112 * Returns an array: the 0th element is an array of prior revisions,
113 * and the 1st element is an array of successor revisions.
115 * There will usually be one prior and one successor revision for a
116 * given change, but some SCMs will return multiples in the case of
119 getRelatedChanges : _abstract,
121 /** Returns a working copy object for the repo
123 * The intended purpose is to support wiki page modifications, and
124 * as such, is not meant to be an especially efficient means to do so.
126 getWorkingCopy : _abstract,
128 /** Returns meta information about the SCM type; this is used in the
129 * UI and tooling to let the user know their options.
131 * Returns an array with the following keys:
132 * 'name' => 'Mercurial', // human displayable name
133 * 'tools' => array('hg'), // list of tools to find during setup
135 getSCMMetaData : _abstract,
137 /** Returns the default 'root' location in the repository.
138 * For SCMs that have a concept of branches, this is the empty string.
139 * For SCMs like SVN, this is the trunk dir */
140 getDefaultRoot : function() {
147 /* takes an MTrackSCM as a parameter because in some bootstrapping
148 * cases, we're actually MTrack_Repo and not the end-class.
149 * MTrack_Repo calls the end-class method and passes itself in for
151 reconcileRepoSettings : _abstract,
156 getBrowseRootName : _abstract,
161 * @param {string} rev - a fixed revision - always returns this if it is not false;
162 * @param {string} object [rev|branch|tag]- object type
163 * @param {ident} object id (eg. rev nun, branch name, tag name)
167 resolveRevision :function(rev, object, ident)
173 if (object === false) {
184 // technically we should check it exists..
187 //var branches = this.getBranches();
188 // branches is now an array - not a map.
190 //rev = typeof(branches[ident]) == 'undefined' ? false : branches[ident];
194 tags = this.getTags();
195 rev = typeof(tags[ident]) == 'undefined' ? false : tags[ident];
199 throw "don't know which revision to use (rev,object,ident) got" + object;
207 function reconcileRepoSettings()
209 $c = self::Factory(array('scmtype'=>$this->scmtype));
210 $s->reconcileRepoSettings($this);
213 function getServerURL()
215 if ($this->serverurl) {
216 return $this->serverurl;
222 function getCheckoutCommand() {
223 $url = $this->getServerURL();
225 return $this->scmtype . ' clone ' . $this->getServerURL();
234 function getWorkingCopy() {
235 throw new Exception("cannot getWorkingCopy from a generic repo object");
238 function deleteRepo(MTrackChangeset $CS) {
239 MTrackDB::q('delete from repos where repoid = ?', $this->repoid);
240 mtrack_rmdir($this->repopath);
245 // these are needed just to implement the abstract interface..
246 function getBranches() {}
247 function getTags() {}
248 function readdir($path, $object = null, $ident = null) {}
249 function file($path, $object = null, $ident = null) {}
250 function history($path, $limit = null, $object = null, $ident = null){}
251 function diff($path, $from = null, $to = null) {}
252 function getRelatedChanges($revision) {}
253 function getSCMMetaData() { return null; }
255 * converts a commit log message (cached locally into a working object..)
259 function commitLogToEvent($str) {
260 throw new Exception("no implementation for commitLogToEvent");
268 static $scms = array();
269 static function factory($ar)
272 $type = ucfirst($ar['scmtype']);
273 $fn = 'MTrack/SCM/'.$type .'/Repo.php';
274 $cls = 'MTrack_SCM_'.$type .'_Repo';
277 $ret = new $cls($ar);
284 static function getAvailableSCMs()
287 $ar = scandir(dirname(__FILE__).'/SCM');
290 if (empty($a) || $a[0] == '.') {
293 $fn = dirname(__FILE__).'/SCM/'.$a.'/Repo.php';
294 if (!file_exists($fn)) {
297 $ret[$a] = MTrack_Repo::factory(array('scmtype'=> $a));
305 Repo.list = function()
308 if (Repo._list !== false) {
312 var dir = GLib.get_home_dir() + '/gitlive';
313 var ar = File.list(dir );
314 print(JSON.stringify(ar));
315 ar.forEach(function(f) {
316 if (File.exists(dir + '/' + f +'/.git')) {
317 Repo._list.push(new imports.Scm.Git.Repo.Repo( {
318 repopath : dir +'/' + f,
327 Repo.get = function(path_or_name)
329 var tr = Repo.list();
330 for (var i =0;i < tr.length; i++) {
331 if (tr[i].name == path_or_name) {
335 if (tr[i].repopath == path_or_name) {