FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #550 from bleathem/blobToBuffer · nodegit/nodegit@dc5667b · GitHub

Repository navigation

Commit dc5667b

Browse files
committed
Merge pull request #550 from bleathem/blobToBuffer
A wrapper for git_diff_blob_to_buffer
2 parents b641689 + 75cbff0 commit dc5667b

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

‎generate/input/descriptor.json‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,39 @@
524524
],
525525
"functions": {
526526
"git_diff_blob_to_buffer": {
527-
"ignore": true
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+
},
556+
"return": {
557+
"isErrorCode": true
558+
},
559+
"isAsync": true
528560
},
529561
"git_diff_blobs": {
530562
"ignore": true

‎lib/diff.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,31 @@ Diff.prototype.findSimilar = function(opts) {
6262
opts = normalizeOptions(opts, NodeGit.DiffFindOptions);
6363
return findSimilar.call(this, opts);
6464
};
65+
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+
78+
opts = normalizeOptions(opts, NodeGit.DiffOptions);
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);
92+
};

‎test/tests/diff.js‎

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

148+
it("can diff the contents of a file to a string", function(done) {
149+
this.repository.getBranchCommit("master")
150+
.then(function(commit) {
151+
return commit.getEntry("LICENSE");
152+
})
153+
.then(function(entry) {
154+
var _entry = entry;
155+
return _entry.getBlob();
156+
})
157+
.then(function(blob) {
158+
var buffer = "New Text";
159+
return Diff.blobToBuffer(
160+
blob,
161+
null,
162+
buffer,
163+
null,
164+
null,
165+
null,
166+
function(delta, hunk, payload) {
167+
assert.equal(hunk.oldStart(), 1);
168+
assert.equal(hunk.oldLines(), 19);
169+
assert.equal(hunk.newStart(), 1);
170+
assert.equal(hunk.newLines(), 1);
171+
assert.equal(
172+
hunk.header().substring(0, hunk.headerLen() - 1),
173+
"@@ -1,19 +1 @@"
174+
);
175+
done();
176+
});
177+
});
178+
});
179+
148180
it("can diff with a null tree", function() {
149181
var repo = this.repository;
150182
var tree = this.masterCommitTree;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL