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') {
37 links_to_remove : false,
44 /** Returns an array keyed by possible branch names.
45 * The data associated with the branches is implementation
47 * If the SCM does not have a concept of first-class branch
48 * objects, this function returns null */
49 getBranches : _abstract,
51 /** Returns an array keyed by possible tag names.
52 * The data associated with the tags is implementation
54 * If the SCM does not have a concept of first-class tag
55 * objects, this function returns null */
58 /** Enumerates the files/dirs that are present in the specified
59 * location of the repository that match the specified revision,
60 * branch or tag information. If no revision, branch or tag is
61 * specified, then the appropriate default is assumed.
63 * The second and third parameters are optional; the second
64 * parameter is one of 'rev', 'branch', or 'tag', and if specifed
65 * the third parameter must be the corresponding revision, branch
68 * The return value is an array of MTrackSCMFile objects present
69 * at that location/revision of the repository.
73 /** Queries information on a specific file in the repository.
75 * Parameters are as for readdir() above.
77 * This function returns a single MTrackSCMFile for the location
82 /** Queries history for a particular location in the repo.
84 * Parameters are as for readdir() above, except that path can be
85 * left unspecified to query the history for the entire repo.
87 * The limit parameter limits the number of entries returned; it it is
88 * a number, it specifies the number of events, otherwise it is assumed
89 * to be a date in the past; only events since that date will be returned.
91 * Returns an array of MTrackSCMEvent objects.
95 /** Obtain the diff text representing a change to a file.
97 * You may optionally provide one or two revisions as context.
99 * If no revisions are passed in, then the change associated
100 * with the location will be assumed.
102 * If one revision is passed, then the change associated with
103 * that event will be assumed.
105 * If two revisions are passed, then the difference between
106 * the two events will be assumed.
110 /** Determine the next and previous revisions for a given
113 * Returns an array: the 0th element is an array of prior revisions,
114 * and the 1st element is an array of successor revisions.
116 * There will usually be one prior and one successor revision for a
117 * given change, but some SCMs will return multiples in the case of
120 getRelatedChanges : _abstract,
122 /** Returns a working copy object for the repo
124 * The intended purpose is to support wiki page modifications, and
125 * as such, is not meant to be an especially efficient means to do so.
127 getWorkingCopy : _abstract,
129 /** Returns meta information about the SCM type; this is used in the
130 * UI and tooling to let the user know their options.
132 * Returns an array with the following keys:
133 * 'name' => 'Mercurial', // human displayable name
134 * 'tools' => array('hg'), // list of tools to find during setup
136 getSCMMetaData : _abstract,
138 /** Returns the default 'root' location in the repository.
139 * For SCMs that have a concept of branches, this is the empty string.
140 * For SCMs like SVN, this is the trunk dir */
141 getDefaultRoot : function() {
148 /* takes an MTrackSCM as a parameter because in some bootstrapping
149 * cases, we're actually MTrack_Repo and not the end-class.
150 * MTrack_Repo calls the end-class method and passes itself in for
152 reconcileRepoSettings : _abstract,
157 getBrowseRootName : _abstract,
162 * @param {string} rev - a fixed revision - always returns this if it is not false;
163 * @param {string} object [rev|branch|tag]- object type
164 * @param {ident} object id (eg. rev nun, branch name, tag name)
168 resolveRevision :function(rev, object, ident)
174 if (object === false) {
185 // technically we should check it exists..
188 //var branches = this.getBranches();
189 // branches is now an array - not a map.
191 //rev = typeof(branches[ident]) == 'undefined' ? false : branches[ident];
195 tags = this.getTags();
196 rev = typeof(tags[ident]) == 'undefined' ? false : tags[ident];
200 throw "don't know which revision to use (rev,object,ident) got" + object;
208 function reconcileRepoSettings()
210 $c = self::Factory(array('scmtype'=>$this->scmtype));
211 $s->reconcileRepoSettings($this);
214 function getServerURL()
216 if ($this->serverurl) {
217 return $this->serverurl;
223 function getCheckoutCommand() {
224 $url = $this->getServerURL();
226 return $this->scmtype . ' clone ' . $this->getServerURL();
235 function getWorkingCopy() {
236 throw new Exception("cannot getWorkingCopy from a generic repo object");
239 function deleteRepo(MTrackChangeset $CS) {
240 MTrackDB::q('delete from repos where repoid = ?', $this->repoid);
241 mtrack_rmdir($this->repopath);
246 // these are needed just to implement the abstract interface..
247 function getBranches() {}
248 function getTags() {}
249 function readdir($path, $object = null, $ident = null) {}
250 function file($path, $object = null, $ident = null) {}
251 function history($path, $limit = null, $object = null, $ident = null){}
252 function diff($path, $from = null, $to = null) {}
253 function getRelatedChanges($revision) {}
254 function getSCMMetaData() { return null; }
256 * converts a commit log message (cached locally into a working object..)
260 function commitLogToEvent($str) {
261 throw new Exception("no implementation for commitLogToEvent");
269 static $scms = array();
270 static function factory($ar)
273 $type = ucfirst($ar['scmtype']);
274 $fn = 'MTrack/SCM/'.$type .'/Repo.php';
275 $cls = 'MTrack_SCM_'.$type .'_Repo';
278 $ret = new $cls($ar);
285 static function getAvailableSCMs()
288 $ar = scandir(dirname(__FILE__).'/SCM');
291 if (empty($a) || $a[0] == '.') {
294 $fn = dirname(__FILE__).'/SCM/'.$a.'/Repo.php';
295 if (!file_exists($fn)) {
298 $ret[$a] = MTrack_Repo::factory(array('scmtype'=> $a));
306 Repo.list = function()
309 if (Repo._list !== false) {
313 var dir = GLib.get_home_dir() + '/gitlive';
314 var ar = File.list(dir );
315 print(JSON.stringify(ar));
316 ar.forEach(function(f) {
317 if (File.exists(dir + '/' + f +'/.git')) {
318 Repo._list.push(new imports.Scm.Git.Repo.Repo({repopath : dir +'/' + f }))