Skip to content

Commit

Permalink
Fix up Diff.blobToBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
John Haley committed Apr 21, 2015
1 parent b294842 commit a0a1654
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
29 changes: 29 additions & 0 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,35 @@
],
"functions": {
"git_diff_blob_to_buffer": {
"args": {
"old_blob" : {
"isOptional": true
},
"old_as_path" : {
"isOptional": true
},
"buffer" : {
"isOptional": true
},
"buffer_len" : {
"isOptional": true
},
"buffer_as_path" : {
"isOptional": true
},
"options" : {
"isOptional": true
},
"file_cb" : {
"isOptional": true
},
"hunk_cb" : {
"isOptional": true
},
"line_cb" : {
"isOptional": true
}
},
"return": {
"isErrorCode": true
},
Expand Down
29 changes: 25 additions & 4 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,30 @@ Diff.prototype.findSimilar = function(opts) {
return findSimilar.call(this, opts);
};

var blobToBuffer = Diff.prototype.blobToBuffer;
Diff.prototype.blobToBuffer = function(old_blob, old_as_path, buffer, buffer_length, buffer_as_path, opts, file_cb, hunk_cb, line_cb) {
console.log("********************************");
var blobToBuffer = Diff.blobToBuffer;
Diff.blobToBuffer= function(
old_blob,
old_as_path,
buffer,
buffer_as_path,
opts,
file_cb,
hunk_cb,
line_cb) {
var bufferLength = !buffer ? 0 : buffer.length;

opts = normalizeOptions(opts, NodeGit.DiffOptions);
return blobToBuffer.call(this, old_blob, old_as_path, buffer, buffer_length, buffer_as_path, opts, file_cb, hunk_cb, line_cb);

return blobToBuffer.call(
this,
old_blob,
old_as_path,
buffer,
bufferLength,
buffer_as_path,
opts,
file_cb,
hunk_cb,
line_cb,
null);
};
26 changes: 13 additions & 13 deletions test/tests/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,28 @@ describe("Diff", function() {
});
});

it("can diff the contents of a file to the index", function(done) {
it("can diff the contents of a file to a string", function(done) {
this.repository.getBranchCommit("master")
.then(function(commit) {
var difffile = "LICENSE";
return commit.getEntry(difffile);
return commit.getEntry("LICENSE");
})
.then(function(entry) {
var _entry = entry;
return _entry.getBlob();
})
.then(function(blob) {
var buffer = "New Text";
console.log(buffer, buffer.length);
Diff.blobToBuffer(blob, null, buffer, buffer.length, null, null, null, function() {
console.log('delta');
done();
}, null, null);
}, function(error) {
console.log('Error', error);
throw new Error(error);
})

return Diff.blobToBuffer(
blob,
null,
buffer,
null,
null,
null,
function() {
console.log("delta");
});
});
});

it("can diff with a null tree", function() {
Expand Down

0 comments on commit a0a1654

Please sign in to comment.