-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitlogparser.js
113 lines (96 loc) · 3.11 KB
/
gitlogparser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* GitLogParser is a JavaScript parser for inflating a data object from the
* output of a `git log --format=raw -- [file]` operation
*
* @author Matt Pardee
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
define(function(require, exports, module) {
module.exports = (function() {
function GitLogParser() {
this.arrLogData = [];
this.currentLine = {
commit : "",
tree : "",
parent : "",
author : {},
committer : {},
message : []
};
}
GitLogParser.prototype = {
/**
* The entry point for parsing the output from git log
*
* @param {string} log The output as a string
*/
parseLog : function(log) {
this.arrLogData = [];
this.currentLine = {
commit : "",
tree : "",
parent : "",
author : {},
committer : {},
message : []
};
var lines = log.split('\n');
for (var lineIt in lines)
this.parseLine(lines[lineIt]);
this.arrLogData.push(this.currentLine);
},
getLogData : function() {
return this.arrLogData;
},
parseLine : function(line) {
if (line === "" || typeof line !== "string")
return;
var splitLine = line.split(" ");
// Tab character means part of the commit message
if (splitLine[0] === "") {
this.currentLine.message.push(line.substr(4));
return;
}
switch (splitLine[0]) {
case "commit":
if (this.currentLine.tree !== "")
this.arrLogData.push(this.currentLine);
this.currentLine = {
commit : splitLine[1],
tree : "",
parent : "",
author : {},
committer : {},
message : []
};
break;
case "tree":
this.currentLine.tree = splitLine[1];
break;
case "parent":
this.currentLine.parent = splitLine[1];
break;
case "author":
this.currentLine.author = this.parseUserLine(splitLine);
break;
case "committer":
this.currentLine.committer = this.parseUserLine(splitLine);
break;
default:
break;
}
},
parseUserLine : function(splitLine) {
var len = splitLine.length;
var user = {
fullName : splitLine.slice(1, len-3).join(" "),
email : splitLine[len-3],
timestamp : splitLine[len-2],
tzOffset : splitLine[len-1]
};
return user;
}
};
return GitLogParser;
})();
});