FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodegit/src/reference.cc at v0.0.75 · nodegit/nodegit · GitHub
nodegit
nodegit
Repository navigation
Code
Issues
344
(344)
Pull requests
21
(21)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nodegit
/
src
/
reference.cc
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
206 lines (158 loc) · 5.53 KB
Breadcrumbs
nodegit
/
src
/
reference.cc
Copy path
File metadata and controls
executable file
·
206 lines (158 loc) · 5.53 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
/*
* Copyright 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
* @author Michael Robinson @codeofinterest <mike@pagesofinterest.net>
*
* Dual licensed under the MIT and GPL licenses.
*/
#
include
<
v8.h
>
#
include
<
node.h
>
#
include
<
string
>
#
include
"
../vendor/libgit2/include/git2.h
"
#
include
"
../include/repo.h
"
#
include
"
../include/reference.h
"
#
include
"
../include/oid.h
"
#
include
"
../include/error.h
"
#
include
"
../include/functions/string.h
"
using
namespace
v8
;
using
namespace
node
;
void
GitReference::Initialize
(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> tpl =
FunctionTemplate::New
(New);
tpl->
InstanceTemplate
()->
SetInternalFieldCount
(
1
);
tpl->
SetClassName
(
String::NewSymbol
(
"
Reference
"
));
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
oid
"
, Oid);
NODE_SET_PROTOTYPE_METHOD
(tpl,
"
lookup
"
, Lookup);
constructor_template = Persistent<Function>::
New
(tpl->
GetFunction
());
target->
Set
(
String::NewSymbol
(
"
Reference
"
), constructor_template);
}
git_reference*
GitReference::GetValue
() {
return
this
->
ref
;
}
void
GitReference::SetValue
(git_reference *ref) {
this
->
ref
= ref;
}
Handle<Value>
GitReference::New
(
const
Arguments& args) {
HandleScope scope;
GitReference *ref =
new
GitReference
();
ref->
Wrap
(args.
This
());
return
args.
This
();
}
Handle<Value>
GitReference::Oid
(
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.
"
)));
}
OidBaton *baton =
new
OidBaton;
baton->
request
.
data
= baton;
baton->
error
=
NULL
;
baton->
rawOid
=
NULL
;
baton->
rawRef
= ObjectWrap::Unwrap<GitReference>(args.
This
())->
GetValue
();
baton->
callback
= Persistent<Function>::
New
(Local<Function>::
Cast
(args[
0
]));
uv_queue_work
(
uv_default_loop
(), &baton->
request
, OidWork, (uv_after_work_cb)OidAfterWork);
return
Undefined
();
}
void
GitReference::OidWork
(
uv_work_t
* req) {
OidBaton *baton =
static_cast
<OidBaton *>(req->
data
);
git_ref_t
referenceType =
git_reference_type
(baton->
rawRef
);
if
(referenceType ==
GIT_REF_INVALID
) {
printf
(
"
invalid
\n
"
);
giterr_set_str
(
GITERR_INVALID
,
"
Invalid reference type
"
);
baton->
error
=
giterr_last
();
return
;
}
if
(referenceType ==
GIT_REF_SYMBOLIC
) {
printf
(
"
symbolic
\n
"
);
int
returnCode =
git_reference_resolve
(&baton->
rawRef
, baton->
rawRef
);
if
(returnCode !=
GIT_OK
) {
baton->
error
=
giterr_last
();
return
;
}
}
baton->
rawOid
=
git_reference_target
(baton->
rawRef
);
}
void
GitReference::OidAfterWork
(
uv_work_t
* req) {
HandleScope scope;
OidBaton *baton =
static_cast
<OidBaton *>(req->
data
);
if
(baton->
error
) {
Local<Value> argv[
1
] = {
GitError::WrapError
(baton->
error
)
};
TryCatch try_catch;
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
1
, argv);
if
(try_catch.
HasCaught
()) {
node::FatalException
(try_catch);
}
}
else
{
Handle<Object> oid = GitOid::constructor_template->
NewInstance
();
GitOid *oidInstance = ObjectWrap::Unwrap<GitOid>(oid);
oidInstance->
SetValue
(*
const_cast
<git_oid *>(baton->
rawOid
));
Handle<Value> argv[
2
] = {
Local<Value>::
New
(
Null
()),
oid
};
TryCatch try_catch;
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
2
, argv);
if
(try_catch.
HasCaught
()) {
node::FatalException
(try_catch);
}
}
delete
req;
}
Handle<Value>
GitReference::Lookup
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() ==
0
|| !args[
0
]->
IsObject
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Repo is required and must be a Object.
"
)));
}
if
(args.
Length
() ==
1
|| !args[
1
]->
IsString
()) {
return
ThrowException
(
Exception::Error
(
String::New
(
"
Name is required and must be a String.
"
)));
}
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->
request
.
data
= baton;
baton->
ref
= ObjectWrap::Unwrap<GitReference>(args.
This
());
baton->
ref
->
Ref
();
baton->
error
=
NULL
;
baton->
rawRepo
= ObjectWrap::Unwrap<GitRepo>(args[
0
]->
ToObject
())->
GetValue
();
baton->
name
=
stringArgToString
(args[
1
]->
ToString
());
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
GitReference::LookupWork
(
uv_work_t
*req) {
LookupBaton *baton =
static_cast
<LookupBaton *>(req->
data
);
baton->
rawRef
=
NULL
;
int
returnCode =
git_reference_lookup
(&baton->
rawRef
, baton->
rawRepo
, baton->
name
.
c_str
());
if
(returnCode !=
GIT_OK
) {
baton->
error
=
giterr_last
();
}
}
void
GitReference::LookupAfterWork
(
uv_work_t
*req) {
HandleScope scope;
LookupBaton *baton =
static_cast
<LookupBaton *>(req->
data
);
if
(baton->
error
) {
Local<Value> argv[
1
] = {
GitError::WrapError
(baton->
error
)
};
TryCatch try_catch;
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
1
, argv);
if
(try_catch.
HasCaught
()) {
node::FatalException
(try_catch);
}
}
else
{
baton->
ref
->
SetValue
(baton->
rawRef
);
Handle<Value> argv[
2
] = {
Local<Value>::
New
(
Null
()),
baton->
ref
->
handle_
};
TryCatch try_catch;
baton->
callback
->
Call
(
Context::GetCurrent
()->
Global
(),
2
, argv);
if
(try_catch.
HasCaught
()) {
node::FatalException
(try_catch);
}
}
baton->
ref
->
Unref
();
delete
req;
}
Persistent<Function> GitReference::constructor_template;
Back
|
FazBrowse Home
|
New Git URL