From da580dd81335ef34060a7af8b0a49fdd237b863c Mon Sep 17 00:00:00 2001 From: oleg Date: Sat, 9 May 2015 19:32:26 +0300 Subject: [PATCH] getCurrent method replaces getId at scm api --- lib/scm/base.js | 4 ++-- lib/scm/mercurial.js | 36 ++++++++++++++++++++++++------------ test/scm.js | 10 +++++----- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/scm/base.js b/lib/scm/base.js index faa2541..21d82cb 100644 --- a/lib/scm/base.js +++ b/lib/scm/base.js @@ -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) { }; /** diff --git a/lib/scm/mercurial.js b/lib/scm/mercurial.js index dce5dea..b329895 100644 --- a/lib/scm/mercurial.js +++ b/lib/scm/mercurial.js @@ -13,6 +13,20 @@ inherits(Scm, ParentScm); 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) { var self = this; this.run({ @@ -28,25 +42,23 @@ Scm.prototype.pull = function(rev, callback) { this.run({cmd: 'hg', args: ['pull', '--rev', rev]}, callback); }; -Scm.prototype.getId = function(callback) { - this.run({cmd: 'hg', args: ['id', '--id']}, function(err, stdout) { - callback(err, !err && stdout.replace('\n', '')); +Scm.prototype.getCurrent = function(callback) { + var self = this; + 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) { - this.run({cmd: 'hg', args: [ + var self = this; + self.run({cmd: 'hg', args: [ 'log', '--rev', rev2 + ':' + rev1, - '--template', '{node|short};;;{author};;;{date|date};;;{desc}\n' + '--template', self._revTemplate + '\n' ]}, function(err, stdout) { callback(err, !err && stdout.split('\n').slice(0, -2).map(function(str) { - var parts = str.split(';;;'); - return { - id: parts[0], - author: parts[1], - date: new Date(parts[2]).getTime(), - comment: parts[3] - }; + return self._parseRev(str); })); }); }; diff --git a/test/scm.js b/test/scm.js index 7639b20..88ee687 100644 --- a/test/scm.js +++ b/test/scm.js @@ -45,10 +45,10 @@ var expect = require('expect.js'), expect(scm.cwd).equal(repositoryPath); }); - it('expect current id equals to rev0', function(done) { - scm.getId(function(err, id) { + it('expect current revision equals to rev0', function(done) { + scm.getCurrent(function(err, rev) { if (err) return done(err); - expect(id).equal(data.rev0.id); + expect(rev).eql(data.rev0); done(); }); }); @@ -83,9 +83,9 @@ var expect = require('expect.js'), }); it('expect current revision equals to rev2', function(done) { - scm.getId(function(err, id) { + scm.getCurrent(function(err, rev) { if (err) return done(err); - expect(id).equal(data.rev2.id); + expect(rev).eql(data.rev2); done(); }); });