// This is a generated file, modify: generate/templates/class_content.cc. #include #include extern "C" { #include } #include "../include/functions/copy.h" #include "../include/annotated_commit.h" #include "../include/functions/sleep_for_ms.h" #include "../include/repository.h" #include "../include/oid.h" #include "../include/reference.h" #include using namespace std; using namespace v8; using namespace node; GitAnnotatedCommit::GitAnnotatedCommit(git_annotated_commit *raw, bool selfFreeing) { this->raw = raw; this->selfFreeing = selfFreeing; } GitAnnotatedCommit::~GitAnnotatedCommit() { if (this->selfFreeing) { git_annotated_commit_free(this->raw); this->raw = NULL; } // this will cause an error if you have a non-self-freeing object that also needs // to save values. Since the object that will eventually free the object has no // way of knowing to free these values. } void GitAnnotatedCommit::InitializeComponent(Local target) { Nan::HandleScope scope; Local tpl = Nan::New(JSNewFunction); tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(Nan::New("AnnotatedCommit").ToLocalChecked()); Nan::SetPrototypeMethod(tpl, "free", Free); Nan::SetMethod(tpl, "fromFetchhead", FromFetchhead); Nan::SetMethod(tpl, "fromRef", FromRef); Nan::SetMethod(tpl, "fromRevspec", FromRevspec); Nan::SetPrototypeMethod(tpl, "id", Id); Nan::SetMethod(tpl, "lookup", Lookup); Local _constructor_template = Nan::GetFunction(tpl).ToLocalChecked(); constructor_template.Reset(_constructor_template); Nan::Set(target, Nan::New("AnnotatedCommit").ToLocalChecked(), _constructor_template); } NAN_METHOD(GitAnnotatedCommit::JSNewFunction) { if (info.Length() == 0 || !info[0]->IsExternal()) { return Nan::ThrowError("A new GitAnnotatedCommit cannot be instantiated."); } GitAnnotatedCommit* object = new GitAnnotatedCommit(static_cast(Local::Cast(info[0])->Value()), Nan::To(info[1]).FromJust()); object->Wrap(info.This()); info.GetReturnValue().Set(info.This()); } Local GitAnnotatedCommit::New(void *raw, bool selfFreeing) { Nan::EscapableHandleScope scope; Local argv[2] = { Nan::New((void *)raw), Nan::New(selfFreeing) }; return scope.Escape(Nan::NewInstance(Nan::New(GitAnnotatedCommit::constructor_template), 2, argv).ToLocalChecked()); } git_annotated_commit *GitAnnotatedCommit::GetValue() { return this->raw; } git_annotated_commit **GitAnnotatedCommit::GetRefValue() { return this->raw == NULL ? NULL : &this->raw; } void GitAnnotatedCommit::ClearValue() { this->raw = NULL; } /* */ NAN_METHOD(GitAnnotatedCommit::Free) { Nan::EscapableHandleScope scope; if (Nan::ObjectWrap::Unwrap(info.This())->GetValue() != NULL) { git_annotated_commit_free( Nan::ObjectWrap::Unwrap(info.This())->GetValue() ); Nan::ObjectWrap::Unwrap(info.This())->ClearValue(); } return info.GetReturnValue().Set(scope.Escape(Nan::Undefined())); } /* * @param Repository repo * @param String branch_name * @param String remote_url * @param Oid id * @param AnnotatedCommit callback */ NAN_METHOD(GitAnnotatedCommit::FromFetchhead) { if (info.Length() == 0 || !info[0]->IsObject()) { return Nan::ThrowError("Repository repo is required."); } if (info.Length() == 1 || !info[1]->IsString()) { return Nan::ThrowError("String branch_name is required."); } if (info.Length() == 2 || !info[2]->IsString()) { return Nan::ThrowError("String remote_url is required."); } if (info.Length() == 3 || (!info[3]->IsObject() && !info[3]->IsString())) { return Nan::ThrowError("Oid id is required."); } if (info.Length() == 4 || !info[4]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } FromFetchheadBaton* baton = new FromFetchheadBaton; baton->error_code = GIT_OK; baton->error = NULL; // start convert_from_v8 block git_repository * from_repo; from_repo = Nan::ObjectWrap::Unwrap(info[0]->ToObject())->GetValue(); // end convert_from_v8 block baton->repo = from_repo; // start convert_from_v8 block const char * from_branch_name; String::Utf8Value branch_name(info[1]->ToString()); from_branch_name = (const char *) strdup(*branch_name); // end convert_from_v8 block baton->branch_name = from_branch_name; // start convert_from_v8 block const char * from_remote_url; String::Utf8Value remote_url(info[2]->ToString()); from_remote_url = (const char *) strdup(*remote_url); // end convert_from_v8 block baton->remote_url = from_remote_url; // start convert_from_v8 block const git_oid * from_id; if (info[3]->IsString()) { // Try and parse in a string to a git_oid String::Utf8Value oidString(info[3]->ToString()); git_oid *oidOut = (git_oid *)malloc(sizeof(git_oid)); if (git_oid_fromstr(oidOut, (const char *) strdup(*oidString)) != GIT_OK) { free(oidOut); if (giterr_last()) { return Nan::ThrowError(giterr_last()->message); } else { return Nan::ThrowError("Unknown Error"); } } from_id = oidOut; } else { from_id = Nan::ObjectWrap::Unwrap(info[3]->ToObject())->GetValue(); } // end convert_from_v8 block baton->id = from_id; baton->idNeedsFree = info[3]->IsString(); Nan::Callback *callback = new Nan::Callback(Local::Cast(info[4])); FromFetchheadWorker *worker = new FromFetchheadWorker(baton, callback); if (!info[0]->IsUndefined() && !info[0]->IsNull()) worker->SaveToPersistent("repo", info[0]->ToObject()); if (!info[1]->IsUndefined() && !info[1]->IsNull()) worker->SaveToPersistent("branch_name", info[1]->ToObject()); if (!info[2]->IsUndefined() && !info[2]->IsNull()) worker->SaveToPersistent("remote_url", info[2]->ToObject()); if (!info[3]->IsUndefined() && !info[3]->IsNull()) worker->SaveToPersistent("id", info[3]->ToObject()); Nan::AsyncQueueWorker(worker); return; } void GitAnnotatedCommit::FromFetchheadWorker::Execute() { int result = git_annotated_commit_from_fetchhead( &baton->out,baton->repo,baton->branch_name,baton->remote_url,baton->id ); baton->error_code = result; if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } void GitAnnotatedCommit::FromFetchheadWorker::HandleOKCallback() { if (baton->error_code == GIT_OK) { Local to; // start convert_to_v8 block if (baton->out != NULL) { // GitAnnotatedCommit baton->out to = GitAnnotatedCommit::New((void *)baton->out, false); } else { to = Nan::Null(); } // end convert_to_v8 block Local result = to; Local argv[2] = { Nan::Null(), result }; callback->Call(2, argv); } else { if (baton->error) { Local argv[1] = { Nan::Error(baton->error->message) }; callback->Call(1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else if (baton->error_code < 0) { std::queue< Local > workerArguments; workerArguments.push(GetFromPersistent("repo")); workerArguments.push(GetFromPersistent("branch_name")); workerArguments.push(GetFromPersistent("remote_url")); workerArguments.push(GetFromPersistent("id")); bool callbackFired = false; while(!workerArguments.empty()) { Local node = workerArguments.front(); workerArguments.pop(); if ( !node->IsObject() || node->IsArray() || node->IsBooleanObject() || node->IsDate() || node->IsFunction() || node->IsNumberObject() || node->IsRegExp() || node->IsStringObject() ) { continue; } Local nodeObj = node->ToObject(); Local checkValue = nodeObj->GetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked()); if (!checkValue.IsEmpty() && !checkValue->IsNull() && !checkValue->IsUndefined()) { Local argv[1] = { checkValue->ToObject() }; callback->Call(1, argv); callbackFired = true; break; } Local properties = nodeObj->GetPropertyNames(); for (unsigned int propIndex = 0; propIndex < properties->Length(); ++propIndex) { Local propName = properties->Get(propIndex)->ToString(); Local nodeToQueue = nodeObj->Get(propName); if (!nodeToQueue->IsUndefined()) { workerArguments.push(nodeToQueue); } } } if (!callbackFired) { Local err = Nan::Error("Method fromFetchhead has thrown an error.")->ToObject(); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); Local argv[1] = { err }; callback->Call(1, argv); } } else { callback->Call(0, NULL); } } free((void *)baton->branch_name); free((void *)baton->remote_url); if (baton->idNeedsFree) { baton->idNeedsFree = false; free((void *)baton->id); } delete baton; } /* * @param Repository repo * @param Reference ref * @param AnnotatedCommit callback */ NAN_METHOD(GitAnnotatedCommit::FromRef) { if (info.Length() == 0 || !info[0]->IsObject()) { return Nan::ThrowError("Repository repo is required."); } if (info.Length() == 1 || !info[1]->IsObject()) { return Nan::ThrowError("Reference ref is required."); } if (info.Length() == 2 || !info[2]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } FromRefBaton* baton = new FromRefBaton; baton->error_code = GIT_OK; baton->error = NULL; // start convert_from_v8 block git_repository * from_repo; from_repo = Nan::ObjectWrap::Unwrap(info[0]->ToObject())->GetValue(); // end convert_from_v8 block baton->repo = from_repo; // start convert_from_v8 block const git_reference * from_ref; from_ref = Nan::ObjectWrap::Unwrap(info[1]->ToObject())->GetValue(); // end convert_from_v8 block baton->ref = from_ref; Nan::Callback *callback = new Nan::Callback(Local::Cast(info[2])); FromRefWorker *worker = new FromRefWorker(baton, callback); if (!info[0]->IsUndefined() && !info[0]->IsNull()) worker->SaveToPersistent("repo", info[0]->ToObject()); if (!info[1]->IsUndefined() && !info[1]->IsNull()) worker->SaveToPersistent("ref", info[1]->ToObject()); Nan::AsyncQueueWorker(worker); return; } void GitAnnotatedCommit::FromRefWorker::Execute() { int result = git_annotated_commit_from_ref( &baton->out,baton->repo,baton->ref ); baton->error_code = result; if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } void GitAnnotatedCommit::FromRefWorker::HandleOKCallback() { if (baton->error_code == GIT_OK) { Local to; // start convert_to_v8 block if (baton->out != NULL) { // GitAnnotatedCommit baton->out to = GitAnnotatedCommit::New((void *)baton->out, false); } else { to = Nan::Null(); } // end convert_to_v8 block Local result = to; Local argv[2] = { Nan::Null(), result }; callback->Call(2, argv); } else { if (baton->error) { Local argv[1] = { Nan::Error(baton->error->message) }; callback->Call(1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else if (baton->error_code < 0) { std::queue< Local > workerArguments; workerArguments.push(GetFromPersistent("repo")); workerArguments.push(GetFromPersistent("ref")); bool callbackFired = false; while(!workerArguments.empty()) { Local node = workerArguments.front(); workerArguments.pop(); if ( !node->IsObject() || node->IsArray() || node->IsBooleanObject() || node->IsDate() || node->IsFunction() || node->IsNumberObject() || node->IsRegExp() || node->IsStringObject() ) { continue; } Local nodeObj = node->ToObject(); Local checkValue = nodeObj->GetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked()); if (!checkValue.IsEmpty() && !checkValue->IsNull() && !checkValue->IsUndefined()) { Local argv[1] = { checkValue->ToObject() }; callback->Call(1, argv); callbackFired = true; break; } Local properties = nodeObj->GetPropertyNames(); for (unsigned int propIndex = 0; propIndex < properties->Length(); ++propIndex) { Local propName = properties->Get(propIndex)->ToString(); Local nodeToQueue = nodeObj->Get(propName); if (!nodeToQueue->IsUndefined()) { workerArguments.push(nodeToQueue); } } } if (!callbackFired) { Local err = Nan::Error("Method fromRef has thrown an error.")->ToObject(); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); Local argv[1] = { err }; callback->Call(1, argv); } } else { callback->Call(0, NULL); } } delete baton; } /* * @param Repository repo * @param String revspec * @param AnnotatedCommit callback */ NAN_METHOD(GitAnnotatedCommit::FromRevspec) { if (info.Length() == 0 || !info[0]->IsObject()) { return Nan::ThrowError("Repository repo is required."); } if (info.Length() == 1 || !info[1]->IsString()) { return Nan::ThrowError("String revspec is required."); } if (info.Length() == 2 || !info[2]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } FromRevspecBaton* baton = new FromRevspecBaton; baton->error_code = GIT_OK; baton->error = NULL; // start convert_from_v8 block git_repository * from_repo; from_repo = Nan::ObjectWrap::Unwrap(info[0]->ToObject())->GetValue(); // end convert_from_v8 block baton->repo = from_repo; // start convert_from_v8 block const char * from_revspec; String::Utf8Value revspec(info[1]->ToString()); from_revspec = (const char *) strdup(*revspec); // end convert_from_v8 block baton->revspec = from_revspec; Nan::Callback *callback = new Nan::Callback(Local::Cast(info[2])); FromRevspecWorker *worker = new FromRevspecWorker(baton, callback); if (!info[0]->IsUndefined() && !info[0]->IsNull()) worker->SaveToPersistent("repo", info[0]->ToObject()); if (!info[1]->IsUndefined() && !info[1]->IsNull()) worker->SaveToPersistent("revspec", info[1]->ToObject()); Nan::AsyncQueueWorker(worker); return; } void GitAnnotatedCommit::FromRevspecWorker::Execute() { int result = git_annotated_commit_from_revspec( &baton->out,baton->repo,baton->revspec ); baton->error_code = result; if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } void GitAnnotatedCommit::FromRevspecWorker::HandleOKCallback() { if (baton->error_code == GIT_OK) { Local to; // start convert_to_v8 block if (baton->out != NULL) { // GitAnnotatedCommit baton->out to = GitAnnotatedCommit::New((void *)baton->out, false); } else { to = Nan::Null(); } // end convert_to_v8 block Local result = to; Local argv[2] = { Nan::Null(), result }; callback->Call(2, argv); } else { if (baton->error) { Local argv[1] = { Nan::Error(baton->error->message) }; callback->Call(1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else if (baton->error_code < 0) { std::queue< Local > workerArguments; workerArguments.push(GetFromPersistent("repo")); workerArguments.push(GetFromPersistent("revspec")); bool callbackFired = false; while(!workerArguments.empty()) { Local node = workerArguments.front(); workerArguments.pop(); if ( !node->IsObject() || node->IsArray() || node->IsBooleanObject() || node->IsDate() || node->IsFunction() || node->IsNumberObject() || node->IsRegExp() || node->IsStringObject() ) { continue; } Local nodeObj = node->ToObject(); Local checkValue = nodeObj->GetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked()); if (!checkValue.IsEmpty() && !checkValue->IsNull() && !checkValue->IsUndefined()) { Local argv[1] = { checkValue->ToObject() }; callback->Call(1, argv); callbackFired = true; break; } Local properties = nodeObj->GetPropertyNames(); for (unsigned int propIndex = 0; propIndex < properties->Length(); ++propIndex) { Local propName = properties->Get(propIndex)->ToString(); Local nodeToQueue = nodeObj->Get(propName); if (!nodeToQueue->IsUndefined()) { workerArguments.push(nodeToQueue); } } } if (!callbackFired) { Local err = Nan::Error("Method fromRevspec has thrown an error.")->ToObject(); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); Local argv[1] = { err }; callback->Call(1, argv); } } else { callback->Call(0, NULL); } } free((void *)baton->revspec); delete baton; } /* * @return Oid result */ NAN_METHOD(GitAnnotatedCommit::Id) { Nan::EscapableHandleScope scope; const git_oid * result = git_annotated_commit_id( Nan::ObjectWrap::Unwrap(info.This())->GetValue() ); // null checks on pointers if (!result) { return info.GetReturnValue().Set(scope.Escape(Nan::Undefined())); } Local to; // start convert_to_v8 block if (result != NULL) { // GitOid result to = GitOid::New((void *)result, false); } else { to = Nan::Null(); } // end convert_to_v8 block return info.GetReturnValue().Set(scope.Escape(to)); } /* * @param Repository repo * @param Oid id * @param AnnotatedCommit callback */ NAN_METHOD(GitAnnotatedCommit::Lookup) { if (info.Length() == 0 || !info[0]->IsObject()) { return Nan::ThrowError("Repository repo is required."); } if (info.Length() == 1 || (!info[1]->IsObject() && !info[1]->IsString())) { return Nan::ThrowError("Oid id is required."); } if (info.Length() == 2 || !info[2]->IsFunction()) { return Nan::ThrowError("Callback is required and must be a Function."); } LookupBaton* baton = new LookupBaton; baton->error_code = GIT_OK; baton->error = NULL; // start convert_from_v8 block git_repository * from_repo; from_repo = Nan::ObjectWrap::Unwrap(info[0]->ToObject())->GetValue(); // end convert_from_v8 block baton->repo = from_repo; // start convert_from_v8 block const git_oid * from_id; if (info[1]->IsString()) { // Try and parse in a string to a git_oid String::Utf8Value oidString(info[1]->ToString()); git_oid *oidOut = (git_oid *)malloc(sizeof(git_oid)); if (git_oid_fromstr(oidOut, (const char *) strdup(*oidString)) != GIT_OK) { free(oidOut); if (giterr_last()) { return Nan::ThrowError(giterr_last()->message); } else { return Nan::ThrowError("Unknown Error"); } } from_id = oidOut; } else { from_id = Nan::ObjectWrap::Unwrap(info[1]->ToObject())->GetValue(); } // end convert_from_v8 block baton->id = from_id; baton->idNeedsFree = info[1]->IsString(); Nan::Callback *callback = new Nan::Callback(Local::Cast(info[2])); LookupWorker *worker = new LookupWorker(baton, callback); if (!info[0]->IsUndefined() && !info[0]->IsNull()) worker->SaveToPersistent("repo", info[0]->ToObject()); if (!info[1]->IsUndefined() && !info[1]->IsNull()) worker->SaveToPersistent("id", info[1]->ToObject()); Nan::AsyncQueueWorker(worker); return; } void GitAnnotatedCommit::LookupWorker::Execute() { int result = git_annotated_commit_lookup( &baton->out,baton->repo,baton->id ); baton->error_code = result; if (result != GIT_OK && giterr_last() != NULL) { baton->error = git_error_dup(giterr_last()); } } void GitAnnotatedCommit::LookupWorker::HandleOKCallback() { if (baton->error_code == GIT_OK) { Local to; // start convert_to_v8 block if (baton->out != NULL) { // GitAnnotatedCommit baton->out to = GitAnnotatedCommit::New((void *)baton->out, false); } else { to = Nan::Null(); } // end convert_to_v8 block Local result = to; Local argv[2] = { Nan::Null(), result }; callback->Call(2, argv); } else { if (baton->error) { Local argv[1] = { Nan::Error(baton->error->message) }; callback->Call(1, argv); if (baton->error->message) free((void *)baton->error->message); free((void *)baton->error); } else if (baton->error_code < 0) { std::queue< Local > workerArguments; workerArguments.push(GetFromPersistent("repo")); workerArguments.push(GetFromPersistent("id")); bool callbackFired = false; while(!workerArguments.empty()) { Local node = workerArguments.front(); workerArguments.pop(); if ( !node->IsObject() || node->IsArray() || node->IsBooleanObject() || node->IsDate() || node->IsFunction() || node->IsNumberObject() || node->IsRegExp() || node->IsStringObject() ) { continue; } Local nodeObj = node->ToObject(); Local checkValue = nodeObj->GetHiddenValue(Nan::New("NodeGitPromiseError").ToLocalChecked()); if (!checkValue.IsEmpty() && !checkValue->IsNull() && !checkValue->IsUndefined()) { Local argv[1] = { checkValue->ToObject() }; callback->Call(1, argv); callbackFired = true; break; } Local properties = nodeObj->GetPropertyNames(); for (unsigned int propIndex = 0; propIndex < properties->Length(); ++propIndex) { Local propName = properties->Get(propIndex)->ToString(); Local nodeToQueue = nodeObj->Get(propName); if (!nodeToQueue->IsUndefined()) { workerArguments.push(nodeToQueue); } } } if (!callbackFired) { Local err = Nan::Error("Method lookup has thrown an error.")->ToObject(); err->Set(Nan::New("errno").ToLocalChecked(), Nan::New(baton->error_code)); Local argv[1] = { err }; callback->Call(1, argv); } } else { callback->Call(0, NULL); } } if (baton->idNeedsFree) { baton->idNeedsFree = false; free((void *)baton->id); } delete baton; } Nan::Persistent GitAnnotatedCommit::constructor_template;