Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 113 lines (79 sloc) 2.794 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
/*
Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
*/

#include <v8.h>
#include <node.h>

#include "../vendor/libgit2/include/git2.h"

#include "../include/repo.h"
#include "../include/sig.h"

using namespace v8;
using namespace node;

void GitSig::Initialize (Handle<v8::Object> target) {
  HandleScope scope;

  Local<FunctionTemplate> t = FunctionTemplate::New(New);
  
  constructor_template = Persistent<FunctionTemplate>::New(t);
  constructor_template->InstanceTemplate()->SetInternalFieldCount(3);
  constructor_template->SetClassName(String::NewSymbol("Sig"));

  NODE_SET_PROTOTYPE_METHOD(constructor_template, "dup", Dup);
  NODE_SET_PROTOTYPE_METHOD(constructor_template, "free", Free);

  // FIXME: This is an irresponsible way to accomplish fetching properties from the struct
  NODE_SET_PROTOTYPE_METHOD(constructor_template, "name", Name);
  NODE_SET_PROTOTYPE_METHOD(constructor_template, "email", Email);

  target->Set(String::NewSymbol("Sig"), constructor_template->GetFunction());
}

git_signature* GitSig::GetValue() {
  return this->sig;
}

void GitSig::SetValue(git_signature* sig) {
  this->sig = sig;
  this->name = sig->name;
  this->email = sig->email;
}

void GitSig::New(const char *name, const char *email, time_t time, int offset) {
  git_signature_new(&this->sig, name, email, time, offset);
  //this->sig = git_signature_new(name, email, time, offset);
}

git_signature* GitSig::Dup() {
  return git_signature_dup(this->sig);
}

void GitSig::Free() {
  git_signature_free(this->sig);
}

char* GitSig::Name() {
  return this->name;
}

char* GitSig::Email() {
  return this->email;
}

Handle<Value> GitSig::New(const Arguments& args) {
  HandleScope scope;

  GitSig *sig = new GitSig();
  sig->Wrap(args.This());

  return scope.Close( args.This() );
}

Handle<Value> GitSig::Dup(const Arguments& args) {
  HandleScope scope;

  if(args.Length() == 0 || !args[0]->IsObject()) {
    return ThrowException(Exception::Error(String::New("GitSignature is required and must be an Object.")));
  }

  GitSig* sig = ObjectWrap::Unwrap<GitSig>(args[0]->ToObject());
  sig->SetValue(sig->Dup());

  return scope.Close( Undefined() );
}

Handle<Value> GitSig::Free(const Arguments& args) {
  HandleScope scope;

  GitSig *sig = ObjectWrap::Unwrap<GitSig>(args.This());
  sig->Free();

  return scope.Close( Undefined() );
}

Handle<Value> GitSig::Name(const Arguments& args) {
  HandleScope scope;

  GitSig *sig = ObjectWrap::Unwrap<GitSig>(args.This());

  return scope.Close( String::New(sig->Name()) );
}

Handle<Value> GitSig::Email(const Arguments& args) {
  HandleScope scope;

  GitSig *sig = ObjectWrap::Unwrap<GitSig>(args.This());

  return scope.Close( String::New(sig->Email()) );
}
Persistent<FunctionTemplate> GitSig::constructor_template;
Something went wrong with that request. Please try again.