forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_list.cc
More file actions
executable file
·229 lines (187 loc) · 5.68 KB
/
Copy pathdiff_list.cc
File metadata and controls
executable file
·229 lines (187 loc) · 5.68 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/**
* 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/diff_list.h"
#include "../include/diff_options.h"
#include "../include/diff_find_options.h"
#include "../include/repo.h"
#include "../include/tree.h"
#include "../include/index.h"
#include "../include/patch.h"
#include "../include/delta.h"
using namespace v8;
using namespace node;
GitDiffList::GitDiffList(git_diff_list *raw) {
this->raw = raw;
}
GitDiffList::~GitDiffList() {
git_diff_list_free(this->raw);
}
void GitDiffList::Initialize(Handle<v8::Object> target) {
NanScope();
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(NanSymbol("DiffList"));
NODE_SET_PROTOTYPE_METHOD(tpl, "merge", Merge);
NODE_SET_PROTOTYPE_METHOD(tpl, "findSimilar", FindSimilar);
NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size);
NODE_SET_METHOD(tpl, "numDeltasOfType", NumDeltasOfType);
NODE_SET_PROTOTYPE_METHOD(tpl, "patch", Patch);
NanAssignPersistent(FunctionTemplate, constructor_template, tpl);
target->Set(String::NewSymbol("DiffList"), tpl->GetFunction());
}
NAN_METHOD(GitDiffList::New) {
NanScope();
if (args.Length() == 0 || !args[0]->IsExternal()) {
return NanThrowError(String::New("git_diff_list is required."));
}
GitDiffList* object = new GitDiffList((git_diff_list *) External::Cast(*args[0])->Value());
object->Wrap(args.This());
NanReturnValue(args.This());
}
Handle<Value> GitDiffList::New(void *raw) {
NanScope();
Handle<Value> argv[1] = { External::New((void *)raw) };
Local<Object> instance;
Local<FunctionTemplate> constructorHandle = NanPersistentToLocal(constructor_template);
instance = constructorHandle->GetFunction()->NewInstance(1, argv);
return scope.Close(instance);
}
git_diff_list *GitDiffList::GetValue() {
return this->raw;
}
/**
* @param {DiffList} from
*/
NAN_METHOD(GitDiffList::Merge) {
NanScope();
if (args.Length() == 0 || !args[0]->IsObject()) {
return NanThrowError(String::New("DiffList from is required."));
}
const git_diff_list * from_from;
from_from = ObjectWrap::Unwrap<GitDiffList>(args[0]->ToObject())->GetValue();
int result = git_diff_merge(
ObjectWrap::Unwrap<GitDiffList>(args.This())->GetValue()
, from_from
);
if (result != GIT_OK) {
if (giterr_last()) {
return NanThrowError(String::New(giterr_last()->message));
} else {
return NanThrowError(String::New("Unkown Error"));
}
}
NanReturnUndefined();
}
/**
* @param {DiffFindOptions} options
*/
NAN_METHOD(GitDiffList::FindSimilar) {
NanScope();
if (args.Length() == 0 || !args[0]->IsObject()) {
return NanThrowError(String::New("DiffFindOptions options is required."));
}
git_diff_find_options * from_options;
from_options = ObjectWrap::Unwrap<GitDiffFindOptions>(args[0]->ToObject())->GetValue();
int result = git_diff_find_similar(
ObjectWrap::Unwrap<GitDiffList>(args.This())->GetValue()
, from_options
);
if (result != GIT_OK) {
if (giterr_last()) {
return NanThrowError(String::New(giterr_last()->message));
} else {
return NanThrowError(String::New("Unkown Error"));
}
}
NanReturnUndefined();
}
/**
* @return {Number} result
*/
NAN_METHOD(GitDiffList::Size) {
NanScope();
size_t result = git_diff_num_deltas(
ObjectWrap::Unwrap<GitDiffList>(args.This())->GetValue()
);
Handle<Value> to;
to = Uint32::New(result);
NanReturnValue(to);
}
/**
* @param {DiffList} diff
* @param {Number} type
* @return {Number} result
*/
NAN_METHOD(GitDiffList::NumDeltasOfType) {
NanScope();
if (args.Length() == 0 || !args[0]->IsObject()) {
return NanThrowError(String::New("DiffList diff is required."));
}
if (args.Length() == 1 || !args[1]->IsInt32()) {
return NanThrowError(String::New("Number type is required."));
}
git_diff_list * from_diff;
from_diff = ObjectWrap::Unwrap<GitDiffList>(args[0]->ToObject())->GetValue();
git_delta_t from_type;
from_type = (git_delta_t) args[1]->ToInt32()->Value();
size_t result = git_diff_num_deltas_of_type(
from_diff
, from_type
);
Handle<Value> to;
to = Uint32::New(result);
NanReturnValue(to);
}
/**
* @param {Number} idx
* @return {Patch} patch_out
* @return {Delta} delta_out
*/
NAN_METHOD(GitDiffList::Patch) {
NanScope();
if (args.Length() == 0 || !args[0]->IsUint32()) {
return NanThrowError(String::New("Number idx is required."));
}
git_diff_patch * patch_out = 0;
const git_diff_delta * delta_out = 0;
size_t from_idx;
from_idx = (size_t) args[0]->ToUint32()->Value();
int result = git_diff_get_patch(
&patch_out
, &delta_out
, ObjectWrap::Unwrap<GitDiffList>(args.This())->GetValue()
, from_idx
);
if (result != GIT_OK) {
if (giterr_last()) {
return NanThrowError(String::New(giterr_last()->message));
} else {
return NanThrowError(String::New("Unkown Error"));
}
}
Handle<Object> toReturn = Object::New();
Handle<Value> to;
if (patch_out != NULL) {
to = GitPatch::New((void *)patch_out);
} else {
to = Null();
}
toReturn->Set(String::NewSymbol("patch"), to);
if (delta_out != NULL) {
delta_out = (const git_diff_delta * )git_diff_delta_dup(delta_out);
}
if (delta_out != NULL) {
to = GitDelta::New((void *)delta_out);
} else {
to = Null();
}
toReturn->Set(String::NewSymbol("delta"), to);
NanReturnValue(toReturn);
}
Persistent<FunctionTemplate> GitDiffList::constructor_template;