Permalink
Browse files

example file and actual parsing

  • Loading branch information...
1 parent aa5cea0 commit 07f8c4f4690a87e8d0cd7ab370fd828b69868bdb @substack committed Oct 2, 2012
Showing with 36 additions and 10 deletions.
  1. +4 −0 example/history.js
  2. +32 −10 index.js
View
4 example/history.js
@@ -0,0 +1,4 @@
+var history = require('../');
+history().on('data', function (commit) {
+ console.dir(commit);
+});
View
42 index.js
@@ -5,23 +5,45 @@ var through = require('through');
exports = module.exports = function (since, until) {
var data = '';
var sp = split();
- sp.pipe(through(write, end));
- return sp;
+ var tr = through(write, end);
+ sp.pipe(tr);
- function write (buf) {
- this.emit('{}\n');
+ var piped = false;
+ sp.on('pipe', function () {
+ piped = true;
+ });
+
+ process.nextTick(function () {
+ if (!piped) history(since, until).pipe(sp);
+ });
+
+ var commit = null;
+
+ return tr;
+
+ function write (line) {
+ var m;
+ if (m = /^commit\s+(\S+)/i.exec(line)) {
+ if (commit) this.emit('data', commit);
+ commit = { hash : line.split(/\s+/)[1] };
+ }
+ else if (m = /^Author:\s+(.+?)(?: <([^>]+)>)?$/i.exec(line)) {
+ commit.author = {
+ name : m[1],
+ email : m[2],
+ };
+ }
+ else if (m = /^Date:\s+(.+)/.exec(line)) {
+ commit.date = new Date(m[1]);
+ }
}
function end () {
-
+ this.emit('data', commit);
+ this.emit('end');
}
};
-function show (ref, file) {
- if (file === '.') file = './';
- return run('git' [ 'show', ref + ':' + file ]);
-}
-
function history (since, until) {
if (since === undefined) {
return run('git', [ 'log' ]);

0 comments on commit 07f8c4f

Please sign in to comment.