/**
* This code is auto-generated; unless you know what you're doing, do not modify!
**/
#include
#include
#include
#include "git2.h"
#include "../include/functions/copy.h"
#include "../include/tree_builder.h"
#include "../include/repo.h"
#include "../include/oid.h"
#include "../include/tree_entry.h"
#include "../include/tree.h"
#include "../include/diff_list.h"
#include "../include/diff_options.h"
#include "../include/index.h"
using namespace v8;
using namespace node;
GitTreeBuilder::GitTreeBuilder(git_treebuilder *raw) {
this->raw = raw;
}
GitTreeBuilder::~GitTreeBuilder() {
git_treebuilder_free(this->raw);
}
void GitTreeBuilder::Initialize(Handle target) {
HandleScope scope;
Local tpl = FunctionTemplate::New(New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(String::NewSymbol("TreeBuilder"));
NODE_SET_METHOD(tpl, "create", Create);
NODE_SET_PROTOTYPE_METHOD(tpl, "clear", Clear);
NODE_SET_METHOD(tpl, "size", Size);
NODE_SET_PROTOTYPE_METHOD(tpl, "get", Get);
NODE_SET_PROTOTYPE_METHOD(tpl, "insert", Insert);
NODE_SET_PROTOTYPE_METHOD(tpl, "gitTreebuilderRemove", GitTreebuilderRemove);
NODE_SET_PROTOTYPE_METHOD(tpl, "write", Write);
constructor_template = Persistent::New(tpl->GetFunction());
target->Set(String::NewSymbol("TreeBuilder"), constructor_template);
}
Handle GitTreeBuilder::New(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsExternal()) {
return ThrowException(Exception::Error(String::New("git_treebuilder is required.")));
}
GitTreeBuilder* object = new GitTreeBuilder((git_treebuilder *) External::Unwrap(args[0]));
object->Wrap(args.This());
return scope.Close(args.This());
}
Handle GitTreeBuilder::New(void *raw) {
HandleScope scope;
Handle argv[1] = { External::New((void *)raw) };
return scope.Close(GitTreeBuilder::constructor_template->NewInstance(1, argv));
}
git_treebuilder *GitTreeBuilder::GetValue() {
return this->raw;
}
/**
* @param {Tree} source
* @return {TreeBuilder} out
*/
Handle GitTreeBuilder::Create(const Arguments& args) {
HandleScope scope;
git_treebuilder *out = NULL;
const git_tree * from_source;
if (args[0]->IsObject()) {
from_source = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue();
} else {
from_source = NULL;
}
int result = git_treebuilder_create(
&out
, from_source
);
if (result != GIT_OK) {
if (giterr_last()) {
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
} else {
return ThrowException(Exception::Error(String::New("Unkown Error")));
}
}
Handle to;
if (out != NULL) {
to = GitTreeBuilder::New((void *)out);
} else {
to = Null();
}
return scope.Close(to);
}
/**
* @param {TreeBuilder} bld
*/
Handle GitTreeBuilder::Clear(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsObject()) {
return ThrowException(Exception::Error(String::New("TreeBuilder bld is required.")));
}
git_treebuilder * from_bld;
from_bld = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue();
git_treebuilder_clear(
from_bld
);
return Undefined();
}
/**
* @return {Number} result
*/
Handle GitTreeBuilder::Size(const Arguments& args) {
HandleScope scope;
unsigned int result = git_treebuilder_entrycount(
ObjectWrap::Unwrap(args.This())->GetValue()
);
Handle to;
to = Uint32::New(result);
return scope.Close(to);
}
/**
* @param {String} filename
* @return {TreeEntry} result
*/
Handle GitTreeBuilder::Get(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsString()) {
return ThrowException(Exception::Error(String::New("String filename is required.")));
}
const char * from_filename;
String::Utf8Value filename(args[0]->ToString());
from_filename = strdup(*filename);
const git_tree_entry * result = git_treebuilder_get(
ObjectWrap::Unwrap(args.This())->GetValue()
, from_filename
);
free((void *)from_filename);
Handle to;
if (result != NULL) {
result = (const git_tree_entry * )git_tree_entry_dup(result);
}
if (result != NULL) {
to = GitTreeEntry::New((void *)result);
} else {
to = Null();
}
return scope.Close(to);
}
/**
* @param {String} filename
* @param {Oid} id
* @param {Number} filemode
* @return {TreeEntry} out
*/
Handle GitTreeBuilder::Insert(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsString()) {
return ThrowException(Exception::Error(String::New("String filename is required.")));
}
if (args.Length() == 1 || !args[1]->IsObject()) {
return ThrowException(Exception::Error(String::New("Oid id is required.")));
}
if (args.Length() == 2 || !args[2]->IsNumber()) {
return ThrowException(Exception::Error(String::New("Number filemode is required.")));
}
const git_tree_entry *out = NULL;
const char * from_filename;
String::Utf8Value filename(args[0]->ToString());
from_filename = strdup(*filename);
const git_oid * from_id;
from_id = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue();
git_filemode_t from_filemode;
from_filemode = (git_filemode_t) args[2]->ToNumber()->Value();
int result = git_treebuilder_insert(
&out
, ObjectWrap::Unwrap(args.This())->GetValue()
, from_filename
, from_id
, from_filemode
);
free((void *)from_filename);
if (result != GIT_OK) {
if (giterr_last()) {
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
} else {
return ThrowException(Exception::Error(String::New("Unkown Error")));
}
}
Handle to;
if (out != NULL) {
out = (const git_tree_entry * )git_tree_entry_dup(out);
}
if (out != NULL) {
to = GitTreeEntry::New((void *)out);
} else {
to = Null();
}
return scope.Close(to);
}
/**
* @param {String} filename
*/
Handle GitTreeBuilder::GitTreebuilderRemove(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsString()) {
return ThrowException(Exception::Error(String::New("String filename is required.")));
}
const char * from_filename;
String::Utf8Value filename(args[0]->ToString());
from_filename = strdup(*filename);
int result = git_treebuilder_remove(
ObjectWrap::Unwrap(args.This())->GetValue()
, from_filename
);
free((void *)from_filename);
if (result != GIT_OK) {
if (giterr_last()) {
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
} else {
return ThrowException(Exception::Error(String::New("Unkown Error")));
}
}
return Undefined();
}
/**
* @param {Repository} repo
* @param {Oid} callback
*/
Handle GitTreeBuilder::Write(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsObject()) {
return ThrowException(Exception::Error(String::New("Repository repo is required.")));
}
if (args.Length() == 1 || !args[1]->IsFunction()) {
return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
}
WriteBaton* baton = new WriteBaton;
baton->error_code = GIT_OK;
baton->error = NULL;
baton->request.data = baton;
baton->id = (git_oid *)malloc(sizeof(git_oid ));
baton->repoReference = Persistent::New(args[0]);
git_repository * from_repo;
from_repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue();
baton->repo = from_repo;
baton->bldReference = Persistent::New(args.This());
baton->bld = ObjectWrap::Unwrap(args.This())->GetValue();
baton->callback = Persistent::New(Local::Cast(args[1]));
uv_queue_work(uv_default_loop(), &baton->request, WriteWork, (uv_after_work_cb)WriteAfterWork);
return Undefined();
}
void GitTreeBuilder::WriteWork(uv_work_t *req) {
WriteBaton *baton = static_cast(req->data);
int result = git_treebuilder_write(
baton->id,
baton->repo,
baton->bld
);
baton->error_code = result;
if (result != GIT_OK) {
baton->error = giterr_last();
}
}
void GitTreeBuilder::WriteAfterWork(uv_work_t *req) {
HandleScope scope;
WriteBaton *baton = static_cast(req->data);
TryCatch try_catch;
if (baton->error_code == GIT_OK) {
Handle to;
if (baton->id != NULL) {
to = GitOid::New((void *)baton->id);
} else {
to = Null();
}
Handle result = to;
Handle argv[2] = {
Local::New(Null()),
result
};
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
} else {
if (baton->error) {
Handle argv[1] = {
Exception::Error(String::New(baton->error->message))
};
baton->callback->Call(Context::GetCurrent()->Global(), 1, argv);
} else {
baton->callback->Call(Context::GetCurrent()->Global(), 0, NULL);
}
free(baton->id);
}
if (try_catch.HasCaught()) {
node::FatalException(try_catch);
}
baton->repoReference.Dispose();
baton->bldReference.Dispose();
baton->callback.Dispose();
delete baton;
}
Persistent GitTreeBuilder::constructor_template;