Permalink
Browse files

SCM init() interface is now asynchronous

  • Loading branch information...
1 parent 80c7335 commit ca5fc743fba5d74727a74260eab8897f807aeb5e @drewfish committed Apr 10, 2012
Showing with 38 additions and 20 deletions.
  1. +31 −15 lib/crank.js
  2. +4 −3 lib/scm-git.js
  3. +3 −2 lib/scm-svn.js
View
46 lib/crank.js
@@ -171,48 +171,64 @@ Base.prototype.filter = function(list, filters) {
Base.prototype.scmGetCurrentChangeID = function(cb) {
var me = this;
- this._scmInit(function(error) {
+ this._scmInit(function(error, scm) {
if (error) {
cb(error);
}
else {
- me._scm.getCurrentChangeID(cb);
+ scm.getCurrentChangeID(cb);
}
});
};
Base.prototype.scmListChanges = function(fromChange, toChange, cb) {
var me = this;
- this._scmInit(function(error) {
+ this._scmInit(function(error, scm) {
if (error) {
cb(error);
}
else {
- me._scm.listChanges(fromChange, toChange, cb);
+ scm.listChanges(fromChange, toChange, cb);
}
});
};
Base.prototype._scmInit = function(cb) {
- var i, scm;
+ var me = this,
+ scms;
+
if (this._scm) {
- cb(null);
+ cb(null, this._scm);
return;
}
- for (i in SCMS) {
- if (SCMS.hasOwnProperty(i)) {
- scm = new SCMS[i](this);
- // TODO: make this interface async as well
- if (scm.init(this.config.target)) {
- this._scm = scm;
- cb(null);
+ scms = Object.keys(SCMS);
+
+ function tryOne() {
+ var name, provisional;
+
+ name = scms.shift();
+ if (! name) {
+ cb(new Error('FAILED to find suitable SCM'));
+ return;
+ }
+
+ provisional = new SCMS[name](me);
+ provisional.init(me.config.target, function(error, scm) {
+ if (error) {
+ cb(error);
return;
}
- }
+ if (scm) {
+ me._scm = scm;
+ cb(null, scm);
+ return;
+ }
+ tryOne();
+ });
}
- cb(new Error('FAILED to find suitable SCM'));
+ tryOne();
};
View
7 lib/scm-git.js
@@ -35,7 +35,7 @@ function SCMGit(base) {
module.exports = SCMGit;
-SCMGit.prototype.init = function(target) {
+SCMGit.prototype.init = function(target, cb) {
var parts, i, path, repo;
if ('/' !== target.substring(0, 1)) {
target = libpath.join(process.cwd(), target);
@@ -48,10 +48,11 @@ SCMGit.prototype.init = function(target) {
if (libpath.existsSync(repo)) {
this.target = target;
this.repo = repo;
- return true;
+ cb(null, this);
+ return;
}
}
- return false;
+ cb(null, null);
};
View
5 lib/scm-svn.js
@@ -28,9 +28,10 @@ function SCMSvn() {}
module.exports = SCMSvn;
-SCMSvn.prototype.init = function(target) {
+SCMSvn.prototype.init = function(target, cb) {
// TODO
- return false;
+ cb(null, null);
+ return;
};

0 comments on commit ca5fc74

Please sign in to comment.