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

  #include "../include/remote.h"
  #include "../include/repository.h"
  #include "../include/signature.h"
  #include "../include/remote_callbacks.h"
  #include "../include/strarray.h"
  #include "../include/refspec.h"
  #include "../include/transport.h"
  #include "../include/transfer_progress.h"
 
#include <iostream>

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

  GitRemote::GitRemote(git_remote *raw, bool selfFreeing) {
    this->raw = raw;
    this->selfFreeing = selfFreeing;
  }

  GitRemote::~GitRemote() {
      if (this->selfFreeing) {
        git_remote_free(this->raw);
      }
   }

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

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

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

          NODE_SET_PROTOTYPE_METHOD(tpl, "addFetch", AddFetch);
            NODE_SET_PROTOTYPE_METHOD(tpl, "addPush", AddPush);
            NODE_SET_PROTOTYPE_METHOD(tpl, "autotag", Autotag);
            NODE_SET_PROTOTYPE_METHOD(tpl, "checkCert", CheckCert);
            NODE_SET_PROTOTYPE_METHOD(tpl, "clearRefspecs", ClearRefspecs);
            NODE_SET_PROTOTYPE_METHOD(tpl, "connect", Connect);
            NODE_SET_PROTOTYPE_METHOD(tpl, "connected", Connected);
             NODE_SET_METHOD(tpl, "create", Create);
             NODE_SET_METHOD(tpl, "createAnonymous", CreateAnonymous);
             NODE_SET_METHOD(tpl, "createWithFetchspec", CreateWithFetchspec);
            NODE_SET_PROTOTYPE_METHOD(tpl, "delete", Delete);
            NODE_SET_PROTOTYPE_METHOD(tpl, "disconnect", Disconnect);
            NODE_SET_PROTOTYPE_METHOD(tpl, "download", Download);
            NODE_SET_PROTOTYPE_METHOD(tpl, "dup", Dup);
            NODE_SET_PROTOTYPE_METHOD(tpl, "fetch", Fetch);
            NODE_SET_PROTOTYPE_METHOD(tpl, "getCallbacks", GetCallbacks);
            NODE_SET_PROTOTYPE_METHOD(tpl, "getFetchRefspecs", GetFetchRefspecs);
            NODE_SET_PROTOTYPE_METHOD(tpl, "getPushRefspecs", GetPushRefspecs);
            NODE_SET_PROTOTYPE_METHOD(tpl, "getRefspec", GetRefspec);
             NODE_SET_METHOD(tpl, "initCallbacks", InitCallbacks);
             NODE_SET_METHOD(tpl, "isValidName", IsValidName);
             NODE_SET_METHOD(tpl, "list", List);
             NODE_SET_METHOD(tpl, "load", Load);
            NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name);
            NODE_SET_PROTOTYPE_METHOD(tpl, "owner", Owner);
            NODE_SET_PROTOTYPE_METHOD(tpl, "pushurl", Pushurl);
            NODE_SET_PROTOTYPE_METHOD(tpl, "refspecCount", RefspecCount);
            NODE_SET_PROTOTYPE_METHOD(tpl, "save", Save);
            NODE_SET_PROTOTYPE_METHOD(tpl, "setAutotag", SetAutotag);
            NODE_SET_PROTOTYPE_METHOD(tpl, "setCallbacks", SetCallbacks);
            NODE_SET_PROTOTYPE_METHOD(tpl, "setPushurl", SetPushurl);
            NODE_SET_PROTOTYPE_METHOD(tpl, "setTransport", SetTransport);
            NODE_SET_PROTOTYPE_METHOD(tpl, "setUpdateFetchhead", SetUpdateFetchhead);
            NODE_SET_PROTOTYPE_METHOD(tpl, "setUrl", SetUrl);
            NODE_SET_PROTOTYPE_METHOD(tpl, "stats", Stats);
            NODE_SET_PROTOTYPE_METHOD(tpl, "stop", Stop);
             NODE_SET_METHOD(tpl, "supportedUrl", SupportedUrl);
            NODE_SET_PROTOTYPE_METHOD(tpl, "updateFetchhead", UpdateFetchhead);
            NODE_SET_PROTOTYPE_METHOD(tpl, "updateTips", UpdateTips);
            NODE_SET_PROTOTYPE_METHOD(tpl, "url", Url);
             NODE_SET_METHOD(tpl, "validUrl", ValidUrl);
    
    Local<Function> _constructor_template = tpl->GetFunction();
    NanAssignPersistent(constructor_template, _constructor_template);
    target->Set(NanNew<String>("Remote"), _constructor_template);
  }

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

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

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

    NanReturnValue(args.This());
  }

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

  git_remote *GitRemote::GetValue() {
    return this->raw;
  }

  git_remote **GitRemote::GetRefValue() {
    return &this->raw;
  }

  
/*
   * @param String refspec
     * @return Number  result    */
NAN_METHOD(GitRemote::AddFetch) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const char * from_refspec;

  String::Utf8Value refspec(args[0]->ToString());
  from_refspec = (const char *) strdup(*refspec);
// end convert_from_v8 block
  int result = git_remote_add_fetch(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_refspec
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @param String refspec
     * @return Number  result    */
NAN_METHOD(GitRemote::AddPush) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const char * from_refspec;

  String::Utf8Value refspec(args[0]->ToString());
  from_refspec = (const char *) strdup(*refspec);
// end convert_from_v8 block
  int result = git_remote_add_push(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_refspec
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     * @return Number  result    */
NAN_METHOD(GitRemote::Autotag) {
  NanEscapableScope();

  git_remote_autotag_option_t result = git_remote_autotag(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @param Number check
     */
NAN_METHOD(GitRemote::CheckCert) {
  NanEscapableScope();

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

// start convert_from_v8 block
  int from_check;
  from_check = (int)   args[0]->ToNumber()->Value();
// end convert_from_v8 block
git_remote_check_cert(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_check
  );
  NanReturnUndefined();
}
   
/*
     */
NAN_METHOD(GitRemote::ClearRefspecs) {
  NanEscapableScope();

git_remote_clear_refspecs(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );
  NanReturnUndefined();
}
   
/*
   * @param Number direction
     * @return Number  result    */
NAN_METHOD(GitRemote::Connect) {
  NanEscapableScope();

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

// start convert_from_v8 block
  git_direction from_direction;
  from_direction = (git_direction)  (int) args[0]->ToNumber()->Value();
// end convert_from_v8 block
  int result = git_remote_connect(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_direction
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     * @return Number  result    */
NAN_METHOD(GitRemote::Connected) {
  NanEscapableScope();

  int result = git_remote_connected(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
  
/*
  * @param Repository repo
   * @param String name
   * @param String url
    * @param Remote callback
   */
NAN_METHOD(GitRemote::Create) {
  NanScope();

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

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

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

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

  CreateBaton* baton = new CreateBaton;

  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_name;

  String::Utf8Value name(args[1]->ToString());
  from_name = (const char *) strdup(*name);
// end convert_from_v8 block
  baton->name = from_name;
// start convert_from_v8 block
  const char * from_url;

  String::Utf8Value url(args[2]->ToString());
  from_url = (const char *) strdup(*url);
// end convert_from_v8 block
  baton->url = from_url;

  NanCallback *callback = new NanCallback(Local<Function>::Cast(args[3]));
  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("name", args[1]->ToObject());
  if (!args[2]->IsUndefined() && !args[2]->IsNull())
    worker->SaveToPersistent("url", args[2]->ToObject());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::CreateWorker::Execute() {
  int result = git_remote_create(
&baton->out,baton->repo,baton->name,baton->url    );

  baton->error_code = result;

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

}

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

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
  
  if (baton->out != NULL) {
    // GitRemote baton->out
       to = GitRemote::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->name);
  free((void *)baton->url);

  delete baton;
}
  
/*
  * @param Repository repo
   * @param String url
   * @param String fetch
    * @param Remote callback
   */
NAN_METHOD(GitRemote::CreateAnonymous) {
  NanScope();

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

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

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

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

  CreateAnonymousBaton* baton = new CreateAnonymousBaton;

  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_url;

  String::Utf8Value url(args[1]->ToString());
  from_url = (const char *) strdup(*url);
// end convert_from_v8 block
  baton->url = from_url;
// start convert_from_v8 block
  const char * from_fetch;

  String::Utf8Value fetch(args[2]->ToString());
  from_fetch = (const char *) strdup(*fetch);
// end convert_from_v8 block
  baton->fetch = from_fetch;

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::CreateAnonymousWorker::Execute() {
  int result = git_remote_create_anonymous(
&baton->out,baton->repo,baton->url,baton->fetch    );

  baton->error_code = result;

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

}

void GitRemote::CreateAnonymousWorker::HandleOKCallback() {
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
  
  if (baton->out != NULL) {
    // GitRemote baton->out
       to = GitRemote::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->url);
  free((void *)baton->fetch);

  delete baton;
}
  
/*
  * @param Repository repo
   * @param String name
   * @param String url
   * @param String fetch
    * @param Remote callback
   */
NAN_METHOD(GitRemote::CreateWithFetchspec) {
  NanScope();

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

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

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

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

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

  CreateWithFetchspecBaton* baton = new CreateWithFetchspecBaton;

  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_name;

  String::Utf8Value name(args[1]->ToString());
  from_name = (const char *) strdup(*name);
// end convert_from_v8 block
  baton->name = from_name;
// start convert_from_v8 block
  const char * from_url;

  String::Utf8Value url(args[2]->ToString());
  from_url = (const char *) strdup(*url);
// end convert_from_v8 block
  baton->url = from_url;
// start convert_from_v8 block
  const char * from_fetch;

  String::Utf8Value fetch(args[3]->ToString());
  from_fetch = (const char *) strdup(*fetch);
// end convert_from_v8 block
  baton->fetch = from_fetch;

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::CreateWithFetchspecWorker::Execute() {
  int result = git_remote_create_with_fetchspec(
&baton->out,baton->repo,baton->name,baton->url,baton->fetch    );

  baton->error_code = result;

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

}

void GitRemote::CreateWithFetchspecWorker::HandleOKCallback() {
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
  
  if (baton->out != NULL) {
    // GitRemote baton->out
       to = GitRemote::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->name);
  free((void *)baton->url);
  free((void *)baton->fetch);

  delete baton;
}
   
/*
     * @return Number  result    */
NAN_METHOD(GitRemote::Delete) {
  NanEscapableScope();

  int result = git_remote_delete(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     */
NAN_METHOD(GitRemote::Disconnect) {
  NanEscapableScope();

git_remote_disconnect(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );
  NanReturnUndefined();
}
   
/*
     * @return Number  result    */
NAN_METHOD(GitRemote::Download) {
  NanEscapableScope();

  int result = git_remote_download(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
  
/*
     * @param Remote callback
   */
NAN_METHOD(GitRemote::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<GitRemote>(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 GitRemote::DupWorker::Execute() {
  int result = git_remote_dup(
&baton->dest,baton->source    );

  baton->error_code = result;

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

}

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

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
  
  if (baton->dest != NULL) {
    // GitRemote baton->dest
       to = GitRemote::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;
}
  
/*
   * @param Signature signature
   * @param String reflog_message
     */
NAN_METHOD(GitRemote::Fetch) {
  NanScope();

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

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

  FetchBaton* baton = new FetchBaton;

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

  baton->remote = ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue();
// start convert_from_v8 block
  const git_signature * from_signature;
  from_signature = ObjectWrap::Unwrap<GitSignature>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  baton->signature = from_signature;
// start convert_from_v8 block
  const char * from_reflog_message;

  if (args[1]->IsString()) {

  String::Utf8Value reflog_message(args[1]->ToString());
  from_reflog_message = (const char *) strdup(*reflog_message);
  }
  else {
    from_reflog_message = 0;
  }

// end convert_from_v8 block
  baton->reflog_message = from_reflog_message;

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::FetchWorker::Execute() {
  int result = git_remote_fetch(
baton->remote,baton->signature,baton->reflog_message    );

  baton->error_code = result;

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

}

void GitRemote::FetchWorker::HandleOKCallback() {
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> result = NanUndefined();
    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->reflog_message);

  delete baton;
}
   
/*
     * @return RemoteCallbacks  result    */
NAN_METHOD(GitRemote::GetCallbacks) {
  NanEscapableScope();

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

  Handle<Value> to;
// start convert_to_v8 block
  
  if (result != NULL) {
    // GitRemoteCallbacks result
       to = GitRemoteCallbacks::New((void *)result, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
  
/*
     * @param Array callback
   */
NAN_METHOD(GitRemote::GetFetchRefspecs) {
  NanScope();

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

  GetFetchRefspecsBaton* baton = new GetFetchRefspecsBaton;

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

  baton->array = (git_strarray *)malloc(sizeof(git_strarray ));
  baton->remote = ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue();

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::GetFetchRefspecsWorker::Execute() {
  int result = git_remote_get_fetch_refspecs(
baton->array,baton->remote    );

}

void GitRemote::GetFetchRefspecsWorker::HandleOKCallback() {
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
    Local<Array> tmpArray = NanNew<Array>(baton->array->count);
    for (unsigned int i = 0; i < baton->array->count; i++) {
      tmpArray->Set(NanNew<Number>(i), NanNew<String>(baton->array->strings[i]));
    }
 
  to = tmpArray;
 // 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);
    }

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

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

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

  delete baton;
}
  
/*
     * @param Array callback
   */
NAN_METHOD(GitRemote::GetPushRefspecs) {
  NanScope();

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

  GetPushRefspecsBaton* baton = new GetPushRefspecsBaton;

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

  baton->array = (git_strarray *)malloc(sizeof(git_strarray ));
  baton->remote = ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue();

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::GetPushRefspecsWorker::Execute() {
  int result = git_remote_get_push_refspecs(
baton->array,baton->remote    );

}

void GitRemote::GetPushRefspecsWorker::HandleOKCallback() {
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
    Local<Array> tmpArray = NanNew<Array>(baton->array->count);
    for (unsigned int i = 0; i < baton->array->count; i++) {
      tmpArray->Set(NanNew<Number>(i), NanNew<String>(baton->array->strings[i]));
    }
 
  to = tmpArray;
 // 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);
    }

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

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

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

  delete baton;
}
   
/*
   * @param Number n
     * @return Refspec  result    */
NAN_METHOD(GitRemote::GetRefspec) {
  NanEscapableScope();

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

// start convert_from_v8 block
  size_t from_n;
  from_n = (size_t)   args[0]->ToNumber()->Value();
// end convert_from_v8 block
  const git_refspec * result = git_remote_get_refspec(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_n
  );
  // null checks on pointers
  if (!result) {
    NodeGitPsueodoNanReturnEscapingValue(NanUndefined());
  }

  Handle<Value> to;
// start convert_to_v8 block
  
  if (result != NULL) {
    // GitRefspec result
       to = GitRefspec::New((void *)result, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
 * @param RemoteCallbacks opts
   * @param Number version
     * @return Number  result    */
NAN_METHOD(GitRemote::InitCallbacks) {
  NanEscapableScope();

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

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

// start convert_from_v8 block
  git_remote_callbacks * from_opts;
  from_opts = ObjectWrap::Unwrap<GitRemoteCallbacks>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
// start convert_from_v8 block
  unsigned int from_version;
  from_version = (unsigned int)   args[1]->ToNumber()->Value();
// end convert_from_v8 block
  int result = git_remote_init_callbacks(
from_opts
,from_version
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
 * @param String remote_name
     * @return Number  result    */
NAN_METHOD(GitRemote::IsValidName) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const char * from_remote_name;

  String::Utf8Value remote_name(args[0]->ToString());
  from_remote_name = (const char *) strdup(*remote_name);
// end convert_from_v8 block
  int result = git_remote_is_valid_name(
from_remote_name
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
  
/*
  * @param Repository repo
    * @param Array callback
   */
NAN_METHOD(GitRemote::List) {
  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.");
  }

  ListBaton* baton = new ListBaton;

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

  baton->out = (git_strarray *)malloc(sizeof(git_strarray ));
// 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]));
  ListWorker *worker = new ListWorker(baton, callback);
  if (!args[0]->IsUndefined() && !args[0]->IsNull())
    worker->SaveToPersistent("repo", args[0]->ToObject());

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::ListWorker::Execute() {
  int result = git_remote_list(
baton->out,baton->repo    );

  baton->error_code = result;

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

}

void GitRemote::ListWorker::HandleOKCallback() {
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
    Local<Array> tmpArray = NanNew<Array>(baton->out->count);
    for (unsigned int i = 0; i < baton->out->count; i++) {
      tmpArray->Set(NanNew<Number>(i), NanNew<String>(baton->out->strings[i]));
    }
 
  to = tmpArray;
 // 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);
    }

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

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

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

  delete baton;
}
  
/*
  * @param Repository repo
   * @param String name
    * @param Remote callback
   */
NAN_METHOD(GitRemote::Load) {
  NanScope();

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

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

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

  LoadBaton* baton = new LoadBaton;

  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_name;

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

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

  NanAsyncQueueWorker(worker);
  NanReturnUndefined();
}

void GitRemote::LoadWorker::Execute() {
  int result = git_remote_load(
&baton->out,baton->repo,baton->name    );

  baton->error_code = result;

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

}

void GitRemote::LoadWorker::HandleOKCallback() {
  TryCatch try_catch;

  if (baton->error_code == GIT_OK) {
    Handle<Value> to;
// start convert_to_v8 block
  
  if (baton->out != NULL) {
    // GitRemote baton->out
       to = GitRemote::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->name);

  delete baton;
}
   
/*
     * @return String  result    */
NAN_METHOD(GitRemote::Name) {
  NanEscapableScope();

  const char * result = git_remote_name(
ObjectWrap::Unwrap<GitRemote>(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);
}
   
/*
     * @return Repository  result    */
NAN_METHOD(GitRemote::Owner) {
  NanEscapableScope();

  git_repository * result = git_remote_owner(
ObjectWrap::Unwrap<GitRemote>(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);
}
   
/*
     * @return String  result    */
NAN_METHOD(GitRemote::Pushurl) {
  NanEscapableScope();

  const char * result = git_remote_pushurl(
ObjectWrap::Unwrap<GitRemote>(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);
}
   
/*
     * @return Number  result    */
NAN_METHOD(GitRemote::RefspecCount) {
  NanEscapableScope();

  size_t result = git_remote_refspec_count(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     * @return Number  result    */
NAN_METHOD(GitRemote::Save) {
  NanEscapableScope();

  int result = git_remote_save(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @param Number value
     */
NAN_METHOD(GitRemote::SetAutotag) {
  NanEscapableScope();

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

// start convert_from_v8 block
  git_remote_autotag_option_t from_value;
  from_value = (git_remote_autotag_option_t)  (int) args[0]->ToNumber()->Value();
// end convert_from_v8 block
git_remote_set_autotag(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_value
  );
  NanReturnUndefined();
}
   
/*
   * @param RemoteCallbacks callbacks
     * @return Number  result    */
NAN_METHOD(GitRemote::SetCallbacks) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const git_remote_callbacks * from_callbacks;
  from_callbacks = ObjectWrap::Unwrap<GitRemoteCallbacks>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  int result = git_remote_set_callbacks(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_callbacks
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @param String url
     * @return Number  result    */
NAN_METHOD(GitRemote::SetPushurl) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const char * from_url;

  String::Utf8Value url(args[0]->ToString());
  from_url = (const char *) strdup(*url);
// end convert_from_v8 block
  int result = git_remote_set_pushurl(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_url
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @param Transport transport
     * @return Number  result    */
NAN_METHOD(GitRemote::SetTransport) {
  NanEscapableScope();

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

// start convert_from_v8 block
  git_transport * from_transport;
  from_transport = ObjectWrap::Unwrap<GitTransport>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  int result = git_remote_set_transport(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_transport
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @param Number value
     */
NAN_METHOD(GitRemote::SetUpdateFetchhead) {
  NanEscapableScope();

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

// start convert_from_v8 block
  int from_value;
  from_value = (int)   args[0]->ToNumber()->Value();
// end convert_from_v8 block
git_remote_set_update_fetchhead(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_value
  );
  NanReturnUndefined();
}
   
/*
   * @param String url
     * @return Number  result    */
NAN_METHOD(GitRemote::SetUrl) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const char * from_url;

  String::Utf8Value url(args[0]->ToString());
  from_url = (const char *) strdup(*url);
// end convert_from_v8 block
  int result = git_remote_set_url(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_url
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     * @return TransferProgress  result    */
NAN_METHOD(GitRemote::Stats) {
  NanEscapableScope();

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

  Handle<Value> to;
// start convert_to_v8 block
  
  if (result != NULL) {
    // GitTransferProgress result
       to = GitTransferProgress::New((void *)result, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     */
NAN_METHOD(GitRemote::Stop) {
  NanEscapableScope();

git_remote_stop(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );
  NanReturnUndefined();
}
   
/*
 * @param String url
     * @return Number  result    */
NAN_METHOD(GitRemote::SupportedUrl) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const char * from_url;

  String::Utf8Value url(args[0]->ToString());
  from_url = (const char *) strdup(*url);
// end convert_from_v8 block
  int result = git_remote_supported_url(
from_url
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     * @return Number  result    */
NAN_METHOD(GitRemote::UpdateFetchhead) {
  NanEscapableScope();

  int result = git_remote_update_fetchhead(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @param Signature signature
   * @param String reflog_message
     * @return Number  result    */
NAN_METHOD(GitRemote::UpdateTips) {
  NanEscapableScope();

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

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

// start convert_from_v8 block
  const git_signature * from_signature;
  from_signature = ObjectWrap::Unwrap<GitSignature>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
// start convert_from_v8 block
  const char * from_reflog_message;

  String::Utf8Value reflog_message(args[1]->ToString());
  from_reflog_message = (const char *) strdup(*reflog_message);
// end convert_from_v8 block
  int result = git_remote_update_tips(
ObjectWrap::Unwrap<GitRemote>(args.This())->GetValue()
,from_signature
,from_reflog_message
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
     * @return String  result    */
NAN_METHOD(GitRemote::Url) {
  NanEscapableScope();

  const char * result = git_remote_url(
ObjectWrap::Unwrap<GitRemote>(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 String url
     * @return Number  result    */
NAN_METHOD(GitRemote::ValidUrl) {
  NanEscapableScope();

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

// start convert_from_v8 block
  const char * from_url;

  String::Utf8Value url(args[0]->ToString());
  from_url = (const char *) strdup(*url);
// end convert_from_v8 block
  int result = git_remote_valid_url(
from_url
  );

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