forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblob.cc
More file actions
executable file
·146 lines (110 loc) · 3.07 KB
/
Copy pathblob.cc
File metadata and controls
executable file
·146 lines (110 loc) · 3.07 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* This code is auto-generated; unless you know what you're doing, do not modify!
**/
#include <v8.h>
#include <node.h>
#include <string.h>
#include "git2.h"
#include "../include/functions/copy.h"
#include "../include/blob.h"
#include "../include/repo.h"
#include "../include/oid.h"
#include "../include/wrapper.h"
#include "node_buffer.h"
using namespace v8;
using namespace node;
GitBlob::GitBlob(git_blob *raw) {
this->raw = raw;
}
GitBlob::~GitBlob() {
git_blob_free(this->raw);
}
void GitBlob::Initialize(Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(String::NewSymbol("Blob"));
NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid);
NODE_SET_PROTOTYPE_METHOD(tpl, "content", Content);
NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size);
NODE_SET_PROTOTYPE_METHOD(tpl, "isBinary", IsBinary);
constructor_template = Persistent<Function>::New(tpl->GetFunction());
target->Set(String::NewSymbol("Blob"), constructor_template);
}
Handle<Value> GitBlob::New(const Arguments& args) {
HandleScope scope;
if (args.Length() == 0 || !args[0]->IsExternal()) {
return ThrowException(Exception::Error(String::New("git_blob is required.")));
}
GitBlob* object = new GitBlob((git_blob *) External::Unwrap(args[0]));
object->Wrap(args.This());
return scope.Close(args.This());
}
Handle<Value> GitBlob::New(void *raw) {
HandleScope scope;
Handle<Value> argv[1] = { External::New((void *)raw) };
return scope.Close(GitBlob::constructor_template->NewInstance(1, argv));
}
git_blob *GitBlob::GetValue() {
return this->raw;
}
/**
* @return {Oid} result
*/
Handle<Value> GitBlob::Oid(const Arguments& args) {
HandleScope scope;
const git_oid * result = git_blob_id(
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
);
Handle<Value> to;
if (result != NULL) {
result = (const git_oid * )git_oid_dup(result);
}
if (result != NULL) {
to = GitOid::New((void *)result);
} else {
to = Null();
}
return scope.Close(to);
}
/**
* @return {Wrapper} result
*/
Handle<Value> GitBlob::Content(const Arguments& args) {
HandleScope scope;
const void * result = git_blob_rawcontent(
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
);
Handle<Value> to;
if (result != NULL) {
to = Wrapper::New((void *)result);
} else {
to = Null();
}
return scope.Close(to);
}
/**
* @return {Number} result
*/
Handle<Value> GitBlob::Size(const Arguments& args) {
HandleScope scope;
git_off_t result = git_blob_rawsize(
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
);
Handle<Value> to;
to = Number::New(result);
return scope.Close(to);
}
/**
* @return {Boolean} result
*/
Handle<Value> GitBlob::IsBinary(const Arguments& args) {
HandleScope scope;
int result = git_blob_is_binary(
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
);
Handle<Value> to;
to = Boolean::New(result);
return scope.Close(to);
}
Persistent<Function> GitBlob::constructor_template;