|
|
var Q = require('q'); |
|
|
|
|
|
var Main = require('../app'); |
|
|
var MultiView = require('../views/multiView').MultiView; |
|
|
|
|
|
function GitShim(options) { |
|
|
options = options || {}; |
|
|
|
|
|
|
|
|
|
|
|
this.beforeCB = options.beforeCB || function() {}; |
|
|
this.afterCB = options.afterCB || function() {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var resolveImmediately = function(deferred) { |
|
|
deferred.resolve(); |
|
|
}; |
|
|
this.beforeDeferHandler = options.beforeDeferHandler || resolveImmediately; |
|
|
this.afterDeferHandler = options.afterDeferHandler || resolveImmediately; |
|
|
this.eventBaton = options.eventBaton || Main.getEventBaton(); |
|
|
} |
|
|
|
|
|
GitShim.prototype.insertShim = function() { |
|
|
this.eventBaton.stealBaton('processGitCommand', this.processGitCommand, this); |
|
|
}; |
|
|
|
|
|
GitShim.prototype.removeShim = function() { |
|
|
this.eventBaton.releaseBaton('processGitCommand', this.processGitCommand, this); |
|
|
}; |
|
|
|
|
|
GitShim.prototype.processGitCommand = function(command, deferred) { |
|
|
this.beforeCB(command); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newDeferred = Q.defer(); |
|
|
newDeferred.promise |
|
|
.then(function() { |
|
|
|
|
|
this.afterGitCommandProcessed(command, deferred); |
|
|
}.bind(this)) |
|
|
.done(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var passBaton = function() { |
|
|
|
|
|
this.eventBaton.passBatonBack('processGitCommand', this.processGitCommand, this, [command, newDeferred]); |
|
|
}.bind(this); |
|
|
|
|
|
var beforeDefer = Q.defer(); |
|
|
beforeDefer.promise |
|
|
.then(passBaton) |
|
|
.done(); |
|
|
|
|
|
|
|
|
|
|
|
this.beforeDeferHandler(beforeDefer, command); |
|
|
}; |
|
|
|
|
|
GitShim.prototype.afterGitCommandProcessed = function(command, deferred) { |
|
|
this.afterCB(command); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var afterDefer = Q.defer(); |
|
|
afterDefer.promise |
|
|
.then(function() { |
|
|
deferred.resolve(); |
|
|
}) |
|
|
.done(); |
|
|
|
|
|
this.afterDeferHandler(afterDefer, command); |
|
|
}; |
|
|
|
|
|
exports.GitShim = GitShim; |
|
|
|
|
|
|