Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,7 @@
"ignore": true
},
"repository": {
"cacheResult": true,
"functions": {
"git_repository__cleanup": {
"ignore": true
Expand Down
1 change: 1 addition & 0 deletions 1 generate/scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ var Helpers = {
typeDef.filename = typeDef.typeName;
typeDef.isLibgitType = true;
typeDef.dependencies = [];
typeDef.cacheResult = Boolean(typeDefOverrides.cacheResult);
typeDef.selfFreeing = Boolean(typeDefOverrides.selfFreeing);

if (typeDefOverrides.freeFunctionName) {
Expand Down
41 changes: 40 additions & 1 deletion 41 generate/templates/partials/sync_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
{%partial doc .%}
NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
Nan::EscapableHandleScope scope;

{%if return.cacheResult %}
{{ cppClassName }} *thisObj = Nan::ObjectWrap::Unwrap<{{ cppClassName }}>(info.This());
return info.GetReturnValue().Set(scope.Escape(Nan::New(thisObj->{{ cppFunctionName }}_cachedResult)));
{% else %}
{%partial guardArguments .%}

{%each .|returnsInfo 'true' as _return %}
Expand Down Expand Up @@ -35,7 +40,7 @@ if (Nan::ObjectWrap::Unwrap<{{ cppClassName }}>(info.This())->GetValue() != NULL
{% endif %}

giterr_clear();

{
LockMaster lockMaster(true{%each args|argsInfo as arg %}
{%if arg.cType|isPointer%}{%if not arg.isReturn%}
Expand Down Expand Up @@ -125,4 +130,38 @@ if (Nan::ObjectWrap::Unwrap<{{ cppClassName }}>(info.This())->GetValue() != NULL
{%endif%}
{%endif%}
}
{%endif%}
}

{%if return.cacheResult %}
void {{ cppClassName }}::{{ cppFunctionName }}_cache() {
if (!raw) {
{{ cppFunctionName }}_cachedResult.Reset(Nan::Null());
return;
}

LockMaster lockMaster(true{%each args|argsInfo as arg %}
{%if arg.cType|isPointer%}{%if not arg.isReturn%}
,{%if arg.isSelf %}
raw
{%endif%}
{%endif%}{%endif%}
{%endeach%});

{{ return.cType }} result = {{ cFunctionName }}(
{%each args|argsInfo as arg %}
{%if arg.isSelf %}
raw
{%endif%}
{%endeach%}
);

Local<v8::Value> to;

{%each .|returnsInfo as _return %}
{%partial convertToV8 _return %}
{%endeach%}

{{ cppFunctionName }}_cachedResult.Reset(to);
}
{% endif %}
10 changes: 10 additions & 0 deletions 10 generate/templates/templates/class_content.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ using namespace node;
NonSelfFreeingConstructedCount++;
}


{%each functions as function%}
{%if not function.ignore %}
{%if not function.isAsync %}
{%if function.return.cacheResult %}
{{ function.cppFunctionName }}_cache(); // populate cached value
{%endif%}
{%endif%}
{%endif%}
{%endeach%}
}

{{ cppClassName }}::~{{ cppClassName }}() {
Expand Down
8 changes: 8 additions & 0 deletions 8 generate/templates/templates/class_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class {{ cppClassName }} : public Nan::ObjectWrap {
private:
{{ function.cppFunctionName }}Baton *baton;
};
{%else%}
{%if function.return.cacheResult %}
// For simple sync functions that return a wrapped object and pass `raw`
// as the the only parameter to libgit2, we cache the results.
// CopyablePersistentTraits are used to get the reset-on-destruct behavior.
void {{ function.cppFunctionName }}_cache();
Nan::Persistent<Value, Nan::CopyablePersistentTraits<Value> > {{ function.cppFunctionName }}_cachedResult;
{%endif%}
{%endif%}

static NAN_METHOD({{ function.cppFunctionName }});
Expand Down
6 changes: 6 additions & 0 deletions 6 test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ describe("Commit", function() {
assert.ok(owner instanceof Repository);
});

it("caches its owner", function() {
var owner = this.commit.owner();
var ownerAgain = this.commit.owner();
assert.ok(owner === ownerAgain);
});

it("can walk its repository's history", function(done) {
var historyCount = 0;
var expectedHistoryCount = 364;
Expand Down
2 changes: 1 addition & 1 deletion 2 test/tests/submodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe("Submodule", function() {
return reference.peel(NodeGit.Object.TYPE.COMMIT);
})
.then(function(commit) {
return submoduleRepo.createBranch("master", commit);
return submoduleRepo.createBranch("master", commit.id());
})
.then(function() {
return submodule.addFinalize();
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.