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

Convenience methods by johnhaley81 · Pull Request #297 · nodegit/nodegit · GitHub

Repository navigation

Merged
2 changes: 1 addition & 1 deletion .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/build/
/test/coverage/
/test/repos/
/test/test/repos/
/test/test/
/src/
/include/
/lib/enums.js
Expand Down
8 changes: 0 additions & 8 deletions example/create-new-repo.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,29 @@ var index;

fse.ensureDir(path.resolve(__dirname, repoDir))
.then(function() {
console.log('a');
return nodegit.Repository.init(path.resolve(__dirname, repoDir), 0);
})
.then(function(repo) {
console.log('b');
repository = repo;
return fse.writeFile(path.join(repository.workdir(), fileName), fileContent);
})
.then(function(){
console.log('c');
return repository.openIndex();
})
.then(function(idx) {
console.log('d');
index = idx;
return index.read(1);
})
.then(function() {
console.log('e');
return index.addByPath(fileName);
})
.then(function() {
console.log('f');
return index.write();
})
.then(function() {
console.log('g');
return index.writeTree();
})
.then(function(oid) {
console.log('j');
var author = nodegit.Signature.create("Scott Chacon", "schacon@gmail.com", 123456789, 60);
var committer = nodegit.Signature.create("Scott A Chacon", "scott@github.com", 987654321, 90);

Expand Down
3 changes: 1 addition & 2 deletions example/details-for-tree-entry.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ var path = require('path');

nodegit.Repository.open(path.resolve(__dirname, '../.git'))
.then(function(repo) {
return repo.getTree(
nodegit.Oid.fromString("e1b0c7ea57bfc5e30ec279402a98168a27838ac9"))
return repo.getTree("e1b0c7ea57bfc5e30ec279402a98168a27838ac9")
.then(function(tree) {
var treeEntry = tree.entryByIndex(0);

Expand Down
5 changes: 1 addition & 4 deletions example/fetch.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ var nodegit = require('../');
var path = require('path');

nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) {
return nodegit.Remote.load(repo, "origin");
}).then(function(remote) {
remote.connect(0);
return remote.download();
return repo.fetch("origin");
})
.done(function() {
console.log("It worked!");
Expand Down
3 changes: 3 additions & 0 deletions generate/combyne/filters/is_oid.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(arg) {
return arg.cppClassName == "GitOid" && !arg.isSelf && !arg.isReturn;
};
148 changes: 78 additions & 70 deletions generate/combyne/partials/async_function.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

{% partial doc . %}
{%partial doc .%}
NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
NanScope();
{% partial guardArguments . %}

{%partial guardArguments .%}
if (args.Length() == {{args|jsArgsCount}} || !args[{{args|jsArgsCount}}]->IsFunction()) {
return NanThrowError("Callback is required and must be a Function.");
}
Expand All @@ -13,85 +12,90 @@ NAN_METHOD({{ cppClassName }}::{{ cppFunctionName }}) {
baton->error_code = GIT_OK;
baton->error = NULL;

{% each args|argsInfo as arg %}
{% if not arg.isReturn %}
{% if arg.isSelf %}
baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue();
{% elsif arg.name %}
{% partial convertFromV8 arg %}
{% if not arg.isPayload %}
baton->{{ arg.name }} = from_{{ arg.name }};
{% endif %}
{% endif %}
{% elsif arg.shouldAlloc %}
baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }}));
{% endif %}
{% endeach %}
{%each args|argsInfo as arg %}
{%if not arg.isReturn %}
{%if arg.isSelf %}
baton->{{ arg.name }} = ObjectWrap::Unwrap<{{ arg.cppClassName }}>(args.This())->GetValue();
{%elsif arg.name %}
{%partial convertFromV8 arg%}
{%if not arg.isPayload %}
baton->{{ arg.name }} = from_{{ arg.name }};
{%if arg | isOid %}
baton->{{ arg.name }}NeedsFree = args[{{ arg.jsArg }}]->IsString();
{%endif%}
{%endif%}
{%endif%}
{%elsif arg.shouldAlloc %}
baton->{{ arg.name }} = ({{ arg.cType }})malloc(sizeof({{ arg.cType|replace '*' '' }}));
{%endif%}
{%endeach%}

NanCallback *callback = new NanCallback(Local<Function>::Cast(args[{{args|jsArgsCount}}]));
{{ cppFunctionName }}Worker *worker = new {{ cppFunctionName }}Worker(baton, callback);
{% each args|argsInfo as arg %}
{% if not arg.isReturn %}
{% if arg.isSelf %}
{%each args|argsInfo as arg %}
{%if not arg.isReturn %}
{%if arg.isSelf %}
worker->SaveToPersistent("{{ arg.name }}", args.This());
{% else %}
{%else%}
if (!args[{{ arg.jsArg }}]->IsUndefined() && !args[{{ arg.jsArg }}]->IsNull())
worker->SaveToPersistent("{{ arg.name }}", args[{{ arg.jsArg }}]->ToObject());
{% endif %}
{% endif %}
{% endeach %}
{%endif%}
{%endif%}
{%endeach%}

NanAsyncQueueWorker(worker);
NanReturnUndefined();
}

// startexecute {{ cppFunctionName }}
void {{ cppClassName }}::{{ cppFunctionName }}Worker::Execute() {
{% if .|hasReturnType %}
{{ return.cType }} result = {{ cFunctionName }}
{% else %}
{{ cFunctionName }}
{% endif %}
(

{% each .args|argsInfo as arg %}
{% if arg.isReturn|and arg.cType|isDoublePointer %}&{% endif %}baton->{{ arg.name }}{% if not arg.lastArg %},{% endif %}
{% endeach %}
);

{% if return.isErrorCode %}
baton->error_code = result;

if (result != GIT_OK && giterr_last() != NULL) {
baton->error = git_error_dup(giterr_last());
}
{% elsif not return.cType == 'void' %}
baton->result = result;
{% endif %}
{%if .|hasReturnType %}
{{ return.cType }} result = {{ cFunctionName }}(
{%else%}
{{ cFunctionName }}(
{%endif%}
{%-- Insert Function Arguments --%}
{%each args|argsInfo as arg %}
{%-- turn the pointer into a ref --%}
{%if arg.isReturn|and arg.cType|isDoublePointer %}&{%endif%}baton->{{ arg.name }}{%if not arg.lastArg %},{%endif%}

{%endeach%}
);

{%if return.isErrorCode %}
baton->error_code = result;

if (result != GIT_OK && giterr_last() != NULL) {
baton->error = git_error_dup(giterr_last());
}

{%elsif not return.cType == 'void' %}

baton->result = result;

{%endif%}
}
// done

void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
TryCatch try_catch;

if (baton->error_code == GIT_OK) {
{% if not .|returnsCount %}
{%if not .|returnsCount %}
Handle<Value> result = NanUndefined();
{% else %}
{%else%}
Handle<Value> to;
{% if .|returnsCount > 1 %}
{%if .|returnsCount > 1 %}
Handle<Object> result = NanNew<Object>();
{% endif %}
{% each .|returnsInfo 0 1 as _return %}
{% partial convertToV8 _return %}
{% if .|returnsCount > 1 %}
{%endif%}
{%each .|returnsInfo 0 1 as _return %}
{%partial convertToV8 _return %}
{%if .|returnsCount > 1 %}
result->Set(NanNew<String>("{{ _return.returnNameOrName }}"), to);
{% endif %}
{% endeach %}
{% if .|returnsCount == 1 %}
{%endif%}
{%endeach%}
{%if .|returnsCount == 1 %}
Handle<Value> result = to;
{% endif %}
{% endif %}
{%endif%}
{%endif%}
Handle<Value> argv[2] = {
NanNull(),
result
Expand All @@ -110,26 +114,30 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
callback->Call(0, NULL);
}

{% each args as arg %}
{% if arg.shouldAlloc %}
{%each args as arg %}
{%if arg.shouldAlloc %}
free((void*)baton->{{ arg.name }});
{% endif %}
{% endeach %}
{%endif%}
{%endeach%}
}

if (try_catch.HasCaught()) {
node::FatalException(try_catch);
}

{% each args|argsInfo as arg %}
{% if arg.isCppClassStringOrArray %}
{% if arg.freeFunctionName %}
{%each args|argsInfo as arg %}
{%if arg.isCppClassStringOrArray %}
{%if arg.freeFunctionName %}
{{ arg.freeFunctionName }}(baton->{{ arg.name }});
{% else %}
{%else%}
free((void *)baton->{{ arg.name }});
{% endif %}
{% endif %}
{% endeach %}
{%endif%}
{%elsif arg | isOid %}
if (baton->{{ arg.name}}NeedsFree) {
free((void *)baton->{{ arg.name }});
}
{%endif%}
{%endeach%}

delete baton;
}
Loading

Back | FazBrowse Home | New Git URL