SVN日志parsing通过Streams

我想通过streamparsingsvn提交日志。 我有一个仓库的工作,但如果我尝试做两个不同的仓库,它不工作,因为我打算。 如果我在getLatest()中使用svn_parse,它会显示两次第一个回购消息。 如果我这样做,如下所示,我得到第二个回购消息两次。 我怎么能得到这个工作,因为我打算?

var svn_parse = require('./svn_stream_parser'), spawn = require('child_process').spawn; function getLatest(repo) { var sp = require('./svn_stream_parser'); var svn = spawn('svn', ['log', '-v', '-l', '1', repo]); sp(svn.stdout).pipe(process.stdout); } getLatest('https://github.com/emberjs/ember.js'); getLatest('https://github.com/emberjs/starter-kit'); 

svn_stream_parser.js:

 var BufferStream = require('bufferstream'), through = require('through'), _ = require('lodash'); var bufferstream = new BufferStream({encoding:'utf8', size:'flexible'}); bufferstream.split('------------------------------------------------------------------------\n'); bufferstream.on('split', function (chunk) { bufferstream.emit('data', chunk) }); function parseStream(istream) { return istream.pipe(bufferstream) .pipe(through(function(chunk) { var str = chunk.toString(); if(str.trim().length === 0) return; var commitObj = parseCommit(str); this.queue(JSON.stringify(commitObj) + '\n'); })); } function parseCommit(commit) { var commitSplit = commit.split('\n'); var summarySplit = commitSplit.shift().split('|'); var commitObject = { /* repository: repositoryUrl,*/ revision: summarySplit[0].trim().substring(1), author: summarySplit[1].trim(), timestamp: summarySplit[2].trim(), files: [], messages: [] }; var idx = 0; if(commitSplit[0].trim() === 'Changed paths:') { // Start at 1 because 0 is expected to be an empty string // inserted for formatting for(idx = 1; idx < commitSplit.length; idx++) { var fileInfo = commitSplit[idx].trim(); if(fileInfo.length === 0) { break; // File change block is contiguous, empty line means the block is done } commitObject.files.push({ operation: fileInfo.substring(0,1), path: fileInfo.substring(2) }); } } // Parse the remaining lines, they should all be the commit message _.forEach(commitSplit.slice(idx + 1), function(msg) { msg = msg.trim(); if(msg.length > 0) { commitObject.messages.push(msg); } }); return commitObject; } module.exports = parseStream; 

问题是我的bufferstream如何被挖掘,应该是

 function parseStream(istream) { var bufferstream = new BufferStream({encoding:'utf8', size:'flexible'}); bufferstream.split('------------------------------------------------------------------------\n'); bufferstream.on('split', function (chunk) { bufferstream.emit('data', chunk) }); return istream.pipe(bufferstream) .pipe(through(function(chunk) { var str = chunk.toString(); if(str.trim().length === 0) return; var commitObj = parseCommit(str); this.queue(JSON.stringify(commitObj) + '\n'); })); }