getCurrent method replaces getId at scm api

This commit is contained in:
oleg 2015-05-09 19:32:26 +03:00
parent 0d8cf1bc17
commit da580dd813
3 changed files with 31 additions and 19 deletions

View File

@ -29,9 +29,9 @@ Scm.prototype.pull = function(rev, callback) {
}; };
/** /**
* Returns string id of current revision * Returns info (in changes format) about current revision
*/ */
Scm.prototype.getId = function(callback) { Scm.prototype.getCurrent = function(callback) {
}; };
/** /**

View File

@ -13,6 +13,20 @@ inherits(Scm, ParentScm);
Scm.prototype.defaultRev = 'default'; Scm.prototype.defaultRev = 'default';
Scm.prototype._revTemplate = (
'{node|short};;;{author};;;{date|date};;;{desc}'
);
Scm.prototype._parseRev = function(str) {
var parts = str.split(';;;');
return {
id: parts[0],
author: parts[1],
date: new Date(parts[2]).getTime(),
comment: parts[3]
};
};
Scm.prototype.clone = function(dst, rev, callback) { Scm.prototype.clone = function(dst, rev, callback) {
var self = this; var self = this;
this.run({ this.run({
@ -28,25 +42,23 @@ Scm.prototype.pull = function(rev, callback) {
this.run({cmd: 'hg', args: ['pull', '--rev', rev]}, callback); this.run({cmd: 'hg', args: ['pull', '--rev', rev]}, callback);
}; };
Scm.prototype.getId = function(callback) { Scm.prototype.getCurrent = function(callback) {
this.run({cmd: 'hg', args: ['id', '--id']}, function(err, stdout) { var self = this;
callback(err, !err && stdout.replace('\n', '')); self.run({cmd: 'hg', args: [
'parent', '--template', self._revTemplate
]}, function(err, stdout) {
callback(err, !err && self._parseRev(stdout));
}); });
}; };
Scm.prototype.getChanges = function(rev1, rev2, callback) { Scm.prototype.getChanges = function(rev1, rev2, callback) {
this.run({cmd: 'hg', args: [ var self = this;
self.run({cmd: 'hg', args: [
'log', '--rev', rev2 + ':' + rev1, 'log', '--rev', rev2 + ':' + rev1,
'--template', '{node|short};;;{author};;;{date|date};;;{desc}\n' '--template', self._revTemplate + '\n'
]}, function(err, stdout) { ]}, function(err, stdout) {
callback(err, !err && stdout.split('\n').slice(0, -2).map(function(str) { callback(err, !err && stdout.split('\n').slice(0, -2).map(function(str) {
var parts = str.split(';;;'); return self._parseRev(str);
return {
id: parts[0],
author: parts[1],
date: new Date(parts[2]).getTime(),
comment: parts[3]
};
})); }));
}); });
}; };

View File

@ -45,10 +45,10 @@ var expect = require('expect.js'),
expect(scm.cwd).equal(repositoryPath); expect(scm.cwd).equal(repositoryPath);
}); });
it('expect current id equals to rev0', function(done) { it('expect current revision equals to rev0', function(done) {
scm.getId(function(err, id) { scm.getCurrent(function(err, rev) {
if (err) return done(err); if (err) return done(err);
expect(id).equal(data.rev0.id); expect(rev).eql(data.rev0);
done(); done();
}); });
}); });
@ -83,9 +83,9 @@ var expect = require('expect.js'),
}); });
it('expect current revision equals to rev2', function(done) { it('expect current revision equals to rev2', function(done) {
scm.getId(function(err, id) { scm.getCurrent(function(err, rev) {
if (err) return done(err); if (err) return done(err);
expect(id).equal(data.rev2.id); expect(rev).eql(data.rev2);
done(); done();
}); });
}); });