FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/src/commit.cc at 552fae76481b86862469c5bb26b08f4b22ed3c9a · nodegit/nodegit · GitHub
nodegit
nodegit
Repository navigation
Code
Issues
344
(344)
Pull requests
23
(23)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
src
/
commit.cc
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
444 lines (327 loc) · 11.8 KB
Breadcrumbs
nodegit
/
src
/
commit.cc
Copy path
File metadata and controls
executable file
·
444 lines (327 loc) · 11.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
/*
*
* 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/commit.h
"
#
include
"
../include/oid.h
"
#
include
"
../include/repo.h
"
#
include
"
../include/signature.h
"
#
include
"
../include/tree.h
"
#
include
"
../include/functions/utilities.h
"
#
include
"
../include/functions/string.h
"
using
namespace
v8
;
using
namespace
node
;
GitCommit::GitCommit
(git_commit *raw) {
this
->
raw
= raw;
}
GitCommit::~GitCommit
() {
git_commit_free
(
this
->
raw
);
}
void
GitCommit::Initialize
(Handle<v8::Object> target) {
HandleScope scope;
Local<FunctionTemplate> tpl =
FunctionTemplate::New
(New);
tpl->
InstanceTemplate
()->
SetInternalFieldCount
(
1
);
tpl->
SetClassName
(
String::NewSymbol
(
"
Commit
"
));
NODE_SET_METHOD
(tpl,
"
lookup
"
, Lookup);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
oid
"
, Oid);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
messageEncoding
"
, MessageEncoding);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
message
"
, Message);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
time
"
, Time);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
offset
"
, Offset);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
committer
"
, Committer);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
author
"
, Author);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
tree
"
, Tree);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
treeId
"
, TreeId);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
parentCount
"
, ParentCount);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
parent
"
, Parent);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
parentId
"
, ParentId);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
nthGenAncestor
"
, NthGenAncestor);
constructor_template = Persistent<Function>::
New
(tpl->
GetFunction
());
target->
Set
(
String::NewSymbol
(
"
Commit
"
), constructor_template);
}
Handle<Value>
GitCommit::New
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsExternal
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
git_commit is required.
"
)));
}
GitCommit* object =
new
GitCommit
((git_commit *)
External::Unwrap
(args[
0
]));
object->
Wrap
(args.
This
());
return
scope.
Close
(args.
This
());
}
git_commit *
GitCommit::GetValue
() {
return
this
->
raw
;
}
Handle<Value>
GitCommit::Lookup
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsObject
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Repository repo is required.
"
)));
}
if
(args.
Length
() ==
1
|| !args[
1
]->
IsObject
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Oid id is required.
"
)));
}
if
(args.
Length
() ==
2
|| !args[
2
]->
IsFunction
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Callback is required and must be a Function.
"
)));
}
LookupBaton* baton =
new
LookupBaton;
baton->
error
=
NULL
;
baton->
request
.
data
= baton;
baton->
repoReference
= Persistent<Value>::
New
(args[
0
]);
baton->
repo
= ObjectWrap::Unwrap<GitRepo>(args[
0
]->
ToObject
())->
GetValue
();
baton->
idReference
= Persistent<Value>::
New
(args[
1
]);
baton->
id
= ObjectWrap::Unwrap<GitOid>(args[
1
]->
ToObject
())->
GetValue
();
baton->
callback
= Persistent<Function>::
New
(Local<Function>::
Cast
(args[
2
]));
uv_queue_work
(
uv_default_loop
(), &baton->
request
, LookupWork, (uv_after_work_cb)LookupAfterWork);
return
Undefined
();
}
void
GitCommit::LookupWork
(
uv_work_t
*req) {
LookupBaton *baton =
static_cast
<LookupBaton *>(req->
data
);
int
commit =
git_commit_lookup
(
&baton->
commit
,
baton->
repo
,
baton->
id
);
if
(commit !=
GIT_OK
) {
baton->
error
=
giterr_last
();
}
}
void
GitCommit::LookupAfterWork
(
uv_work_t
*req) {
HandleScope scope;
LookupBaton *baton =
static_cast
<LookupBaton *>(req->
data
);
TryCatch try_catch;
if
(!baton->
error
) {
Handle<Value> argv[
1
] = {
External::New
(baton->
commit
) };
Handle<Object> commit = GitCommit::constructor_template->
NewInstance
(
1
, argv);
Handle<Value> argv2[
2
] = {
Local<Value>::
New
(
Null
()),
commit
};
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
2
, argv2);
}
else
{
Handle<Value> argv2[
1
] = {
GitError::WrapError
(baton->
error
)
};
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
1
, argv2);
}
if
(try_catch.
HasCaught
()) {
node::FatalException
(try_catch);
}
baton->
repoReference
.
Dispose
();
baton->
idReference
.
Dispose
();
baton->
callback
.
Dispose
();
delete
baton;
}
Handle<Value>
GitCommit::Oid
(
const
Arguments& args) {
HandleScope scope;
const
git_oid * result =
git_commit_id
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
//
XXX need to copy object?
Handle<Value> argv[
1
] = {
External::New
((
void
*)result) };
return
scope.
Close
(GitOid::constructor_template->
NewInstance
(
1
, argv));
}
Handle<Value>
GitCommit::MessageEncoding
(
const
Arguments& args) {
HandleScope scope;
const
char
* result =
git_commit_message_encoding
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
return
scope.
Close
(
String::New
(result));
}
Handle<Value>
GitCommit::Message
(
const
Arguments& args) {
HandleScope scope;
const
char
* result =
git_commit_message
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
return
scope.
Close
(
String::New
(result));
}
Handle<Value>
GitCommit::Time
(
const
Arguments& args) {
HandleScope scope;
git_time_t
result =
git_commit_time
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
return
scope.
Close
(
Number::New
(result));
}
Handle<Value>
GitCommit::Offset
(
const
Arguments& args) {
HandleScope scope;
int
result =
git_commit_time_offset
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
return
scope.
Close
(
Integer::New
(result));
}
Handle<Value>
GitCommit::Committer
(
const
Arguments& args) {
HandleScope scope;
const
git_signature * result =
git_commit_committer
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
//
XXX need to copy object?
Handle<Value> argv[
1
] = {
External::New
((
void
*)result) };
return
scope.
Close
(GitSignature::constructor_template->
NewInstance
(
1
, argv));
}
Handle<Value>
GitCommit::Author
(
const
Arguments& args) {
HandleScope scope;
const
git_signature * result =
git_commit_author
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
//
XXX need to copy object?
Handle<Value> argv[
1
] = {
External::New
((
void
*)result) };
return
scope.
Close
(GitSignature::constructor_template->
NewInstance
(
1
, argv));
}
Handle<Value>
GitCommit::Tree
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsFunction
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Callback is required and must be a Function.
"
)));
}
TreeBaton* baton =
new
TreeBaton;
baton->
error
=
NULL
;
baton->
request
.
data
= baton;
baton->
commitReference
= Persistent<Value>::
New
(args.
This
());
baton->
commit
= ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
();
baton->
callback
= Persistent<Function>::
New
(Local<Function>::
Cast
(args[
0
]));
uv_queue_work
(
uv_default_loop
(), &baton->
request
, TreeWork, (uv_after_work_cb)TreeAfterWork);
return
Undefined
();
}
void
GitCommit::TreeWork
(
uv_work_t
*req) {
TreeBaton *baton =
static_cast
<TreeBaton *>(req->
data
);
int
tree_out =
git_commit_tree
(
&baton->
tree_out
,
baton->
commit
);
if
(tree_out !=
GIT_OK
) {
baton->
error
=
giterr_last
();
}
}
void
GitCommit::TreeAfterWork
(
uv_work_t
*req) {
HandleScope scope;
TreeBaton *baton =
static_cast
<TreeBaton *>(req->
data
);
TryCatch try_catch;
if
(!baton->
error
) {
Handle<Value> argv[
1
] = {
External::New
(baton->
tree_out
) };
Handle<Object> tree_out = GitTree::constructor_template->
NewInstance
(
1
, argv);
Handle<Value> argv2[
2
] = {
Local<Value>::
New
(
Null
()),
tree_out
};
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
2
, argv2);
}
else
{
Handle<Value> argv2[
1
] = {
GitError::WrapError
(baton->
error
)
};
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
1
, argv2);
}
if
(try_catch.
HasCaught
()) {
node::FatalException
(try_catch);
}
baton->
commitReference
.
Dispose
();
baton->
callback
.
Dispose
();
delete
baton;
}
Handle<Value>
GitCommit::TreeId
(
const
Arguments& args) {
HandleScope scope;
const
git_oid * result =
git_commit_tree_id
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
//
XXX need to copy object?
Handle<Value> argv[
1
] = {
External::New
((
void
*)result) };
return
scope.
Close
(GitOid::constructor_template->
NewInstance
(
1
, argv));
}
Handle<Value>
GitCommit::ParentCount
(
const
Arguments& args) {
HandleScope scope;
unsigned
int
result =
git_commit_parentcount
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
);
return
scope.
Close
(
Uint32::New
(result));
}
Handle<Value>
GitCommit::Parent
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsUint32
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Number n is required.
"
)));
}
if
(args.
Length
() ==
1
|| !args[
1
]->
IsFunction
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Callback is required and must be a Function.
"
)));
}
ParentBaton* baton =
new
ParentBaton;
baton->
error
=
NULL
;
baton->
request
.
data
= baton;
baton->
commitReference
= Persistent<Value>::
New
(args.
This
());
baton->
commit
= ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
();
baton->
nReference
= Persistent<Value>::
New
(args[
0
]);
baton->
n
= (
unsigned
int
) args[
0
]->
ToUint32
()->
Value
();
baton->
callback
= Persistent<Function>::
New
(Local<Function>::
Cast
(args[
1
]));
uv_queue_work
(
uv_default_loop
(), &baton->
request
, ParentWork, (uv_after_work_cb)ParentAfterWork);
return
Undefined
();
}
void
GitCommit::ParentWork
(
uv_work_t
*req) {
ParentBaton *baton =
static_cast
<ParentBaton *>(req->
data
);
int
out =
git_commit_parent
(
&baton->
out
,
baton->
commit
,
baton->
n
);
if
(out !=
GIT_OK
) {
baton->
error
=
giterr_last
();
}
}
void
GitCommit::ParentAfterWork
(
uv_work_t
*req) {
HandleScope scope;
ParentBaton *baton =
static_cast
<ParentBaton *>(req->
data
);
TryCatch try_catch;
if
(!baton->
error
) {
Handle<Value> argv[
1
] = {
External::New
(baton->
out
) };
Handle<Object> out = GitCommit::constructor_template->
NewInstance
(
1
, argv);
Handle<Value> argv2[
2
] = {
Local<Value>::
New
(
Null
()),
out
};
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
2
, argv2);
}
else
{
Handle<Value> argv2[
1
] = {
GitError::WrapError
(baton->
error
)
};
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
1
, argv2);
}
if
(try_catch.
HasCaught
()) {
node::FatalException
(try_catch);
}
baton->
commitReference
.
Dispose
();
baton->
nReference
.
Dispose
();
baton->
callback
.
Dispose
();
delete
baton;
}
Handle<Value>
GitCommit::ParentId
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsUint32
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Number n is required.
"
)));
}
const
git_oid * result =
git_commit_parent_id
(
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
,
(
unsigned
int
) args[
0
]->
ToUint32
()->
Value
()
);
//
XXX need to copy object?
Handle<Value> argv[
1
] = {
External::New
((
void
*)result) };
return
scope.
Close
(GitOid::constructor_template->
NewInstance
(
1
, argv));
}
Handle<Value>
GitCommit::NthGenAncestor
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsUint32
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Number n is required.
"
)));
}
git_commit * ancestor;
int
result =
git_commit_nth_gen_ancestor
(
&
ancestor
,
ObjectWrap::Unwrap<GitCommit>(args.
This
())->
GetValue
()
,
(
unsigned
int
) args[
0
]->
ToUint32
()->
Value
()
);
if
(result !=
GIT_OK
) {
return
ThrowException
(
GitError::WrapError
(
giterr_last
()));
}
//
XXX need to copy object?
Handle<Value> argv[
1
] = {
External::New
((
void
*)ancestor) };
return
scope.
Close
(GitCommit::constructor_template->
NewInstance
(
1
, argv));
}
Persistent<Function> GitCommit::constructor_template;
Back
|
FazBrowse Home
|
New Git URL