Skip to content

Commit

Permalink
cleaned trailing whitespace in some files
Browse files Browse the repository at this point in the history
  • Loading branch information
payload committed May 18, 2011
1 parent 718e0ce commit 166f142
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 285 deletions.
91 changes: 38 additions & 53 deletions lib/git/commit.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ var Commit = exports.Commit = function(repo, id, parents, tree, author, authored
Object.defineProperty(this, "repo", { get: function() { return _repo; }, set: function(value) { _repo = value; }, enumerable: true, configurable:true}); Object.defineProperty(this, "repo", { get: function() { return _repo; }, set: function(value) { _repo = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "id", { get: function() { return _id; }, set: function(value) { _id = value; }, enumerable: true, configurable:true}); Object.defineProperty(this, "id", { get: function() { return _id; }, set: function(value) { _id = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "sha", { get: function() { return _id; }, set: function(value) { _id = value; }, enumerable: true, configurable:true}); Object.defineProperty(this, "sha", { get: function() { return _id; }, set: function(value) { _id = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "parents", { get: function() { Object.defineProperty(this, "parents", { get: function() {
_parents = lazy_reader(_repo, _id, 'parents', _parents); _parents = lazy_reader(_repo, _id, 'parents', _parents);
return _parents; return _parents;
}, set: function(value) { _parents = value; }, enumerable: true, configurable:true}); }, set: function(value) { _parents = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "tree", { get: function() { Object.defineProperty(this, "tree", { get: function() {
_tree = lazy_reader(_repo, _id, 'tree', _tree); _tree = lazy_reader(_repo, _id, 'tree', _tree);
return _tree; return _tree;
}, set: function(value) { _tree = value; }, enumerable: true, configurable:true}); }, set: function(value) { _tree = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "author", { get: function() { Object.defineProperty(this, "author", { get: function() {
_author = lazy_reader(_repo, _id, 'author', _author); _author = lazy_reader(_repo, _id, 'author', _author);
return _author; return _author;
}, set: function(value) { _author = value; }, enumerable: true, configurable:true}); }, set: function(value) { _author = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "authored_date", { get: function() { Object.defineProperty(this, "authored_date", { get: function() {
_authored_date = lazy_reader(_repo, _id, 'authored_date', _authored_date); _authored_date = lazy_reader(_repo, _id, 'authored_date', _authored_date);
return _authored_date; return _authored_date;
}, set: function(value) { _authored_date = value; }, enumerable: true, configurable:true}); }, set: function(value) { _authored_date = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "committer", { get: function() { Object.defineProperty(this, "committer", { get: function() {
_committer = lazy_reader(_repo, _id, 'comitter', _committer); _committer = lazy_reader(_repo, _id, 'comitter', _committer);
return _committer; return _committer;
}, set: function(value) { _comitter = value; }, enumerable: true, configurable:true}); }, set: function(value) { _comitter = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "committed_date", { get: function() { Object.defineProperty(this, "committed_date", { get: function() {
_committed_date = lazy_reader(_repo, _id, 'committed_date', _committed_date); _committed_date = lazy_reader(_repo, _id, 'committed_date', _committed_date);
return _committed_date; return _committed_date;
}, set: function(value) { _committed_date = value; }, enumerable: true, configurable:true}); }, set: function(value) { _committed_date = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "message", { get: function() { Object.defineProperty(this, "message", { get: function() {
_message = lazy_reader(_repo, _id, 'message', _message); _message = lazy_reader(_repo, _id, 'message', _message);
return _message; return _message;
}, set: function(value) { _message = value; }, enumerable: true, configurable:true}); }, set: function(value) { _message = value; }, enumerable: true, configurable:true});
Object.defineProperty(this, "short_message", { get: function() { Object.defineProperty(this, "short_message", { get: function() {
_short_message = lazy_reader(_repo, _id, 'short_message', _short_message); _short_message = lazy_reader(_repo, _id, 'short_message', _short_message);
return _short_message; return _short_message;
}, set: function(value) { _short_message = value; }, enumerable: true, configurable:true}); }, set: function(value) { _short_message = value; }, enumerable: true, configurable:true});
Expand All @@ -69,13 +69,13 @@ var lazy_reader = function(repo, id, name, variable) {
}) })


while(!done) {}; while(!done) {};
return value ? value : ''; return value ? value : '';
} }


// Load a commit // Load a commit
Commit.prototype.load = function(callback) { Commit.prototype.load = function(callback) {
var self = this; var self = this;

Commit.find_all(this.repo, this.id, {max_count:1}, function(err, commits) { Commit.find_all(this.repo, this.id, {max_count:1}, function(err, commits) {
if(err) return callback(err, commits); if(err) return callback(err, commits);
var commit = commits[0]; var commit = commits[0];
Expand All @@ -94,7 +94,7 @@ var chomp = function chomp(raw_text) {
// Fetch the short form of an id // Fetch the short form of an id
Commit.prototype.id_abbrev = function(callback) { Commit.prototype.id_abbrev = function(callback) {
var self = this; var self = this;

if(this._id_abbrev) return callback(null, this._id_abbrev); if(this._id_abbrev) return callback(null, this._id_abbrev);
this.repo.git.rev_parse({}, this.id, 0, function(err, id) { this.repo.git.rev_parse({}, this.id, 0, function(err, id) {
if(err) return callback(err, id); if(err) return callback(err, id);
Expand All @@ -118,10 +118,10 @@ Commit.list_from_string = function(repo, text) {
var lines = text.split("\n"); var lines = text.split("\n");
var commits = []; var commits = [];
// Parse all commit messages // Parse all commit messages
while(lines.length > 0) { while(lines.length > 0) {
var id = lines.shift().split(/ /).pop(); var id = lines.shift().split(/ /).pop();
var tree = new Tree(repo, lines.shift().split(/ /).pop()); var tree = new Tree(repo, lines.shift().split(/ /).pop());

// Let's get the parents // Let's get the parents
var parents = []; var parents = [];
while(lines[0].match(/^parent/)) { while(lines[0].match(/^parent/)) {
Expand All @@ -137,14 +137,14 @@ Commit.list_from_string = function(repo, text) {
// Unpack encoding // Unpack encoding
var encoding = lines[0].match(/^encoding/) ? lines.shift().split().pop() : ''; var encoding = lines[0].match(/^encoding/) ? lines.shift().split().pop() : '';
// Jump empty space // Jump empty space
lines.shift(); lines.shift();
// Unpack message lines // Unpack message lines
var message_lines = []; var message_lines = [];
while(lines.length > 0 && lines[0].match(/^ {4}/)) { while(lines.length > 0 && lines[0].match(/^ {4}/)) {
var message_line = lines.shift(); var message_line = lines.shift();
message_lines.push(message_line.substring(4, message_line.length)) ; message_lines.push(message_line.substring(4, message_line.length)) ;
} }

// Move and point to next message // Move and point to next message
while(lines[0] != null && lines[0] == '') lines.shift(); while(lines[0] != null && lines[0] == '') lines.shift();
// Create commit object // Create commit object
Expand All @@ -159,27 +159,27 @@ Commit.find_all = function(repo, reference, options, callback) {
var self = this; var self = this;
var args = Array.prototype.slice.call(arguments, 1); var args = Array.prototype.slice.call(arguments, 1);
callback = args.pop(); callback = args.pop();
reference = args.length ? args.shift() : null; reference = args.length ? args.shift() : null;
options = args.length ? args.shift() : {}; options = args.length ? args.shift() : {};

// Merge the options with the default_options // Merge the options with the default_options
if(!options.pretty) options['pretty'] = 'raw'; if(!options.pretty) options['pretty'] = 'raw';
// If we have a reference use that for the lookup // If we have a reference use that for the lookup
if(!reference) options['all'] = true; if(!reference) options['all'] = true;

// Locate revisions // Locate revisions
if(reference) { if(reference) {
repo.git.rev_list(options, reference, function(err, revision_output) { repo.git.rev_list(options, reference, function(err, revision_output) {
if(err) return callback(err, []); if(err) return callback(err, []);
// Turn string into a list of revisions // Turn string into a list of revisions
callback(null, Commit.list_from_string(repo, revision_output)); callback(null, Commit.list_from_string(repo, revision_output));
}); });
} else { } else {
repo.git.rev_list(options, function(err, revision_output) { repo.git.rev_list(options, function(err, revision_output) {
if(err) return callback(err, []); if(err) return callback(err, []);
// Turn string into a list of revisions // Turn string into a list of revisions
callback(null, Commit.list_from_string(repo, revision_output)); callback(null, Commit.list_from_string(repo, revision_output));
}); });
} }
} }


Expand All @@ -204,14 +204,14 @@ Commit.diff = function(repo, a, b, paths, callback) {
var args = Array.prototype.slice.call(arguments, 2); var args = Array.prototype.slice.call(arguments, 2);
callback = args.pop(); callback = args.pop();
b = args.length ? args.shift() : null; b = args.length ? args.shift() : null;
paths = args.length ? args.shift() : []; paths = args.length ? args.shift() : [];

// If b is an array we skipped the b parameter // If b is an array we skipped the b parameter
if(Array.isArray(b)) { if(Array.isArray(b)) {
paths = b; paths = b;
b = null; b = null;
} }

// Set up parameters correctly // Set up parameters correctly
if(paths.length > 0) { if(paths.length > 0) {
if(paths.length > 0) paths.unshift("--"); if(paths.length > 0) paths.unshift("--");
Expand All @@ -221,19 +221,19 @@ Commit.diff = function(repo, a, b, paths, callback) {
repo.git.call_git('', 'diff', '', {full_index:true}, paths, function(err, text) { repo.git.call_git('', 'diff', '', {full_index:true}, paths, function(err, text) {
// Create a list of diffs from the string // Create a list of diffs from the string
if(text) { if(text) {
Diff.list_from_string(repo, text, callback); Diff.list_from_string(repo, text, callback);
} else { } else {
callback(null, []); callback(null, []);
} }
}); });
} else { } else {
repo.git.diff(a, b, {full_index:true}, function(err, text) { repo.git.diff(a, b, {full_index:true}, function(err, text) {
// Create a list of diffs from the string // Create a list of diffs from the string
if(text) { if(text) {
Diff.list_from_string(repo, text, callback); Diff.list_from_string(repo, text, callback);
} else { } else {
callback(null, []); callback(null, []);
} }
}); });
} }
} }
Expand All @@ -253,7 +253,7 @@ Commit.prototype.show = function(callback) {
var parents = this.parents; var parents = this.parents;
var diff = null var diff = null
var self = this; var self = this;

if(parents.length > 1) { if(parents.length > 1) {
this.repo.git.native_call("diff " + parents[0].id + "..." + parents[1].id, {full_index:true}, function(err, diff) { this.repo.git.native_call("diff " + parents[0].id + "..." + parents[1].id, {full_index:true}, function(err, diff) {
if(err) return callback(err, diff); if(err) return callback(err, diff);
Expand All @@ -262,19 +262,19 @@ Commit.prototype.show = function(callback) {
} else { } else {
this.repo.git.show({full_index:true, pretty:'raw'}, this.id, function(err, diff) { this.repo.git.show({full_index:true, pretty:'raw'}, this.id, function(err, diff) {
if(err) return callback(err, diff); if(err) return callback(err, diff);
process_diff(this.repo, diff, callback); process_diff(this.repo, diff, callback);
}); });
} }
} }


// Return the diffs for a commit // Return the diffs for a commit
Commit.prototype.diffs = function(callback) { Commit.prototype.diffs = function(callback) {
var parents = this.parents; var parents = this.parents;
// If we have no parents // If we have no parents
if(parents.length == 0) { if(parents.length == 0) {
this.show(callback); this.show(callback);
} else { } else {
Commit.diff(this.repo, parents[0].id, this.id, callback) Commit.diff(this.repo, parents[0].id, this.id, callback)
} }
} }


Expand All @@ -288,18 +288,3 @@ Commit.prototype.toPatch = function(callback) {
this.repo.git.format_patch({'1':true, stdout:true}, this.id, callback); this.repo.git.format_patch({'1':true, stdout:true}, this.id, callback);
} }

















30 changes: 15 additions & 15 deletions lib/git/diff.js
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
var Blob = require('./blob').Blob; var Blob = require('./blob').Blob;


var Diff = exports.Diff = function(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff) { var Diff = exports.Diff = function(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff) {
var _repo = repo, _a_path = a_path, _b_path = b_path var _repo = repo, _a_path = a_path, _b_path = b_path
var _a_mode = a_mode, _b_mode = b_mode, _diff = diff; var _a_mode = a_mode, _b_mode = b_mode, _diff = diff;
// Create blob objects // Create blob objects
Expand All @@ -10,16 +10,16 @@ var Diff = exports.Diff = function(repo, a_path, b_path, a_blob, b_blob, a_mode,
var _new_file = new_file || _a_blob == null; var _new_file = new_file || _a_blob == null;
var _deleted_file = deleted_file || _b_blob == null; var _deleted_file = deleted_file || _b_blob == null;


Object.defineProperty(this, "repo", { get: function() { return _repo; }, enumerable: true}); Object.defineProperty(this, "repo", { get: function() { return _repo; }, enumerable: true});
Object.defineProperty(this, "a_path", { get: function() { return _a_path; }, enumerable: true}); Object.defineProperty(this, "a_path", { get: function() { return _a_path; }, enumerable: true});
Object.defineProperty(this, "b_path", { get: function() { return _b_path; }, enumerable: true}); Object.defineProperty(this, "b_path", { get: function() { return _b_path; }, enumerable: true});
Object.defineProperty(this, "a_mode", { get: function() { return _a_mode; }, enumerable: true}); Object.defineProperty(this, "a_mode", { get: function() { return _a_mode; }, enumerable: true});
Object.defineProperty(this, "b_mode", { get: function() { return _b_mode; }, enumerable: true}); Object.defineProperty(this, "b_mode", { get: function() { return _b_mode; }, enumerable: true});
Object.defineProperty(this, "diff", { get: function() { return _diff; }, enumerable: true}); Object.defineProperty(this, "diff", { get: function() { return _diff; }, enumerable: true});
Object.defineProperty(this, "a_blob", { get: function() { return _a_blob; }, enumerable: true}); Object.defineProperty(this, "a_blob", { get: function() { return _a_blob; }, enumerable: true});
Object.defineProperty(this, "b_blob", { get: function() { return _b_blob; }, enumerable: true}); Object.defineProperty(this, "b_blob", { get: function() { return _b_blob; }, enumerable: true});
Object.defineProperty(this, "new_file", { get: function() { return _new_file; }, enumerable: true}); Object.defineProperty(this, "new_file", { get: function() { return _new_file; }, enumerable: true});
Object.defineProperty(this, "deleted_file", { get: function() { return _deleted_file; }, enumerable: true}); Object.defineProperty(this, "deleted_file", { get: function() { return _deleted_file; }, enumerable: true});
} }


// Create a list of diffs from a diff text // Create a list of diffs from a diff text
Expand All @@ -31,22 +31,22 @@ Diff.list_from_string = function(repo, text, callback) {
var diffs = []; var diffs = [];
var a_path, b_path, a_mode, b_mode, new_file = false, deleted_file = false; var a_path, b_path, a_mode, b_mode, new_file = false, deleted_file = false;
var a_blob, b_blob; var a_blob, b_blob;

while(text.length > 0 && lines.length > 0) { while(text.length > 0 && lines.length > 0) {
// Extract a line // Extract a line
var parts = lines.shift().match(/^diff --git a\/(.+?) b\/(.+)$/); var parts = lines.shift().match(/^diff --git a\/(.+?) b\/(.+)$/);
// Unpack parts // Unpack parts
var a_path = parts[1]; var a_path = parts[1];
var b_path = parts[2]; var b_path = parts[2];

if(lines[0].match(/^old mode/)) { if(lines[0].match(/^old mode/)) {
a_mode = lines.shift().match(/^old mode (\d+)/)[1] a_mode = lines.shift().match(/^old mode (\d+)/)[1]
b_mode = lines.shift().match(/^new mode (\d+)/)[1] b_mode = lines.shift().match(/^new mode (\d+)/)[1]
} }

if(lines.length == 0 || lines[0].match(/^diff --git/)) { if(lines.length == 0 || lines[0].match(/^diff --git/)) {
diffs.push(new Diff(repo, a_path, b_path, null, null, a_mode, b_mode, false, false, null)); diffs.push(new Diff(repo, a_path, b_path, null, null, a_mode, b_mode, false, false, null));
} else { } else {
if(lines[0].match(/^new file/)) { if(lines[0].match(/^new file/)) {
b_mode = lines.shift().match(/^new file mode (.+)$/)[1]; b_mode = lines.shift().match(/^new file mode (.+)$/)[1];
a_mode = null; a_mode = null;
Expand Down
Loading

0 comments on commit 166f142

Please sign in to comment.