Permalink
Browse files

made git log working

  • Loading branch information...
1 parent 166f142 commit cb04773a3928e4e93ba903b982adcffb63f0b953 @payload payload committed May 18, 2011
Showing with 39 additions and 13 deletions.
  1. +32 −12 lib/git/commit.js
  2. +7 −1 lib/git/git.js
View
44 lib/git/commit.js
@@ -4,9 +4,9 @@ var sys = require('sys'),
Tree = require('./tree').Tree;
// Create a commit object
-var Commit = exports.Commit = function(repo, id, parents, tree, author, authored_date, committer, committed_date, message) {
+var Commit = exports.Commit = function(repo, id, parents, tree, author, authored_date, committer, committed_date, message, filechanges) {
var _repo = repo, _id = id, _parents = parents, _tree = tree, _author = author, _authored_date = authored_date;
- var _committer = committer, _committed_date = committed_date, _id_abbrev = null;
+ var _committer = committer, _committed_date = committed_date, _id_abbrev = null, _filechanges = filechanges;
// Ensure we have an empty message at least
message = message ? message : [];
message = Array.isArray(message) ? message : [message];
@@ -52,6 +52,10 @@ var Commit = exports.Commit = function(repo, id, parents, tree, author, authored
_short_message = lazy_reader(_repo, _id, 'short_message', _short_message);
return _short_message;
}, set: function(value) { _short_message = value; }, enumerable: true, configurable:true});
+ Object.defineProperty(this, "filechanges", { get: function() {
+ _filechanges = lazy_reader(_repo, _id, 'filechanges', _filechanges);
+ return _filechanges;
+ }, set: function(value) { _filechanges = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "_id_abbrev", { get: function() { return _id_abbrev; }, set: function(value) { _id_abbrev = value; }, enumerable: true, configurable:true});
}
@@ -116,39 +120,55 @@ var actor = function(line) {
Commit.list_from_string = function(repo, text) {
// Split up the result
var lines = text.split("\n");
+ var linesshift = function() { return lines.shift(); };
var commits = [];
// Parse all commit messages
while(lines.length > 0) {
- var id = lines.shift().split(/ /).pop();
- var tree = new Tree(repo, lines.shift().split(/ /).pop());
+ var id = linesshift().split(/ /).pop();
+ var tree = new Tree(repo, linesshift().split(/ /).pop());
// Let's get the parents
var parents = [];
while(lines[0].match(/^parent/)) {
- parents.push(new Commit(repo, lines.shift().split(/ /).pop()))
+ parents.push(new Commit(repo, linesshift().split(/ /).pop()))
}
// Let's get the author and committer
- var actor_info = actor(lines.shift());
+ var actor_info = actor(linesshift());
var author = actor_info[0];
var authored_date = actor_info[1]
- var committer_info = actor(lines.shift());
+ var committer_info = actor(linesshift());
var comitter = committer_info[0];
var committed_date = committer_info[1];
// Unpack encoding
- var encoding = lines[0].match(/^encoding/) ? lines.shift().split().pop() : '';
+ var encoding = lines[0].match(/^encoding/) ? linesshift().split().pop() : '';
// Jump empty space
- lines.shift();
+ linesshift();
// Unpack message lines
var message_lines = [];
while(lines.length > 0 && lines[0].match(/^ {4}/)) {
- var message_line = lines.shift();
+ var message_line = linesshift();
message_lines.push(message_line.substring(4, message_line.length)) ;
}
+ linesshift();
+ // Parse --raw lines
+ var filechanges = []
+ while (lines.length > 0) {
+ var re = /:(\d+) (\d+) ([a-z0-9]+) ([a-z0-9]+) (\S+)\s+(.+)/;
+ var rawline = linesshift().match(re);
+ if (!rawline) break;
+ var filechange = {};
+ var xs = ['a_mode', 'b_mode', 'a_blob', 'b_blob', 'what', 'path'];
+ for(var i = 0; i < xs.length; i++) {
+ filechange[xs[i]] = rawline[i+1];
+ }
+ filechanges.push(filechange);
+ }
+
// Move and point to next message
- while(lines[0] != null && lines[0] == '') lines.shift();
+ while(lines[0] != null && lines[0] == '') linesshift();
// Create commit object
- commits.push(new Commit(repo, id, parents, tree, author, authored_date, comitter, committed_date, message_lines));
+ commits.push(new Commit(repo, id, parents, tree, author, authored_date, comitter, committed_date, message_lines, filechanges));
}
// Return all the commits
return commits;
View
8 lib/git/git.js
@@ -605,7 +605,13 @@ Git.prototype.fs_write = function(file, content, callback) {
// Log function, returns the number of logs
Git.prototype.log = function(commit, path, options, callback) {
-
+ args = ['--raw', '--no-abbrev'];
+ if (path) {
+ args.push('--');
+ args.push(path);
+ }
+ options.color = 'never';
+ this.call_git('', 'log', '', options, args, callback);
}
// Select the objects that exists

0 comments on commit cb04773

Please sign in to comment.