X Tutup
Skip to content
Open
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
76 changes: 72 additions & 4 deletions generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,10 @@
}
},
"git_index_new": {
"ignore": true
"isAsync": true,
"return": {
"isErrorCode": true
}
},
"git_index_open": {
"isAsync": true,
Expand Down Expand Up @@ -2264,7 +2267,36 @@
}
},
"mempack": {
"ignore": true
"cType": "git_odb_backend",
"cppClassName": "GitMempack",
"jsClassName": "Mempack",
"selfFreeing": false,
"cDependencies": [
"git2/sys/mempack.h"
],
"functions": {
"git_mempack_new": {
"ignore": true
},
"git_mempack_dump": {
"ignore": true
},
"git_mempack_reset": {
"args": {
"backend": {
"ignore": false,
"isSelf": true
}
}
},
"git_mempack_create": {
"args": {
"out": {
"ignore": false
}
}
}
}
},
"merge": {
"functions": {
Expand Down Expand Up @@ -2529,13 +2561,23 @@
},
"odb": {
"selfFreeing": true,
"dependencies": [
"../include/mempack.h"
],
"functions": {
"git_odb_add_alternate": {
"ignore": true
},
"git_odb_add_backend": {
"ignore": true
},
"git_odb_add_mempack_backend": {
"args": {
"backend": {
"ignore": false
}
}
},
"git_odb_add_disk_alternate": {
"isAsync": true,
"return": {
Expand Down Expand Up @@ -2578,7 +2620,19 @@
"ignore": true
},
"git_odb_hash": {
"ignore": true
"isAsync": true,
"args": {
"oid": {
"isReturn": true
},
"data": {
"cppClassName": "Wrapper",
"jsClassName": "Buffer"
}
},
"return": {
"isErrorCode": true
}
},
"git_odb_hashfile": {
"isAsync": true,
Expand Down Expand Up @@ -3749,7 +3803,21 @@
"ignore": true
},
"git_repository_hashfile": {
"ignore": true
"isAsync": true,
"args": {
"out": {
"isReturn": true
},
"repo": {
"isSelf": true
},
"as_path": {
"isOptional": true
}
},
"return": {
"isErrorCode": true
}
},
"git_repository_ident": {
"args": {
Expand Down
74 changes: 74 additions & 0 deletions generate/input/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,70 @@
"type": "int",
"isErrorCode": true
}
},
"git_mempack_create": {
"_wraps": "git_mempack_new (renamed to 'create' for JS convention)",
"args": [
{
"name": "out",
"type": "git_odb_backend **"
}
],
"type": "function",
"isManual": true,
"cFile": "generate/templates/manual/mempack/create.cc",
"isAsync": true,
"isPrototypeMethod": false,
"group": "mempack",
"return": {
"type": "int",
"isErrorCode": true
}
},
"git_mempack_reset": {
"args": [
{
"name": "backend",
"type": "git_odb_backend *"
}
],
"type": "function",
"isManual": true,
"cFile": "generate/templates/manual/mempack/reset.cc",
"isAsync": true,
"isPrototypeMethod": true,
"group": "mempack",
"return": {
"type": "int",
"isErrorCode": true
}
},
"git_odb_add_mempack_backend": {
"_wraps": "git_odb_add_backend (specialized for Mempack backends only)",
"args": [
{
"name": "odb",
"type": "git_odb *"
},
{
"name": "backend",
"type": "git_odb_backend *"
},
{
"name": "priority",
"type": "int"
}
],
"type": "function",
"isManual": true,
"cFile": "generate/templates/manual/odb/add_backend.cc",
"isAsync": true,
"isPrototypeMethod": true,
"group": "odb",
"return": {
"type": "int",
"isErrorCode": true
}
}
},
"groups": [
Expand Down Expand Up @@ -1735,6 +1799,13 @@
"git_tree_entry_to_object",
"git_tree_entry_type"
]
],
[
"mempack",
[
"git_mempack_create",
"git_mempack_reset"
]
]
],
"types": [
Expand Down Expand Up @@ -2682,6 +2753,9 @@
"git_note_next",
"git_note_read",
"git_note_remove"
],
"odb": [
"git_odb_add_mempack_backend"
]
}
}
5 changes: 5 additions & 0 deletions generate/templates/manual/include/odb_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Stub header for git_odb_backend - the type is already defined by git2.h
// This file exists to satisfy auto-generated #include dependencies.
#ifndef GITODB_BACKEND_H
#define GITODB_BACKEND_H
#endif
92 changes: 92 additions & 0 deletions generate/templates/manual/mempack/create.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Manual binding for git_mempack_new, exposed as Mempack.create()

NAN_METHOD(GitMempack::Create) {
if (!info[info.Length() - 1]->IsFunction()) {
return Nan::ThrowError("Callback is required and must be a Function.");
}

CreateBaton *baton = new CreateBaton();
baton->error_code = GIT_OK;
baton->error = NULL;
baton->out = NULL;

Nan::Callback *callback =
new Nan::Callback(v8::Local<Function>::Cast(info[info.Length() - 1]));
std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> cleanupHandles;
CreateWorker *worker = new CreateWorker(baton, callback, cleanupHandles);

nodegit::Context *nodegitContext = reinterpret_cast<nodegit::Context *>(info.Data().As<External>()->Value());
nodegitContext->QueueWorker(worker);
return;
}

nodegit::LockMaster GitMempack::CreateWorker::AcquireLocks() {
nodegit::LockMaster lockMaster(true);
return lockMaster;
}

void GitMempack::CreateWorker::Execute() {
git_error_clear();

baton->error_code = git_mempack_new(&baton->out);

if (baton->error_code != GIT_OK && git_error_last() != NULL && git_error_last()->klass != GIT_ERROR_NONE) {
baton->error = git_error_dup(git_error_last());
}
}

void GitMempack::CreateWorker::HandleErrorCallback() {
if (baton->error) {
if (baton->error->message) {
free((void *)baton->error->message);
}

free((void *)baton->error);
}

delete baton;
}

void GitMempack::CreateWorker::HandleOKCallback() {
if (baton->error_code == GIT_OK) {
if (baton->out == NULL) {
// This should never happen if error_code == GIT_OK
v8::Local<v8::Value> argv[1] = {Nan::Error("Mempack creation returned OK but produced no backend.")};
callback->Call(1, argv, async_resource);
delete baton;
return;
}

v8::Local<v8::Value> to = GitMempack::New(baton->out, false);
v8::Local<v8::Value> argv[2] = {Nan::Null(), to};
callback->Call(2, argv, async_resource);
} else if (baton->error) {
v8::Local<v8::Object> err;
if (baton->error->message) {
err = Nan::To<v8::Object>(Nan::Error(baton->error->message)).ToLocalChecked();
} else {
err = Nan::To<v8::Object>(Nan::Error("Method create has thrown an error.")).ToLocalChecked();
}
Nan::Set(err, Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code));
Nan::Set(err, Nan::New("errorFunction").ToLocalChecked(),
Nan::New("Mempack.create").ToLocalChecked());
v8::Local<v8::Value> argv[1] = {err};
callback->Call(1, argv, async_resource);
if (baton->error->message)
free((void *)baton->error->message);
free((void *)baton->error);
} else if (baton->error_code < 0) {
v8::Local<v8::Object> err =
Nan::To<v8::Object>(Nan::Error("Method create has thrown an error.")).ToLocalChecked();
Nan::Set(err, Nan::New("errno").ToLocalChecked(),
Nan::New(baton->error_code));
Nan::Set(err, Nan::New("errorFunction").ToLocalChecked(),
Nan::New("Mempack.create").ToLocalChecked());
v8::Local<v8::Value> argv[1] = {err};
callback->Call(1, argv, async_resource);
} else {
callback->Call(0, NULL, async_resource);
}

delete baton;
}
57 changes: 57 additions & 0 deletions generate/templates/manual/mempack/reset.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Manual binding for git_mempack_reset, exposed as Mempack.prototype.reset()

NAN_METHOD(GitMempack::Reset) {
if (!info[info.Length() - 1]->IsFunction()) {
return Nan::ThrowError("Callback is required and must be a Function.");
}

ResetBaton *baton = new ResetBaton();
baton->error_code = GIT_OK;
baton->error = NULL;
baton->backend = Nan::ObjectWrap::Unwrap<GitMempack>(info.This())->GetValue();

Nan::Callback *callback =
new Nan::Callback(v8::Local<Function>::Cast(info[info.Length() - 1]));
std::map<std::string, std::shared_ptr<nodegit::CleanupHandle>> cleanupHandles;
ResetWorker *worker = new ResetWorker(baton, callback, cleanupHandles);

worker->Reference<GitMempack>("backend", info.This());

nodegit::Context *nodegitContext = reinterpret_cast<nodegit::Context *>(info.Data().As<External>()->Value());
nodegitContext->QueueWorker(worker);
return;
}

nodegit::LockMaster GitMempack::ResetWorker::AcquireLocks() {
nodegit::LockMaster lockMaster(true, baton->backend);
return lockMaster;
}

void GitMempack::ResetWorker::Execute() {
git_error_clear();

baton->error_code = git_mempack_reset(baton->backend);

if (baton->error_code != GIT_OK && git_error_last() != NULL && git_error_last()->klass != GIT_ERROR_NONE) {
baton->error = git_error_dup(git_error_last());
}
}

void GitMempack::ResetWorker::HandleErrorCallback() {
if (baton->error) {
if (baton->error->message) {
free((void *)baton->error->message);
}

free((void *)baton->error);
}

delete baton;
}

void GitMempack::ResetWorker::HandleOKCallback() {
v8::Local<v8::Value> argv[1] = {Nan::Null()};
callback->Call(1, argv, async_resource);

delete baton;
}
Loading
X Tutup