Skip to content

Commit

Permalink
Adds Git.logBetween
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoffey authored and Eoin Coffey committed Sep 26, 2012
1 parent 7e82234 commit ac888bf
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/git-fs.js
Expand Up @@ -213,7 +213,38 @@ function gitExec(commands, encoding, callback) {
child.stdin.end();
}

var parseSummaryLogEntry = function(entry) {
var id = entry.match(/^commit ([a-f0-9]{40})/)[1];

var commit = {
id: id,
message: entry.match(/\n\n([\s\S]*)/)[1].trim()
}

entry.match(/^[A-Z][a-z]*:.*$/gm).forEach(function (line) {
var matches = line.match(/^([A-Za-z]+):\s*(.*)$/);
commit[matches[1].toLowerCase()] = matches[2];
});

return commit;
};

Git.logBetween = function(from, to, callback) {
var commands;
var args = ["log", "-z", from + ".." + to]

gitExec(args, 'utf8', function(err, text) {
if (err) { callback(err); return; }
if (text.length === 0) { callback(null, []); return; }

var log = [];
text.split("\0").forEach(function (entry) {
log.push(parseSummaryLogEntry(entry));
});

callback(null, log);
});
};

var logFile = safe(function logFile(version, path, callback) {
// Get the data from a git subprocess at the given sha hash.
Expand Down

0 comments on commit ac888bf

Please sign in to comment.