@@ -36,6 +36,17 @@ function parseDate(line) {
36
36
return moment . unix ( dateStamp ) . format ( formatString ) ;
37
37
}
38
38
39
+ /**
40
+ * Parses the summary line from the blame data for a line of code
41
+ *
42
+ * @param {string } line - the blame data for a particular line of code
43
+ * @return {string } - the summary line for the last commit for a line of code
44
+ */
45
+ function parseSummary ( line ) {
46
+ var summaryMatcher = / ^ s u m m a r y \s ( .* ) $ / m;
47
+ return line . match ( summaryMatcher ) [ 1 ] ;
48
+ }
49
+
39
50
/**
40
51
* Parses the blame --porcelain output for a particular line of code into a
41
52
* usable object with properties:
@@ -44,6 +55,7 @@ function parseDate(line) {
44
55
* line: the line number (1 indexed)
45
56
* committer: name of the committer of that line
46
57
* date: the date of the commit
58
+ * summary: the summary of the commit
47
59
*
48
60
* @param {string } blameData - the blame --porcelain output for a line of code
49
61
* @param {number } index - the index that the data appeared in an array of line
@@ -55,7 +67,8 @@ function parseBlameLine(blameData, index) {
55
67
hash : parseRevision ( blameData ) ,
56
68
line : index + 1 ,
57
69
committer : parseCommitter ( blameData ) ,
58
- date : parseDate ( blameData )
70
+ date : parseDate ( blameData ) ,
71
+ summary : parseSummary ( blameData )
59
72
} ) ;
60
73
}
61
74
@@ -78,14 +91,18 @@ function markIfNoCommit(parsedBlame) {
78
91
* @param {string } blameOutput - output from 'git blame --porcelain <file>'
79
92
*/
80
93
function parseBlameOutput ( blameOut ) {
81
- // Matches new lines only when followed by a line with commit hash info that
82
- // are followed by autor line. This is the 1st and 2nd line of the blame
83
- // --porcelain output.
84
- var singleLineDataSplitRegex = / \n (? = \w + \s (?: \d + \s ) + \d + \n a u t h o r ) / g;
94
+ // Matches the info lines for a specific line in the blame --porcelain output,
95
+ // which is up to the line after the one that begins with filename.
96
+ var blameChunkRegex = / (?: .* \n ) * ?f i l e n a m e .* ?\n \t .* ?\n / g;
85
97
86
98
// Split the blame output into data for each line and parse out desired
87
99
// data from each into an object.
88
- return blameOut . split ( singleLineDataSplitRegex ) . map ( parseBlameLine ) ;
100
+ var results = [ ] ;
101
+ var match ;
102
+ while ( ( match = blameChunkRegex . exec ( blameOut ) ) ) {
103
+ results . push ( parseBlameLine ( match [ 0 ] ) ) ;
104
+ }
105
+ return results ;
89
106
}
90
107
91
108
// EXPORTS
0 commit comments