// 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/note.h"

#include "../include/oid.h"
#include "../include/repository.h"
#include "../include/signature.h"
#include "../include/note.h"
#include "../include/note_iterator.h"

#include <iostream>

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

GitNote::GitNote(git_note *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitNote::~GitNote()
{
  if (this->selfFreeing) {
    git_note_free(this->raw);
  }
}

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

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

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

  NODE_SET_METHOD(tpl, "create", Create);
  NODE_SET_METHOD(tpl, "defaultRef", DefaultRef);
  NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id);
  NODE_SET_METHOD(tpl, "iteratorFree", IteratorFree);
  NODE_SET_METHOD(tpl, "iteratorNew", IteratorNew);
  NODE_SET_PROTOTYPE_METHOD(tpl, "message", Message);
  NODE_SET_METHOD(tpl, "next", Next);
  NODE_SET_METHOD(tpl, "read", Read);
  NODE_SET_METHOD(tpl, "remove", Remove);

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

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

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

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

  NanReturnValue(args.This());
}

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

git_note *GitNote::GetValue()
{
  return this->raw;
}

git_note **GitNote::GetRefValue()
{
  return &this->raw;
}


/*
  * @param Repository repo
   * @param Signature author
   * @param Signature committer
   * @param String notes_ref
   * @param Oid oid
   * @param String note
   * @param Number force
    * @param Oid callback
   */
NAN_METHOD(GitNote::Create)
{
  NanScope();

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

  if (args.Length() == 1 || !args[1]->IsObject()) {
    return NanThrowError("Signature author is required.");
  }

  if (args.Length() == 2 || !args[2]->IsObject()) {
    return NanThrowError("Signature committer is required.");
  }

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

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

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

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

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

  CreateBaton* baton = new CreateBaton;

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

  baton->out = (git_oid *)malloc(sizeof(git_oid ));
// 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_signature * from_author;
  from_author = ObjectWrap::Unwrap<GitSignature>(args[1]->ToObject())->GetValue();
// end convert_from_v8 block
  baton->author = from_author;
// start convert_from_v8 block
  const git_signature * from_committer;
  from_committer = ObjectWrap::Unwrap<GitSignature>(args[2]->ToObject())->GetValue();
// end convert_from_v8 block
  baton->committer = from_committer;
// start convert_from_v8 block
  const char * from_notes_ref;

  String::Utf8Value notes_ref(args[3]->ToString());
  from_notes_ref = (const char *) strdup(*notes_ref);
// end convert_from_v8 block
  baton->notes_ref = from_notes_ref;
// start convert_from_v8 block
  const git_oid * from_oid;
  if (args[4]->IsString()) {
    // Try and parse in a string to a git_oid
    String::Utf8Value oidString(args[4]->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_oid = oidOut;
  } else {
    from_oid = ObjectWrap::Unwrap<GitOid>(args[4]->ToObject())->GetValue();
  }
// end convert_from_v8 block
  baton->oid = from_oid;
  baton->oidNeedsFree = args[4]->IsString();
// start convert_from_v8 block
  const char * from_note;

  String::Utf8Value note(args[5]->ToString());
  from_note = (const char *) strdup(*note);
// end convert_from_v8 block
  baton->note = from_note;
// start convert_from_v8 block
  int from_force;
  from_force = (int)   args[6]->ToNumber()->Value();
// end convert_from_v8 block
  baton->force = from_force;

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[7]));
  CreateWorker *worker = new CreateWorker(baton, callback);
  if (!args[0]->IsUndefined() && !args[0]->IsNull())
    worker->SaveToPersistent("repo", args[0]->ToObject());
  if (!args[1]->IsUndefined() && !args[1]->IsNull())
    worker->SaveToPersistent("author", args[1]->ToObject());
  if (!args[2]->IsUndefined() && !args[2]->IsNull())
    worker->SaveToPersistent("committer", args[2]->ToObject());
  if (!args[3]->IsUndefined() && !args[3]->IsNull())
    worker->SaveToPersistent("notes_ref", args[3]->ToObject());
  if (!args[4]->IsUndefined() && !args[4]->IsNull())
    worker->SaveToPersistent("oid", args[4]->ToObject());
  if (!args[5]->IsUndefined() && !args[5]->IsNull())
    worker->SaveToPersistent("note", args[5]->ToObject());
  if (!args[6]->IsUndefined() && !args[6]->IsNull())
    worker->SaveToPersistent("force", args[6]->ToObject());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitNote::CreateWorker::Execute()
{
  int result = git_note_create(
                 baton->out,baton->repo,baton->author,baton->committer,baton->notes_ref,baton->oid,baton->note,baton->force    );

  baton->error_code = result;

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

}

void GitNote::CreateWorker::HandleOKCallback()
{
  TryCatch try_catch;

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

    if (baton->out != NULL) {
      // GitOid baton->out
      to = GitOid::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->notes_ref);
  if (baton->oidNeedsFree) {
    baton->oidNeedsFree = false;
    free((void *)baton->oid);
  }
  free((void *)baton->note);

  delete baton;
}

/*
  * @param Repository repo
    * @param String callback
   */
NAN_METHOD(GitNote::DefaultRef)
{
  NanScope();

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

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

  DefaultRefBaton* baton = new DefaultRefBaton;

  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;

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitNote::DefaultRefWorker::Execute()
{
  int result = git_note_default_ref(
                 &baton->out,baton->repo    );

  baton->error_code = result;

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

}

void GitNote::DefaultRefWorker::HandleOKCallback()
{
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
    if (baton->out) {
      to = NanNew<String>(baton->out);
    } 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->out);

  delete baton;
}

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

  const git_oid * result = git_note_id(
                             ObjectWrap::Unwrap<GitNote>(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 NoteIterator it
     */
NAN_METHOD(GitNote::IteratorFree)
{
  NanEscapableScope();

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

// start convert_from_v8 block
  git_note_iterator * from_it;
  from_it = ObjectWrap::Unwrap<GitNoteIterator>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  git_note_iterator_free(
    from_it
  );
  NanReturnUndefined();
}

/*
  * @param Repository repo
   * @param String notes_ref
    * @param NoteIterator callback
   */
NAN_METHOD(GitNote::IteratorNew)
{
  NanScope();

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

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

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

  IteratorNewBaton* baton = new IteratorNewBaton;

  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 char * from_notes_ref;

  String::Utf8Value notes_ref(args[1]->ToString());
  from_notes_ref = (const char *) strdup(*notes_ref);
// end convert_from_v8 block
  baton->notes_ref = from_notes_ref;

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitNote::IteratorNewWorker::Execute()
{
  int result = git_note_iterator_new(
                 &baton->out,baton->repo,baton->notes_ref    );

  baton->error_code = result;

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

}

void GitNote::IteratorNewWorker::HandleOKCallback()
{
  TryCatch try_catch;

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

    if (baton->out != NULL) {
      // GitNoteIterator baton->out
      to = GitNoteIterator::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->notes_ref);

  delete baton;
}

/*
     * @return String  result    */
NAN_METHOD(GitNote::Message)
{
  NanEscapableScope();

  const char * result = git_note_message(
                          ObjectWrap::Unwrap<GitNote>(args.This())->GetValue()
                        );
  // 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 Oid note_id
   * @param Oid annotated_id
   * @param NoteIterator it
     * @return Number  result    */
NAN_METHOD(GitNote::Next)
{
  NanEscapableScope();

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

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

  if (args.Length() == 2 || !args[2]->IsObject()) {
    return NanThrowError("NoteIterator it is required.");
  }

// start convert_from_v8 block
  git_oid * from_note_id;
  if (args[0]->IsString()) {
    // Try and parse in a string to a git_oid
    String::Utf8Value oidString(args[0]->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_note_id = oidOut;
  } else {
    from_note_id = ObjectWrap::Unwrap<GitOid>(args[0]->ToObject())->GetValue();
  }
// end convert_from_v8 block
// start convert_from_v8 block
  git_oid * from_annotated_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_annotated_id = oidOut;
  } else {
    from_annotated_id = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject())->GetValue();
  }
// end convert_from_v8 block
// start convert_from_v8 block
  git_note_iterator * from_it;
  from_it = ObjectWrap::Unwrap<GitNoteIterator>(args[2]->ToObject())->GetValue();
// end convert_from_v8 block
  int result = git_note_next(
                 from_note_id
                 ,from_annotated_id
                 ,from_it
               );
  if (args[0]->IsString()) {
    free(&from_note_id);
  }
  if (args[1]->IsString()) {
    free(&from_annotated_id);
  }

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

/*
  * @param Repository repo
   * @param String notes_ref
   * @param Oid oid
    * @param Note callback
   */
NAN_METHOD(GitNote::Read)
{
  NanScope();

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

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

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

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

  ReadBaton* baton = new ReadBaton;

  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 char * from_notes_ref;

  String::Utf8Value notes_ref(args[1]->ToString());
  from_notes_ref = (const char *) strdup(*notes_ref);
// end convert_from_v8 block
  baton->notes_ref = from_notes_ref;
// start convert_from_v8 block
  const git_oid * from_oid;
  if (args[2]->IsString()) {
    // Try and parse in a string to a git_oid
    String::Utf8Value oidString(args[2]->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_oid = oidOut;
  } else {
    from_oid = ObjectWrap::Unwrap<GitOid>(args[2]->ToObject())->GetValue();
  }
// end convert_from_v8 block
  baton->oid = from_oid;
  baton->oidNeedsFree = args[2]->IsString();

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitNote::ReadWorker::Execute()
{
  int result = git_note_read(
                 &baton->out,baton->repo,baton->notes_ref,baton->oid    );

  baton->error_code = result;

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

}

void GitNote::ReadWorker::HandleOKCallback()
{
  TryCatch try_catch;

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

    if (baton->out != NULL) {
      // GitNote baton->out
      to = GitNote::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->notes_ref);
  if (baton->oidNeedsFree) {
    baton->oidNeedsFree = false;
    free((void *)baton->oid);
  }

  delete baton;
}

/*
 * @param Repository repo
   * @param String notes_ref
   * @param Signature author
   * @param Signature committer
   * @param Oid oid
     * @return Number  result    */
NAN_METHOD(GitNote::Remove)
{
  NanEscapableScope();

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

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

  if (args.Length() == 2 || !args[2]->IsObject()) {
    return NanThrowError("Signature author is required.");
  }

  if (args.Length() == 3 || !args[3]->IsObject()) {
    return NanThrowError("Signature committer is required.");
  }

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

// start convert_from_v8 block
  git_repository * from_repo;
  from_repo = ObjectWrap::Unwrap<GitRepository>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
// start convert_from_v8 block
  const char * from_notes_ref;

  String::Utf8Value notes_ref(args[1]->ToString());
  from_notes_ref = (const char *) strdup(*notes_ref);
// end convert_from_v8 block
// start convert_from_v8 block
  const git_signature * from_author;
  from_author = ObjectWrap::Unwrap<GitSignature>(args[2]->ToObject())->GetValue();
// end convert_from_v8 block
// start convert_from_v8 block
  const git_signature * from_committer;
  from_committer = ObjectWrap::Unwrap<GitSignature>(args[3]->ToObject())->GetValue();
// end convert_from_v8 block
// start convert_from_v8 block
  const git_oid * from_oid;
  if (args[4]->IsString()) {
    // Try and parse in a string to a git_oid
    String::Utf8Value oidString(args[4]->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_oid = oidOut;
  } else {
    from_oid = ObjectWrap::Unwrap<GitOid>(args[4]->ToObject())->GetValue();
  }
// end convert_from_v8 block
  int result = git_note_remove(
                 from_repo
                 ,from_notes_ref
                 ,from_author
                 ,from_committer
                 ,from_oid
               );
  if (args[4]->IsString()) {
    free(&from_oid);
  }

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