Skip to content

Commit 6527aac

Browse files
committed
Extracted a partial for conversion from v8 types to c types
1 parent 486b0cc commit 6527aac

29 files changed

+483
-491
lines changed

TODO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
- rename all async methods getXXX
2-
- convert to "ignore": true for all classes
32
- reorder functions so the raw api is oo-like
43
- rename files remove .h
5-
- remove stringArgToString invocation

binding.gyp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
'src/diff_range.cc',
2727
'src/threads.cc',
2828
'src/wrapper.cc',
29-
'src/functions/string.cc',
3029
],
3130

3231
'include_dirs': [

src/blob.cc

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include "../include/wrapper.h"
1414
#include "node_buffer.h"
1515

16-
#include "../include/functions/string.h"
17-
1816
using namespace v8;
1917
using namespace node;
2018

@@ -73,8 +71,7 @@ git_blob *GitBlob::GetValue() {
7371

7472
Handle<Value> GitBlob::Lookup(const Arguments& args) {
7573
HandleScope scope;
76-
77-
if (args.Length() == 0 || !args[0]->IsObject()) {
74+
if (args.Length() == 0 || !args[0]->IsObject()) {
7875
return ThrowException(Exception::Error(String::New("Repository repo is required.")));
7976
}
8077
if (args.Length() == 1 || !args[1]->IsObject()) {
@@ -90,9 +87,11 @@ Handle<Value> GitBlob::Lookup(const Arguments& args) {
9087
baton->error = NULL;
9188
baton->request.data = baton;
9289
baton->repoReference = Persistent<Value>::New(args[0]);
93-
baton->repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
90+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
91+
baton->repo = from_repo;
9492
baton->idReference = Persistent<Value>::New(args[1]);
95-
baton->id = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject())->GetValue();
93+
const git_oid * from_id = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject())->GetValue();
94+
baton->id = from_id;
9695
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
9796

9897
uv_queue_work(uv_default_loop(), &baton->request, LookupWork, (uv_after_work_cb)LookupAfterWork);
@@ -153,7 +152,6 @@ Handle<Value> GitBlob::Oid(const Arguments& args) {
153152
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
154153
);
155154

156-
157155
Handle<Value> to;
158156
to = GitOid::New((void *)result);
159157
return scope.Close(to);
@@ -167,7 +165,6 @@ Handle<Value> GitBlob::Content(const Arguments& args) {
167165
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
168166
);
169167

170-
171168
Handle<Value> to;
172169
to = Wrapper::New((void *)result);
173170
return scope.Close(to);
@@ -181,16 +178,14 @@ Handle<Value> GitBlob::Size(const Arguments& args) {
181178
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
182179
);
183180

184-
185181
Handle<Value> to;
186182
to = Number::New(result);
187183
return scope.Close(to);
188184
}
189185

190186
Handle<Value> GitBlob::CreateFromFile(const Arguments& args) {
191187
HandleScope scope;
192-
193-
if (args.Length() == 0 || !args[0]->IsObject()) {
188+
if (args.Length() == 0 || !args[0]->IsObject()) {
194189
return ThrowException(Exception::Error(String::New("Repository repo is required.")));
195190
}
196191
if (args.Length() == 1 || !args[1]->IsString()) {
@@ -206,10 +201,12 @@ Handle<Value> GitBlob::CreateFromFile(const Arguments& args) {
206201
baton->error = NULL;
207202
baton->request.data = baton;
208203
baton->repoReference = Persistent<Value>::New(args[0]);
209-
baton->repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
204+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
205+
baton->repo = from_repo;
210206
baton->pathReference = Persistent<Value>::New(args[1]);
211-
String::Utf8Value path(args[1]->ToString());
212-
baton->path = strdup(*path);
207+
String::Utf8Value path(args[1]->ToString());
208+
const char * from_path = strdup(*path);
209+
baton->path = from_path;
213210
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
214211

215212
uv_queue_work(uv_default_loop(), &baton->request, CreateFromFileWork, (uv_after_work_cb)CreateFromFileAfterWork);
@@ -265,8 +262,7 @@ void GitBlob::CreateFromFileAfterWork(uv_work_t *req) {
265262

266263
Handle<Value> GitBlob::CreateFromBuffer(const Arguments& args) {
267264
HandleScope scope;
268-
269-
if (args.Length() == 0 || !args[0]->IsObject()) {
265+
if (args.Length() == 0 || !args[0]->IsObject()) {
270266
return ThrowException(Exception::Error(String::New("Repository repo is required.")));
271267
}
272268
if (args.Length() == 1 || !args[1]->IsObject()) {
@@ -285,11 +281,14 @@ Handle<Value> GitBlob::CreateFromBuffer(const Arguments& args) {
285281
baton->error = NULL;
286282
baton->request.data = baton;
287283
baton->repoReference = Persistent<Value>::New(args[0]);
288-
baton->repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
284+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
285+
baton->repo = from_repo;
289286
baton->bufferReference = Persistent<Value>::New(args[1]);
290-
baton->buffer = Buffer::Data(ObjectWrap::Unwrap<Buffer>(args[1]->ToObject()));
287+
const void * from_buffer = Buffer::Data(ObjectWrap::Unwrap<Buffer>(args[1]->ToObject()));
288+
baton->buffer = from_buffer;
291289
baton->lenReference = Persistent<Value>::New(args[2]);
292-
baton->len = (size_t) args[2]->ToNumber()->Value();
290+
size_t from_len = (size_t) args[2]->ToNumber()->Value();
291+
baton->len = from_len;
293292
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[3]));
294293

295294
uv_queue_work(uv_default_loop(), &baton->request, CreateFromBufferWork, (uv_after_work_cb)CreateFromBufferAfterWork);
@@ -351,7 +350,6 @@ Handle<Value> GitBlob::IsBinary(const Arguments& args) {
351350
int result = git_blob_is_binary(
352351
ObjectWrap::Unwrap<GitBlob>(args.This())->GetValue()
353352
);
354-
355353
if (result != GIT_OK) {
356354
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
357355
}

src/branch.cc

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#include "../include/branch.h"
1111

12-
#include "../include/functions/string.h"
13-
1412
using namespace v8;
1513
using namespace node;
1614

@@ -87,15 +85,20 @@ Handle<Value> Branch::Create(const Arguments& args) {
8785
}
8886

8987
git_reference *out = NULL;
88+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
89+
String::Utf8Value branch_name(args[1]->ToString());
90+
const char * from_branch_name = strdup(*branch_name);
91+
const git_commit * from_target = ObjectWrap::Unwrap<GitCommit>(args[2]->ToObject())->GetValue();
92+
int from_force = (int) args[3]->ToInt32()->Value();
9093

9194
int result = git_branch_create(
9295
&out
93-
, ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue()
94-
, stringArgToString(args[1]->ToString()).c_str()
95-
, ObjectWrap::Unwrap<GitCommit>(args[2]->ToObject())->GetValue()
96-
, (int) args[3]->ToInt32()->Value()
96+
, from_repo
97+
, from_branch_name
98+
, from_target
99+
, from_force
97100
);
98-
101+
delete from_branch_name;
99102
if (result != GIT_OK) {
100103
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
101104
}
@@ -111,11 +114,11 @@ Handle<Value> Branch::Delete(const Arguments& args) {
111114
return ThrowException(Exception::Error(String::New("Reference branch is required.")));
112115
}
113116

117+
git_reference * from_branch = ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue();
114118

115119
int result = git_branch_delete(
116-
ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue()
120+
from_branch
117121
);
118-
119122
if (result != GIT_OK) {
120123
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
121124
}
@@ -138,14 +141,17 @@ Handle<Value> Branch::Foreach(const Arguments& args) {
138141
return ThrowException(Exception::Error(String::New("void payload is required.")));
139142
}
140143

144+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
145+
unsigned int from_list_flags = (unsigned int) args[1]->ToUint32()->Value();
146+
git_branch_foreach_cb from_branch_cb = ObjectWrap::Unwrap<BranchForeachCb>(args[2]->ToObject())->GetValue();
147+
void * from_payload = ObjectWrap::Unwrap<void>(args[3]->ToObject())->GetValue();
141148

142149
int result = git_branch_foreach(
143-
ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue()
144-
, (unsigned int) args[1]->ToUint32()->Value()
145-
, ObjectWrap::Unwrap<BranchForeachCb>(args[2]->ToObject())->GetValue()
146-
, ObjectWrap::Unwrap<void>(args[3]->ToObject())->GetValue()
150+
from_repo
151+
, from_list_flags
152+
, from_branch_cb
153+
, from_payload
147154
);
148-
149155
if (result != GIT_OK) {
150156
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
151157
}
@@ -166,14 +172,18 @@ Handle<Value> Branch::Move(const Arguments& args) {
166172
}
167173

168174
git_reference *out = NULL;
175+
git_reference * from_branch = ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue();
176+
String::Utf8Value new_branch_name(args[1]->ToString());
177+
const char * from_new_branch_name = strdup(*new_branch_name);
178+
int from_force = (int) args[2]->ToInt32()->Value();
169179

170180
int result = git_branch_move(
171181
&out
172-
, ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue()
173-
, stringArgToString(args[1]->ToString()).c_str()
174-
, (int) args[2]->ToInt32()->Value()
182+
, from_branch
183+
, from_new_branch_name
184+
, from_force
175185
);
176-
186+
delete from_new_branch_name;
177187
if (result != GIT_OK) {
178188
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
179189
}
@@ -196,14 +206,18 @@ Handle<Value> Branch::Lookup(const Arguments& args) {
196206
}
197207

198208
git_reference *out = NULL;
209+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue();
210+
String::Utf8Value branch_name(args[1]->ToString());
211+
const char * from_branch_name = strdup(*branch_name);
212+
git_branch_t from_branch_type = ObjectWrap::Unwrap<BranchT>(args[2]->ToObject())->GetValue();
199213

200214
int result = git_branch_lookup(
201215
&out
202-
, ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject())->GetValue()
203-
, stringArgToString(args[1]->ToString()).c_str()
204-
, ObjectWrap::Unwrap<BranchT>(args[2]->ToObject())->GetValue()
216+
, from_repo
217+
, from_branch_name
218+
, from_branch_type
205219
);
206-
220+
delete from_branch_name;
207221
if (result != GIT_OK) {
208222
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
209223
}
@@ -220,12 +234,12 @@ Handle<Value> Branch::Name(const Arguments& args) {
220234
}
221235

222236
const char *out = NULL;
237+
git_reference * from_ref = ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue();
223238

224239
int result = git_branch_name(
225240
&out
226-
, ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue()
241+
, from_ref
227242
);
228-
229243
if (result != GIT_OK) {
230244
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
231245
}
@@ -242,12 +256,12 @@ Handle<Value> Branch::Upstream(const Arguments& args) {
242256
}
243257

244258
git_reference *out = NULL;
259+
git_reference * from_branch = ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue();
245260

246261
int result = git_branch_upstream(
247262
&out
248-
, ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue()
263+
, from_branch
249264
);
250-
251265
if (result != GIT_OK) {
252266
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
253267
}
@@ -266,12 +280,15 @@ Handle<Value> Branch::SetUpstream(const Arguments& args) {
266280
return ThrowException(Exception::Error(String::New("String upstream_name is required.")));
267281
}
268282

283+
git_reference * from_branch = ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue();
284+
String::Utf8Value upstream_name(args[1]->ToString());
285+
const char * from_upstream_name = strdup(*upstream_name);
269286

270287
int result = git_branch_set_upstream(
271-
ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue()
272-
, stringArgToString(args[1]->ToString()).c_str()
288+
from_branch
289+
, from_upstream_name
273290
);
274-
291+
delete from_upstream_name;
275292
if (result != GIT_OK) {
276293
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
277294
}
@@ -294,14 +311,21 @@ Handle<Value> Branch::UpstreamName(const Arguments& args) {
294311
return ThrowException(Exception::Error(String::New("String canonical_branch_name is required.")));
295312
}
296313

314+
String::Utf8Value tracking_branch_name_out(args[0]->ToString());
315+
char * from_tracking_branch_name_out = strdup(*tracking_branch_name_out);
316+
size_t from_buffer_size = (size_t) args[1]->ToUint32()->Value();
317+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[2]->ToObject())->GetValue();
318+
String::Utf8Value canonical_branch_name(args[3]->ToString());
319+
const char * from_canonical_branch_name = strdup(*canonical_branch_name);
297320

298321
int result = git_branch_upstream_name(
299-
stringArgToString(args[0]->ToString()).c_str()
300-
, (size_t) args[1]->ToUint32()->Value()
301-
, ObjectWrap::Unwrap<GitRepo>(args[2]->ToObject())->GetValue()
302-
, stringArgToString(args[3]->ToString()).c_str()
322+
from_tracking_branch_name_out
323+
, from_buffer_size
324+
, from_repo
325+
, from_canonical_branch_name
303326
);
304-
327+
delete from_tracking_branch_name_out;
328+
delete from_canonical_branch_name;
305329
if (result != GIT_OK) {
306330
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
307331
}
@@ -315,11 +339,11 @@ Handle<Value> Branch::IsHead(const Arguments& args) {
315339
return ThrowException(Exception::Error(String::New("Reference branch is required.")));
316340
}
317341

342+
git_reference * from_branch = ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue();
318343

319344
int result = git_branch_is_head(
320-
ObjectWrap::Unwrap<GitReference>(args[0]->ToObject())->GetValue()
345+
from_branch
321346
);
322-
323347
if (result != GIT_OK) {
324348
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
325349
}
@@ -342,14 +366,21 @@ Handle<Value> Branch::RemoteName(const Arguments& args) {
342366
return ThrowException(Exception::Error(String::New("String canonical_branch_name is required.")));
343367
}
344368

369+
String::Utf8Value remote_name_out(args[0]->ToString());
370+
char * from_remote_name_out = strdup(*remote_name_out);
371+
size_t from_buffer_size = (size_t) args[1]->ToUint32()->Value();
372+
git_repository * from_repo = ObjectWrap::Unwrap<GitRepo>(args[2]->ToObject())->GetValue();
373+
String::Utf8Value canonical_branch_name(args[3]->ToString());
374+
const char * from_canonical_branch_name = strdup(*canonical_branch_name);
345375

346376
int result = git_branch_remote_name(
347-
stringArgToString(args[0]->ToString()).c_str()
348-
, (size_t) args[1]->ToUint32()->Value()
349-
, ObjectWrap::Unwrap<GitRepo>(args[2]->ToObject())->GetValue()
350-
, stringArgToString(args[3]->ToString()).c_str()
377+
from_remote_name_out
378+
, from_buffer_size
379+
, from_repo
380+
, from_canonical_branch_name
351381
);
352-
382+
delete from_remote_name_out;
383+
delete from_canonical_branch_name;
353384
if (result != GIT_OK) {
354385
return ThrowException(Exception::Error(String::New(giterr_last()->message)));
355386
}

0 commit comments

Comments
 (0)