Skip to content

Commit f70feae

Browse files
committed
Show the lastTag and the noOfAdditionalCommits
1 parent 3f25daa commit f70feae

File tree

12 files changed

+141
-15
lines changed

12 files changed

+141
-15
lines changed

index.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,40 @@ function findTag(gitPath, sha) {
149149
return tags.length ? tags[0] : false;
150150
}
151151

152+
var LAST_TAG_CACHE = {};
153+
154+
function findLastTagCached(gitPath, sha, commitsSinceLastTag) {
155+
if(!LAST_TAG_CACHE[gitPath]) {
156+
LAST_TAG_CACHE[gitPath] = {};
157+
}
158+
159+
if(!LAST_TAG_CACHE[gitPath][sha]) {
160+
LAST_TAG_CACHE[gitPath][sha] = findLastTag(gitPath, sha, commitsSinceLastTag);
161+
}
162+
163+
return LAST_TAG_CACHE[gitPath][sha];
164+
}
165+
166+
function findLastTag(gitPath, sha, commitsSinceLastTag) {
167+
commitsSinceLastTag = commitsSinceLastTag || 0;
168+
var tag = findTag(gitPath, sha);
169+
if(!tag) {
170+
var commitData = getCommitData(gitPath, sha);
171+
if(!commitData) {
172+
return { tag: null, commitsSinceLastTag: Infinity };
173+
}
174+
return commitData.parents
175+
.map(parent => findLastTag(gitPath, parent, commitsSinceLastTag + 1))
176+
.reduce((a,b) => {
177+
return a.commitsSinceLastTag < b.commitsSinceLastTag ? a : b;
178+
}, { commitsSinceLastTag: Infinity });
179+
}
180+
return {
181+
tag: tag,
182+
commitsSinceLastTag: commitsSinceLastTag
183+
};
184+
}
185+
152186
function findUnpackedTags(gitPath, sha) {
153187
var unpackedTags = [];
154188
var tags = findLooseRefsForType(gitPath, 'tags');
@@ -179,7 +213,9 @@ module.exports = function(gitPath) {
179213
author: null,
180214
authorDate: null,
181215
commitMessage: null,
182-
root: null
216+
root: null,
217+
lastTag: null,
218+
commitsSinceLastTag: 0,
183219
};
184220

185221
if (!gitPathInfo) { return result; }
@@ -228,6 +264,10 @@ module.exports = function(gitPath) {
228264
if (tag) {
229265
result.tag = tag;
230266
}
267+
268+
var lastTagInfo = findLastTagCached(gitPathInfo.commonGitDir, result.sha);
269+
result.lastTag = lastTagInfo.tag;
270+
result.commitsSinceLastTag = lastTagInfo.commitsSinceLastTag;
231271
}
232272
} catch (e) {
233273
if (!module.exports._suppressErrors) {
@@ -263,7 +303,6 @@ function getCommitData(gitPath, sha) {
263303
case 'object':
264304
case 'type':
265305
case 'tree':
266-
case 'parent':
267306
//ignore these for now
268307
break;
269308
case 'author':
@@ -275,6 +314,9 @@ function getCommitData(gitPath, sha) {
275314
data[part + 'Date'] = parseDate(parts[2]);
276315
}
277316
break;
317+
case 'parent':
318+
data.parents = section.split('\n').map(p => p.split(' ')[1]);
319+
break;
278320
default:
279321
//should just be the commit message left
280322
data.commitMessage = section;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b60d665ae0978a7b46e2447f4c13d7909997f56c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4f5c726a1528fdfb1ec7c9537e4b1b2dbaacbcc4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
65 Bytes
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��A��0 Eg�Sx��<�qS !�p��q���A�ק�a��K��I������e�*P�>a�Ys��Q� �>ƚU�Gr���l�̵S�%r(��F
2+
B5K�<uZ�T�.�6���==�҆Q8�����f4��>�4���M'���ā�C��u ���o�{�����^��p5����%&Y�
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fb26504da0ed5cd9ed366f7428c06a8433fd76e6

0 commit comments

Comments
 (0)