Skip to content

Commit 45907da

Browse files
committed
Fixing lastAction getter. Adding rev to the action object.
1 parent 933cadc commit 45907da

File tree

1 file changed

+62
-43
lines changed

1 file changed

+62
-43
lines changed

lib/svn-log-parser.js

+62-43
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var stream = require("stream")
44
, util = require("util")
5+
, path = require("path")
56
;
67

78
module.exports = function createParser( callback, opts, logs ) {
@@ -45,11 +46,13 @@ Parser.prototype.pipe = function( dest, opts ) {
4546
Parser.prototype.write = function( data ) {
4647
var parser = this;
4748

48-
var lines = "".split.call(data, /[\n\r]+/)
49-
, revInfo
50-
;
49+
var lines = "".split.call(data, /[\n\r]+/);
5150

5251
lines.forEach(function( line ) {
52+
var revInfo
53+
, actionInfo
54+
;
55+
5356
switch (whatIsLine(line)) {
5457
case "sep":
5558
break;
@@ -62,7 +65,9 @@ Parser.prototype.write = function( data ) {
6265
parser.results.revs[parser.currRev] = revInfo;
6366
break;
6467
case "action":
65-
updateFileInfo(parseActionInfo(line));
68+
actionInfo = parseActionInfo(line);
69+
actionInfo.rev = parser.currRev;
70+
updateFileInfo(parser, actionInfo);
6671
break;
6772
default:
6873
// Assume revision message
@@ -71,43 +76,6 @@ Parser.prototype.write = function( data ) {
7176
}
7277
}
7378
});
74-
75-
function updateFileInfo( actionInfo ) {
76-
var fileInfo;
77-
78-
if (!parser.results.files[actionInfo.file]) {
79-
parser.results.files[actionInfo.file] = { revs: [] };
80-
Object.defineProperty(parser.results.files[actionInfo.file], "lastAction", {
81-
enumerable: true
82-
, get: function() {
83-
var lastRev = fileInfo.revs[fileInfo.revs.length - 1]
84-
, actions = parser.results.revs[lastRev].actions
85-
, lastAction = actions.length - 1
86-
;
87-
88-
while (~lastAction && actions[lastAction].file != actionInfo.file) {
89-
lastAction--;
90-
}
91-
92-
return actions[lastAction];
93-
}
94-
});
95-
}
96-
fileInfo = parser.results.files[actionInfo.file];
97-
98-
fileInfo.revs.unshift(parser.currRev);
99-
100-
parser.results.revs[parser.currRev].actions.unshift(actionInfo);
101-
102-
parser.emit("action", {
103-
action: actionInfo.action
104-
, file: actionInfo.file
105-
, rev: parser.currRev
106-
});
107-
108-
// Test to also add all files in ADDED directories
109-
return fileInfo;
110-
}
11179
};
11280
Parser.prototype.end = function( chunk ) {
11381
if (!this._ended) {
@@ -174,10 +142,10 @@ var sepTest = /^-+$|^Changed paths:$/
174142
function parseRevInfo( line ) {
175143
var revMatch = revMatcher.exec(line);
176144
return {
177-
rev: revMatch[1]
145+
rev: Number(revMatch[1])
178146
, author: revMatch[2]
179147
, timestamp: revMatch[3]
180-
, actions: []
148+
, actions: {}
181149
, message: ""
182150
};
183151
}
@@ -190,6 +158,57 @@ function parseActionInfo( line ) {
190158
};
191159
}
192160

161+
function updateFileInfo( parser, actionInfo ) {
162+
var fileInfo;
163+
164+
if (!parser.results.files[actionInfo.file]) {
165+
parser.results.files[actionInfo.file] = { revs: [] };
166+
167+
Object.defineProperty(parser.results.files[actionInfo.file], "lastAction", {
168+
enumerable: true
169+
, get: function() {
170+
var lastRev = fileInfo.revs[fileInfo.revs.length - 1]
171+
, lastAction = parser.results.revs[lastRev].actions[actionInfo.file]
172+
, pathName
173+
, pathInfo
174+
, lastPathRev
175+
, lastPathAction
176+
, pathSplit = actionInfo.file.split(path.sep)
177+
;
178+
179+
while (lastAction.action !== "D" && pathSplit.pop()) {
180+
pathName = pathSplit.join(path.sep);
181+
pathInfo = parser.results.files[pathName];
182+
183+
if (!pathInfo) continue;
184+
185+
lastPathAction = pathInfo.lastAction;
186+
187+
if (lastPathAction.rev > lastRev && lastPathAction.action === "D") {
188+
lastAction = lastPathAction;
189+
}
190+
}
191+
192+
return lastAction;
193+
}
194+
});
195+
}
196+
197+
fileInfo = parser.results.files[actionInfo.file];
198+
199+
fileInfo.revs.unshift(parser.currRev);
200+
201+
parser.results.revs[parser.currRev].actions[actionInfo.file] = actionInfo;
202+
203+
parser.emit("action", {
204+
action: actionInfo.action
205+
, file: actionInfo.file
206+
, rev: parser.currRev
207+
});
208+
209+
return fileInfo;
210+
}
211+
193212
function whatIsLine( line ) {
194213
if (actionTest.test(line)) {
195214
return "action";

0 commit comments

Comments
 (0)