Skip to content

Commit 4c8f13f

Browse files
committed
Merge pull request #517 from nodegit/add-graph-ahead-behind
Add `Graph.aheadBehind` and tests
2 parents 9474379 + d0a018f commit 4c8f13f

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

generate/input/descriptor.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,20 @@
743743
"graph": {
744744
"functions": {
745745
"git_graph_ahead_behind": {
746-
"ignore": true
746+
"args": {
747+
"ahead": {
748+
"shouldAlloc": true,
749+
"isReturn": true
750+
},
751+
"behind": {
752+
"shouldAlloc": true,
753+
"isReturn": true
754+
}
755+
},
756+
"isAsync": true,
757+
"return": {
758+
"isErrorCode": true
759+
}
747760
}
748761
}
749762
},

generate/templates/filters/returns_info.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var isPointer = require("./is_pointer");
2+
13
module.exports = function(fn, argReturnsOnly, isAsync) {
24
var result = [];
35
var args = fn.args || [];
@@ -11,6 +13,10 @@ module.exports = function(fn, argReturnsOnly, isAsync) {
1113

1214
return_info.parsedName = isAsync ? "baton->" + return_info.name : return_info.name;
1315
return_info.isCppClassIntType = ~['Uint32', 'Int32'].indexOf(return_info.cppClassName);
16+
return_info.needsDereference
17+
= isAsync &&
18+
return_info.cppClassName == "Number" &&
19+
isPointer(return_info.cType);
1420
return_info.parsedClassName = (return_info.cppClassName || '').toLowerCase() + "_t";
1521
return_info.returnNameOrName = return_info.returnName || return_info.name;
1622
return_info.jsOrCppClassName = return_info.jsClassName || return_info.cppClassName;

generate/templates/partials/convert_to_v8.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
{% if isCppClassIntType %}
2323
to = NanNew<{{ cppClassName }}>(({{ parsedClassName }}){{= parsedName =}});
2424
{% else %}
25-
to = NanNew<{{ cppClassName }}>({{= parsedName =}});
25+
to = NanNew<{{ cppClassName }}>({% if needsDereference %}*{% endif %}{{= parsedName =}});
2626
{% endif %}
2727

2828
{% elsif cppClassName == 'External' %}

test/tests/graph.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var assert = require("assert");
2+
var path = require("path");
3+
var local = path.join.bind(path, __dirname);
4+
5+
describe("Graph", function() {
6+
var NodeGit = require("../../");
7+
var Repository = NodeGit.Repository;
8+
var Graph = NodeGit.Graph;
9+
10+
var reposPath = local("../repos/workdir");
11+
12+
beforeEach(function() {
13+
var test = this;
14+
15+
return Repository.open(reposPath)
16+
.then(function(repository) {
17+
test.repository = repository;
18+
});
19+
});
20+
21+
it("can get commits ahead/behind for 2 different commits", function() {
22+
return Graph.aheadBehind(
23+
this.repository,
24+
"32789a79e71fbc9e04d3eff7425e1771eb595150",
25+
"1729c73906bb8467f4095c2f4044083016b4dfde")
26+
.then(function(result) {
27+
assert.equal(result.ahead, 1);
28+
assert.equal(result.behind, 1);
29+
});
30+
});
31+
});

0 commit comments

Comments
 (0)