forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoid.cc
More file actions
executable file
·119 lines (92 loc) · 2.52 KB
/
Copy pathoid.cc
File metadata and controls
executable file
·119 lines (92 loc) · 2.52 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
113
114
115
116
117
118
119
/**
* This code is auto-generated; unless you know what you're doing, do not modify!
**/
#include <nan.h>
#include <string.h>
#include "git2.h"
#include "../include/functions/copy.h"
#include "../include/oid.h"
using namespace v8;
using namespace node;
GitOid::GitOid(git_oid *raw) {
this->raw = raw;
}
GitOid::~GitOid() {
free(this->raw);
}
void GitOid::Initialize(Handle<v8::Object> target) {
NanScope();
Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(NanNew<String>("Oid"));
NODE_SET_METHOD(tpl, "fromString", FromString);
NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha);
Local<Function> _constructor_template = tpl->GetFunction();
NanAssignPersistent(constructor_template, _constructor_template);
target->Set(NanNew<String>("Oid"), _constructor_template);
}
NAN_METHOD(GitOid::New) {
NanScope();
if (args.Length() == 0 || !args[0]->IsExternal()) {
return NanThrowError("git_oid is required.");
}
GitOid* object = new GitOid(static_cast<git_oid *>(Handle<External>::Cast(args[0])->Value()));
object->Wrap(args.This());
NanReturnValue(args.This());
}
Handle<Value> GitOid::New(void *raw) {
NanEscapableScope();
Handle<Value> argv[1] = { NanNew<External>((void *)raw) };
return NanEscapeScope(NanNew<Function>(GitOid::constructor_template)->NewInstance(1, argv));
}
git_oid *GitOid::GetValue() {
return this->raw;
}
/**
* @param {String} str
* @return {Oid} out
*/
NAN_METHOD(GitOid::FromString) {
NanScope();
if (args.Length() == 0 || !args[0]->IsString()) {
return NanThrowError("String str is required.");
}
git_oid *out = (git_oid *)malloc(sizeof(git_oid));
const char * from_str;
String::Utf8Value str(args[0]->ToString());
from_str = strdup(*str);
int result = git_oid_fromstr(
out
, from_str
);
free((void *)from_str);
if (result != GIT_OK) {
free(out);
if (giterr_last()) {
return NanThrowError(giterr_last()->message);
} else {
return NanThrowError("Unknown Error");
}
}
Handle<Value> to;
if (out != NULL) {
to = GitOid::New((void *)out);
} else {
to = NanNull();
}
NanReturnValue(to);
}
/**
* @return {String} result
*/
NAN_METHOD(GitOid::Sha) {
NanScope();
char * result = git_oid_allocfmt(
ObjectWrap::Unwrap<GitOid>(args.This())->GetValue()
);
Handle<Value> to;
to = NanNew<String>(result);
free(result);
NanReturnValue(to);
}
Persistent<Function> GitOid::constructor_template;