Skip to content

Commit a0a1654

Browse files
author
John Haley
committed
Fix up Diff.blobToBuffer
1 parent b294842 commit a0a1654

File tree

3 files changed

+67
-17
lines changed

3 files changed

+67
-17
lines changed

generate/input/descriptor.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,35 @@
524524
],
525525
"functions": {
526526
"git_diff_blob_to_buffer": {
527+
"args": {
528+
"old_blob" : {
529+
"isOptional": true
530+
},
531+
"old_as_path" : {
532+
"isOptional": true
533+
},
534+
"buffer" : {
535+
"isOptional": true
536+
},
537+
"buffer_len" : {
538+
"isOptional": true
539+
},
540+
"buffer_as_path" : {
541+
"isOptional": true
542+
},
543+
"options" : {
544+
"isOptional": true
545+
},
546+
"file_cb" : {
547+
"isOptional": true
548+
},
549+
"hunk_cb" : {
550+
"isOptional": true
551+
},
552+
"line_cb" : {
553+
"isOptional": true
554+
}
555+
},
527556
"return": {
528557
"isErrorCode": true
529558
},

lib/diff.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,30 @@ Diff.prototype.findSimilar = function(opts) {
6363
return findSimilar.call(this, opts);
6464
};
6565

66-
var blobToBuffer = Diff.prototype.blobToBuffer;
67-
Diff.prototype.blobToBuffer = function(old_blob, old_as_path, buffer, buffer_length, buffer_as_path, opts, file_cb, hunk_cb, line_cb) {
68-
console.log("********************************");
66+
var blobToBuffer = Diff.blobToBuffer;
67+
Diff.blobToBuffer= function(
68+
old_blob,
69+
old_as_path,
70+
buffer,
71+
buffer_as_path,
72+
opts,
73+
file_cb,
74+
hunk_cb,
75+
line_cb) {
76+
var bufferLength = !buffer ? 0 : buffer.length;
77+
6978
opts = normalizeOptions(opts, NodeGit.DiffOptions);
70-
return blobToBuffer.call(this, old_blob, old_as_path, buffer, buffer_length, buffer_as_path, opts, file_cb, hunk_cb, line_cb);
79+
80+
return blobToBuffer.call(
81+
this,
82+
old_blob,
83+
old_as_path,
84+
buffer,
85+
bufferLength,
86+
buffer_as_path,
87+
opts,
88+
file_cb,
89+
hunk_cb,
90+
line_cb,
91+
null);
7192
};

test/tests/diff.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,28 +145,28 @@ describe("Diff", function() {
145145
});
146146
});
147147

148-
it("can diff the contents of a file to the index", function(done) {
148+
it("can diff the contents of a file to a string", function(done) {
149149
this.repository.getBranchCommit("master")
150150
.then(function(commit) {
151-
var difffile = "LICENSE";
152-
return commit.getEntry(difffile);
151+
return commit.getEntry("LICENSE");
153152
})
154153
.then(function(entry) {
155154
var _entry = entry;
156155
return _entry.getBlob();
157156
})
158157
.then(function(blob) {
159158
var buffer = "New Text";
160-
console.log(buffer, buffer.length);
161-
Diff.blobToBuffer(blob, null, buffer, buffer.length, null, null, null, function() {
162-
console.log('delta');
163-
done();
164-
}, null, null);
165-
}, function(error) {
166-
console.log('Error', error);
167-
throw new Error(error);
168-
})
169-
159+
return Diff.blobToBuffer(
160+
blob,
161+
null,
162+
buffer,
163+
null,
164+
null,
165+
null,
166+
function() {
167+
console.log("delta");
168+
});
169+
});
170170
});
171171

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

0 commit comments

Comments
 (0)