parse mercurial tags

This commit is contained in:
oleg 2015-06-28 13:04:36 +03:00
parent b5bca8076d
commit 15e5191ca5
5 changed files with 42 additions and 7 deletions

View File

@ -15,18 +15,44 @@ inherits(Scm, ParentScm);
Scm.prototype.defaultRev = 'default';
Scm.prototype._revTemplate = (
'{node|short};;;{author};;;{date|date};;;{desc}'
);
// use 2 invisible separators as fields separator
Scm.prototype._fieldsSeparator = String.fromCharCode(2063);
Scm.prototype._fieldsSeparator += Scm.prototype._fieldsSeparator;
// use 2 vertical tabs as arrays separator
Scm.prototype._arraysSeparator = String.fromCharCode(11);
Scm.prototype._arraysSeparator += Scm.prototype._arraysSeparator;
Scm.prototype._revTemplate = [
'{node|short}',
'{author}',
'{date|date}',
'{desc}',
'{join(tags, "' + Scm.prototype._arraysSeparator + '")}'
].join(Scm.prototype._fieldsSeparator);
Scm.prototype._parseRev = function(str) {
var parts = str.split(';;;');
return {
var parts = str.split(this._fieldsSeparator);
var rev = {
id: parts[0],
author: parts[1],
date: new Date(parts[2]).getTime(),
comment: parts[3]
};
var tagsStr = parts[4];
if (tagsStr) {
var tags = tagsStr.split(this._arraysSeparator);
// drop the tip tag
tags = _(tags).without('tip');
if (tags.length) {
// sort tags alphabetically
rev.tags = _(tags).sortBy();
}
}
return rev;
};
Scm.prototype.clone = function(dst, rev, callback) {

View File

@ -21,6 +21,7 @@ exports.removeDirIfExists = function(dir, done) {
// revisions for the test mercurial repo
exports.mercurialRevs = [{
id: 'da2762e71e87',
tags: ['zero revision'],
author: 'kotbegemot',
date: new Date('Fri May 09 22:36:41 2014 +0400').getTime(),
comment: 'zero revision'
@ -31,6 +32,7 @@ exports.mercurialRevs = [{
comment: 'first revision'
}, {
id: '9d7d08445f4c',
tags: ['release 0.1.0', 'second revision'],
author: 'kotbegemot',
date: new Date('Sat May 10 03:18:20 2014 +0400').getTime(),
comment: 'third revision'

View File

@ -0,0 +1 @@
default

Binary file not shown.

View File

@ -1,6 +1,7 @@
'use strict';
var expect = require('expect.js'),
_ = require('underscore'),
path = require('path'),
fs = require('fs'),
createScm = require('../lib/scm').createScm,
@ -49,7 +50,11 @@ var expect = require('expect.js'),
it('expect current revision equals to rev0', function(done) {
scm.getCurrent(function(err, rev) {
if (err) return done(err);
expect(rev).eql(data[0]);
// there is no tag for mercurial repo coz when you clone with
// specified revision no later revision will be cloned
// including those one with add tag (it's after rev 0 in our
// repo)
expect(rev).eql(_(data[0]).omit('tags'));
done();
});
});
@ -57,7 +62,8 @@ var expect = require('expect.js'),
it('expect rev0 info is good', function(done) {
scm.getRev(mercurialRevs[0].id, function(err, rev) {
if (err) return done(err);
expect(rev).eql(mercurialRevs[0]);
// no tag here, see note above
expect(rev).eql(_(data[0]).omit('tags'));
done();
});
});