Skip to content

Commit 89bc1a8

Browse files
committed
Implement isOptional.
1 parent efc794c commit 89bc1a8

4 files changed

Lines changed: 34 additions & 16 deletions

File tree

generate/descriptor.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,17 @@
126126
"diff": {
127127
"functions": {
128128
"git_diff_tree_to_tree": {
129-
"ignore": true,
130-
"args": [{ "isReturn": true }, { "isSelf": true }]
129+
"isAsync": true,
130+
"args": [
131+
{ "isReturn": true },
132+
{ "isSelf": true },
133+
{},
134+
{},
135+
{ "isOptional": true }
136+
],
137+
"return": {
138+
"isErrorCode": true
139+
}
131140
}
132141
}
133142
},

generate/setup.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ Object.keys(descriptor).forEach(function(fileName, index) {
247247
return file.jsClassName === typeMap[arg.type].js;
248248
};
249249

250+
var isOptional = function() {
251+
if (manualArgs[index] && typeof manualArgs[index].isOptional === "boolean") {
252+
return manualArgs[index].isOptional;
253+
}
254+
};
255+
250256
var isReturn = function() {
251257
if (manualArgs[index] && typeof manualArgs[index].isReturn === "boolean") {
252258
return manualArgs[index].isReturn;
@@ -273,6 +279,7 @@ Object.keys(descriptor).forEach(function(fileName, index) {
273279
cppClassName: typeMap[arg.type].cpp,
274280
jsClassName: typeMap[arg.type].js,
275281
comment: arg.comment,
282+
isOptional: isOptional() || true,
276283
isReturn: isReturn() || false,
277284
isSelf: isSelf() || false,
278285
shouldAlloc: manualArgs[index] ? manualArgs[index].shouldAlloc || false : false

lib/tree.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var git = require('../');
22
var Tree = git.Tree;
3+
var Diff = git.Diff;
4+
var DiffOptions = git.DiffOptions;
35
var TreeEntry = require('./tree_entry');
46
var events = require('events');
57
var path = require('path');
@@ -8,6 +10,7 @@ var oldBuilder = Tree.prototype.builder;
810
var oldEntryByIndex = Tree.prototype.entryByindex;
911
var oldEntryByName = Tree.prototype.entryByname;
1012
var oldGetEntry = Tree.prototype.entryBypath;
13+
var oldTreeToTree = Diff.prototype.treeToTree;
1114

1215
// Backwards compatibility.
1316
Object.defineProperties(Tree.prototype, {
@@ -23,8 +26,8 @@ Object.defineProperties(Tree.prototype, {
2326
* @param {Function} callback
2427
* @return {DiffList}
2528
*/
26-
Tree.prototype.diff = function(that, callback) {
27-
this.diffTree(this.repo, that, null, callback);
29+
Tree.prototype.diff = function(tree, callback) {
30+
oldTreeToTree.call(this.repo, tree, this, null, callback);
2831
};
2932

3033
/**

test/commit.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,17 @@ exports.tree = function(test) {
225225
/**
226226
* Test that getDiff works as expected.
227227
*/
228-
//exports.getDiff = function(test) {
229-
// test.expect(1);
230-
// git.Repo.open('repos/workdir/.git', function(error, repository) {
231-
// repository.getCommit(historyCountKnownSHA, function(error, commit) {
232-
// commit.getDiff(function(error, diff) {
233-
// console.log(error);
234-
// test.equals(diff.length, 1, 'Should be one item in parents diff trees');
235-
// test.done();
236-
// });
237-
// });
238-
// });
239-
//};
228+
exports.getDiff = function(test) {
229+
test.expect(1);
230+
git.Repo.open('repos/workdir/.git', function(error, repository) {
231+
repository.getCommit(historyCountKnownSHA, function(error, commit) {
232+
commit.getDiff(function(error, diff) {
233+
test.equals(diff.length, 1, 'Should be one item in parents diff trees');
234+
test.done();
235+
});
236+
});
237+
});
238+
};
240239

241240
process.on('uncaughtException', function(err) {
242241
console.log(err.stack);

0 commit comments

Comments
 (0)