// This is a generated file, modify: generate/templates/class_content.cc.
#include <nan.h>
#include <string.h>

extern "C" {
#include <git2.h>
}


#include "../include/functions/copy.h"
#include "../include/macros.h"
#include "../include/object.h"

#include "../include/object.h"
#include "../include/oid.h"
#include "../include/repository.h"
#include "../include/buf.h"

#include <iostream>

using namespace std;
using namespace v8;
using namespace node;

GitObject::GitObject(git_object *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitObject::~GitObject()
{
  if (this->selfFreeing) {
    git_object_free(this->raw);
  }
}

void GitObject::InitializeComponent(Handle<v8::Object> target)
{
  NanScope();

  Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(JSNewFunction);

  tpl->InstanceTemplate()->SetInternalFieldCount(1);
  tpl->SetClassName(NanNew<String>("Object"));

  NODE_SET_METHOD(tpl, "size", Size);
  NODE_SET_PROTOTYPE_METHOD(tpl, "dup", Dup);
  NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id);
  NODE_SET_METHOD(tpl, "lookup", Lookup);
  NODE_SET_PROTOTYPE_METHOD(tpl, "lookupByPath", LookupBypath);
  NODE_SET_METHOD(tpl, "lookupPrefix", LookupPrefix);
  NODE_SET_PROTOTYPE_METHOD(tpl, "owner", Owner);
  NODE_SET_PROTOTYPE_METHOD(tpl, "peel", Peel);
  NODE_SET_PROTOTYPE_METHOD(tpl, "shortId", ShortId);
  NODE_SET_METHOD(tpl, "string2type", String2type);
  NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type);
  NODE_SET_METHOD(tpl, "type2string", Type2string);
  NODE_SET_METHOD(tpl, "typeisloose", Typeisloose);

  Local<Function> _constructor_template = tpl->GetFunction();
  NanAssignPersistent(constructor_template, _constructor_template);
  target->Set(NanNew<String>("Object"), _constructor_template);
}

NAN_METHOD(GitObject::JSNewFunction)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsExternal()) {
    return NanThrowError("A new GitObject cannot be instantiated.");
  }

  GitObject* object = new GitObject(static_cast<git_object *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue());
  object->Wrap(args.This());

  NanReturnValue(args.This());
}

Handle<Value> GitObject::New(void *raw, bool selfFreeing)
{
  NanEscapableScope();
  Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) };
  return NanEscapeScope(NanNew<Function>(GitObject::constructor_template)->NewInstance(2, argv));
}

git_object *GitObject::GetValue()
{
  return this->raw;
}

git_object **GitObject::GetRefValue()
{
  return &this->raw;
}


/*
 * @param Number type
     * @return Number  result    */
NAN_METHOD(GitObject::Size)
{
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsNumber()) {
    return NanThrowError("Number type is required.");
  }

// start convert_from_v8 block
  git_otype from_type;
  from_type = (git_otype)  (int) args[0]->ToNumber()->Value();
// end convert_from_v8 block
  size_t result = git_object__size(
                    from_type
                  );

  Handle<Value> to;
// start convert_to_v8 block
  to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}

/*
     * @param Object callback
   */
NAN_METHOD(GitObject::Dup)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsFunction()) {
    return NanThrowError("Callback is required and must be a Function.");
  }

  DupBaton* baton = new DupBaton;

  baton->error_code = GIT_OK;
  baton->error = NULL;

  baton->source = ObjectWrap::Unwrap<GitObject>(args.This())->GetValue();

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[0]));
  DupWorker *worker = new DupWorker(baton, callback);
  worker->SaveToPersistent("source", args.This());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitObject::DupWorker::Execute()
{
  int result = git_object_dup(
                 &baton->dest,baton->source    );

  baton->error_code = result;

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

}

void GitObject::DupWorker::HandleOKCallback()
{
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block

    if (baton->dest != NULL) {
      // GitObject baton->dest
      to = GitObject::New((void *)baton->dest, false);
    } else {
      to = NanNull();
    }

// end convert_to_v8 block
    Handle<Value> result = to;
    Handle<Value> argv[2] = {
      NanNull(),
      result
    };
    callback->Call(2, argv);
  } else {
    if (baton->error) {
      Handle<Value> argv[1] = {
        NanError(baton->error->message)
      };
      callback->Call(1, argv);
      if (baton->error->message)
        free((void *)baton->error->message);
      free((void *)baton->error);
    } else {
      callback->Call(0, NULL);
    }

  }

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


  delete baton;
}

/*
     * @return Oid  result    */
NAN_METHOD(GitObject::Id)
{
  NanEscapableScope();

  const git_oid * result = git_object_id(
                             ObjectWrap::Unwrap<GitObject>(args.This())->GetValue()
                           );
  // null checks on pointers
  if (!result) {
    NodeGitPsueodoNanReturnEscapingValue(NanUndefined());
  }

  Handle<Value> to;
// start convert_to_v8 block

  if (result != NULL) {
    // GitOid result
    to = GitOid::New((void *)result, false);
  } else {
    to = NanNull();
  }

// end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}

/*
  * @param Repository repo
   * @param Oid id
   * @param Number type
    * @param Object callback
   */
NAN_METHOD(GitObject::Lookup)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsObject()) {
    return NanThrowError("Repository repo is required.");
  }

  if (args.Length() == 1
      || (!args[1]->IsObject() && !args[1]->IsString())) {
    return NanThrowError("Oid id is required.");
  }

  if (args.Length() == 2 || !args[2]->IsNumber()) {
    return NanThrowError("Number type is required.");
  }

  if (args.Length() == 3 || !args[3]->IsFunction()) {
    return NanThrowError("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 = ObjectWrap::Unwrap<GitRepository>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  baton->repo = from_repo;
// start convert_from_v8 block
  const git_oid * from_id;
  if (args[1]->IsString()) {
    // Try and parse in a string to a git_oid
    String::Utf8Value oidString(args[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 NanThrowError(giterr_last()->message);
      } else {
        return NanThrowError("Unknown Error");
      }
    }

    from_id = oidOut;
  } else {
    from_id = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject())->GetValue();
  }
// end convert_from_v8 block
  baton->id = from_id;
  baton->idNeedsFree = args[1]->IsString();
// start convert_from_v8 block
  git_otype from_type;
  from_type = (git_otype)  (int) args[2]->ToNumber()->Value();
// end convert_from_v8 block
  baton->type = from_type;

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[3]));
  LookupWorker *worker = new LookupWorker(baton, callback);
  if (!args[0]->IsUndefined() && !args[0]->IsNull())
    worker->SaveToPersistent("repo", args[0]->ToObject());
  if (!args[1]->IsUndefined() && !args[1]->IsNull())
    worker->SaveToPersistent("id", args[1]->ToObject());
  if (!args[2]->IsUndefined() && !args[2]->IsNull())
    worker->SaveToPersistent("type", args[2]->ToObject());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitObject::LookupWorker::Execute()
{
  int result = git_object_lookup(
                 &baton->object,baton->repo,baton->id,baton->type    );

  baton->error_code = result;

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

}

void GitObject::LookupWorker::HandleOKCallback()
{
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block

    if (baton->object != NULL) {
      // GitObject baton->object
      to = GitObject::New((void *)baton->object, false);
    } else {
      to = NanNull();
    }

// end convert_to_v8 block
    Handle<Value> result = to;
    Handle<Value> argv[2] = {
      NanNull(),
      result
    };
    callback->Call(2, argv);
  } else {
    if (baton->error) {
      Handle<Value> argv[1] = {
        NanError(baton->error->message)
      };
      callback->Call(1, argv);
      if (baton->error->message)
        free((void *)baton->error->message);
      free((void *)baton->error);
    } else {
      callback->Call(0, NULL);
    }

  }

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

  if (baton->idNeedsFree) {
    baton->idNeedsFree = false;
    free((void *)baton->id);
  }

  delete baton;
}

/*
    * @param String path
   * @param Number type
    * @param Object callback
   */
NAN_METHOD(GitObject::LookupBypath)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsString()) {
    return NanThrowError("String path is required.");
  }

  if (args.Length() == 1 || !args[1]->IsNumber()) {
    return NanThrowError("Number type is required.");
  }

  if (args.Length() == 2 || !args[2]->IsFunction()) {
    return NanThrowError("Callback is required and must be a Function.");
  }

  LookupBypathBaton* baton = new LookupBypathBaton;

  baton->error_code = GIT_OK;
  baton->error = NULL;

  baton->treeish = ObjectWrap::Unwrap<GitObject>(args.This())->GetValue();
// start convert_from_v8 block
  const char * from_path;

  String::Utf8Value path(args[0]->ToString());
  from_path = (const char *) strdup(*path);
// end convert_from_v8 block
  baton->path = from_path;
// start convert_from_v8 block
  git_otype from_type;
  from_type = (git_otype)  (int) args[1]->ToNumber()->Value();
// end convert_from_v8 block
  baton->type = from_type;

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[2]));
  LookupBypathWorker *worker = new LookupBypathWorker(baton, callback);
  worker->SaveToPersistent("treeish", args.This());
  if (!args[0]->IsUndefined() && !args[0]->IsNull())
    worker->SaveToPersistent("path", args[0]->ToObject());
  if (!args[1]->IsUndefined() && !args[1]->IsNull())
    worker->SaveToPersistent("type", args[1]->ToObject());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitObject::LookupBypathWorker::Execute()
{
  int result = git_object_lookup_bypath(
                 &baton->out,baton->treeish,baton->path,baton->type    );

  baton->error_code = result;

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

}

void GitObject::LookupBypathWorker::HandleOKCallback()
{
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block

    if (baton->out != NULL) {
      // GitObject baton->out
      to = GitObject::New((void *)baton->out, false);
    } else {
      to = NanNull();
    }

// end convert_to_v8 block
    Handle<Value> result = to;
    Handle<Value> argv[2] = {
      NanNull(),
      result
    };
    callback->Call(2, argv);
  } else {
    if (baton->error) {
      Handle<Value> argv[1] = {
        NanError(baton->error->message)
      };
      callback->Call(1, argv);
      if (baton->error->message)
        free((void *)baton->error->message);
      free((void *)baton->error);
    } else {
      callback->Call(0, NULL);
    }

  }

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

  free((void *)baton->path);

  delete baton;
}

/*
  * @param Repository repo
   * @param Oid id
   * @param Number len
   * @param Number type
    * @param Object callback
   */
NAN_METHOD(GitObject::LookupPrefix)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsObject()) {
    return NanThrowError("Repository repo is required.");
  }

  if (args.Length() == 1
      || (!args[1]->IsObject() && !args[1]->IsString())) {
    return NanThrowError("Oid id is required.");
  }

  if (args.Length() == 2 || !args[2]->IsNumber()) {
    return NanThrowError("Number len is required.");
  }

  if (args.Length() == 3 || !args[3]->IsNumber()) {
    return NanThrowError("Number type is required.");
  }

  if (args.Length() == 4 || !args[4]->IsFunction()) {
    return NanThrowError("Callback is required and must be a Function.");
  }

  LookupPrefixBaton* baton = new LookupPrefixBaton;

  baton->error_code = GIT_OK;
  baton->error = NULL;

// start convert_from_v8 block
  git_repository * from_repo;
  from_repo = ObjectWrap::Unwrap<GitRepository>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  baton->repo = from_repo;
// start convert_from_v8 block
  const git_oid * from_id;
  if (args[1]->IsString()) {
    // Try and parse in a string to a git_oid
    String::Utf8Value oidString(args[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 NanThrowError(giterr_last()->message);
      } else {
        return NanThrowError("Unknown Error");
      }
    }

    from_id = oidOut;
  } else {
    from_id = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject())->GetValue();
  }
// end convert_from_v8 block
  baton->id = from_id;
  baton->idNeedsFree = args[1]->IsString();
// start convert_from_v8 block
  size_t from_len;
  from_len = (size_t)   args[2]->ToNumber()->Value();
// end convert_from_v8 block
  baton->len = from_len;
// start convert_from_v8 block
  git_otype from_type;
  from_type = (git_otype)  (int) args[3]->ToNumber()->Value();
// end convert_from_v8 block
  baton->type = from_type;

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[4]));
  LookupPrefixWorker *worker = new LookupPrefixWorker(baton, callback);
  if (!args[0]->IsUndefined() && !args[0]->IsNull())
    worker->SaveToPersistent("repo", args[0]->ToObject());
  if (!args[1]->IsUndefined() && !args[1]->IsNull())
    worker->SaveToPersistent("id", args[1]->ToObject());
  if (!args[2]->IsUndefined() && !args[2]->IsNull())
    worker->SaveToPersistent("len", args[2]->ToObject());
  if (!args[3]->IsUndefined() && !args[3]->IsNull())
    worker->SaveToPersistent("type", args[3]->ToObject());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitObject::LookupPrefixWorker::Execute()
{
  int result = git_object_lookup_prefix(
                 &baton->object_out,baton->repo,baton->id,baton->len,baton->type    );

  baton->error_code = result;

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

}

void GitObject::LookupPrefixWorker::HandleOKCallback()
{
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block

    if (baton->object_out != NULL) {
      // GitObject baton->object_out
      to = GitObject::New((void *)baton->object_out, false);
    } else {
      to = NanNull();
    }

// end convert_to_v8 block
    Handle<Value> result = to;
    Handle<Value> argv[2] = {
      NanNull(),
      result
    };
    callback->Call(2, argv);
  } else {
    if (baton->error) {
      Handle<Value> argv[1] = {
        NanError(baton->error->message)
      };
      callback->Call(1, argv);
      if (baton->error->message)
        free((void *)baton->error->message);
      free((void *)baton->error);
    } else {
      callback->Call(0, NULL);
    }

  }

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

  if (baton->idNeedsFree) {
    baton->idNeedsFree = false;
    free((void *)baton->id);
  }

  delete baton;
}

/*
     * @return Repository  result    */
NAN_METHOD(GitObject::Owner)
{
  NanEscapableScope();

  git_repository * result = git_object_owner(
                              ObjectWrap::Unwrap<GitObject>(args.This())->GetValue()
                            );
  // null checks on pointers
  if (!result) {
    NodeGitPsueodoNanReturnEscapingValue(NanUndefined());
  }

  Handle<Value> to;
// start convert_to_v8 block

  if (result != NULL) {
    // GitRepository result
    to = GitRepository::New((void *)result, false);
  } else {
    to = NanNull();
  }

// end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}

/*
    * @param Number target_type
    * @param Object callback
   */
NAN_METHOD(GitObject::Peel)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsNumber()) {
    return NanThrowError("Number target_type is required.");
  }

  if (args.Length() == 1 || !args[1]->IsFunction()) {
    return NanThrowError("Callback is required and must be a Function.");
  }

  PeelBaton* baton = new PeelBaton;

  baton->error_code = GIT_OK;
  baton->error = NULL;

  baton->object = ObjectWrap::Unwrap<GitObject>(args.This())->GetValue();
// start convert_from_v8 block
  git_otype from_target_type;
  from_target_type = (git_otype)  (int) args[0]->ToNumber()->Value();
// end convert_from_v8 block
  baton->target_type = from_target_type;

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[1]));
  PeelWorker *worker = new PeelWorker(baton, callback);
  worker->SaveToPersistent("object", args.This());
  if (!args[0]->IsUndefined() && !args[0]->IsNull())
    worker->SaveToPersistent("target_type", args[0]->ToObject());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitObject::PeelWorker::Execute()
{
  int result = git_object_peel(
                 &baton->peeled,baton->object,baton->target_type    );

  baton->error_code = result;

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

}

void GitObject::PeelWorker::HandleOKCallback()
{
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block

    if (baton->peeled != NULL) {
      // GitObject baton->peeled
      to = GitObject::New((void *)baton->peeled, false);
    } else {
      to = NanNull();
    }

// end convert_to_v8 block
    Handle<Value> result = to;
    Handle<Value> argv[2] = {
      NanNull(),
      result
    };
    callback->Call(2, argv);
  } else {
    if (baton->error) {
      Handle<Value> argv[1] = {
        NanError(baton->error->message)
      };
      callback->Call(1, argv);
      if (baton->error->message)
        free((void *)baton->error->message);
      free((void *)baton->error);
    } else {
      callback->Call(0, NULL);
    }

  }

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


  delete baton;
}

/*
     * @param Buf callback
   */
NAN_METHOD(GitObject::ShortId)
{
  NanScope();

  if (args.Length() == 0 || !args[0]->IsFunction()) {
    return NanThrowError("Callback is required and must be a Function.");
  }

  ShortIdBaton* baton = new ShortIdBaton;

  baton->error_code = GIT_OK;
  baton->error = NULL;

  baton->out = (git_buf *)malloc(sizeof(git_buf ));
  baton->obj = ObjectWrap::Unwrap<GitObject>(args.This())->GetValue();

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[0]));
  ShortIdWorker *worker = new ShortIdWorker(baton, callback);
  worker->SaveToPersistent("obj", args.This());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitObject::ShortIdWorker::Execute()
{
  int result = git_object_short_id(
                 baton->out,baton->obj    );

  baton->error_code = result;

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

}

void GitObject::ShortIdWorker::HandleOKCallback()
{
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block

    if (baton->out != NULL) {
      // GitBuf baton->out
      to = GitBuf::New((void *)baton->out, false);
    } else {
      to = NanNull();
    }

// end convert_to_v8 block
    Handle<Value> result = to;
    Handle<Value> argv[2] = {
      NanNull(),
      result
    };
    callback->Call(2, argv);
  } else {
    if (baton->error) {
      Handle<Value> argv[1] = {
        NanError(baton->error->message)
      };
      callback->Call(1, argv);
      if (baton->error->message)
        free((void *)baton->error->message);
      free((void *)baton->error);
    } else {
      callback->Call(0, NULL);
    }

  }

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


  delete baton;
}

/*
 * @param String str
     * @return Number  result    */
NAN_METHOD(GitObject::String2type)
{
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsString()) {
    return NanThrowError("String str is required.");
  }

// start convert_from_v8 block
  const char * from_str;

  String::Utf8Value str(args[0]->ToString());
  from_str = (const char *) strdup(*str);
// end convert_from_v8 block
  git_otype result = git_object_string2type(
                       from_str
                     );

  Handle<Value> to;
// start convert_to_v8 block
  to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}

/*
     * @return Number  result    */
NAN_METHOD(GitObject::Type)
{
  NanEscapableScope();

  git_otype result = git_object_type(
                       ObjectWrap::Unwrap<GitObject>(args.This())->GetValue()
                     );

  Handle<Value> to;
// start convert_to_v8 block
  to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}

/*
 * @param Number type
     * @return String  result    */
NAN_METHOD(GitObject::Type2string)
{
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsNumber()) {
    return NanThrowError("Number type is required.");
  }

// start convert_from_v8 block
  git_otype from_type;
  from_type = (git_otype)  (int) args[0]->ToNumber()->Value();
// end convert_from_v8 block
  const char * result = git_object_type2string(
                          from_type
                        );
  // null checks on pointers
  if (!result) {
    NodeGitPsueodoNanReturnEscapingValue(NanUndefined());
  }

  Handle<Value> to;
// start convert_to_v8 block
  if (result) {
    to = NanNew<String>(result);
  } else {
    to = NanNull();
  }

  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}

/*
 * @param Number type
     * @return Number  result    */
NAN_METHOD(GitObject::Typeisloose)
{
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsNumber()) {
    return NanThrowError("Number type is required.");
  }

// start convert_from_v8 block
  git_otype from_type;
  from_type = (git_otype)  (int) args[0]->ToNumber()->Value();
// end convert_from_v8 block
  int result = git_object_typeisloose(
                 from_type
               );

  Handle<Value> to;
// start convert_to_v8 block
  to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
Persistent<Function> GitObject::constructor_template;
