Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef0c27c

Browse files
committed
Expose git_libgit2_opts
Not all options are supported
1 parent 0598d40 commit ef0c27c

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

generate/input/libgit2-supplement.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@
8686
},
8787
"new" : {
8888
"functions": {
89+
"git_libgit2_opts": {
90+
"type": "function",
91+
"isManual": true,
92+
"cFile": "generate/templates/manual/libgit2/opts.cc",
93+
"isAsync": false,
94+
"isPrototypeMethod": false,
95+
"group": "libgit2"
96+
},
8997
"git_clone": {
9098
"isManual": true,
9199
"cFile": "generate/templates/manual/clone/clone.cc",
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
NAN_METHOD(GitLibgit2::Opts)
2+
{
3+
Nan::EscapableHandleScope scope;
4+
5+
if (info.Length() == 0 || !info[0]->IsNumber())
6+
{
7+
return Nan::ThrowError("Number option is required.");
8+
}
9+
10+
int from_option = (int)info[0].As<v8::Number>()->Value();
11+
12+
git_error_clear();
13+
14+
v8::Local<v8::Value> to;
15+
switch (from_option)
16+
{
17+
// GET size_t
18+
case GIT_OPT_GET_MWINDOW_SIZE:
19+
case GIT_OPT_GET_MWINDOW_MAPPED_LIMIT:
20+
case GIT_OPT_GET_PACK_MAX_OBJECTS:
21+
{
22+
size_t option_value;
23+
if (git_libgit2_opts(from_option, &option_value))
24+
{
25+
return Nan::ThrowError("git_libgit2_opts failed");
26+
}
27+
to = Nan::New<Number>(option_value);
28+
break;
29+
}
30+
// GET int
31+
case GIT_OPT_GET_WINDOWS_LONGPATHS:
32+
{
33+
int option_value;
34+
if (git_libgit2_opts(from_option, &option_value))
35+
{
36+
return Nan::ThrowError("git_libgit2_opts failed");
37+
}
38+
to = Nan::New<Number>(option_value);
39+
break;
40+
}
41+
// GET unsigned long
42+
case GIT_OPT_GET_WINDOWS_SHAREMODE:
43+
{
44+
unsigned long option_value;
45+
if (git_libgit2_opts(from_option, &option_value))
46+
{
47+
return Nan::ThrowError("git_libgit2_opts failed");
48+
}
49+
to = Nan::New<Number>(option_value);
50+
break;
51+
}
52+
// GET ssize_t
53+
case GIT_OPT_GET_CACHED_MEMORY:
54+
{
55+
ssize_t option_value;
56+
if (git_libgit2_opts(from_option, &option_value))
57+
{
58+
return Nan::ThrowError("git_libgit2_opts failed");
59+
}
60+
to = Nan::New<Number>(option_value);
61+
break;
62+
}
63+
// GET git_buf
64+
case GIT_OPT_GET_TEMPLATE_PATH:
65+
case GIT_OPT_GET_USER_AGENT:
66+
{
67+
git_buf option_value = {0};
68+
if (git_libgit2_opts(from_option, &option_value))
69+
{
70+
return Nan::ThrowError("git_libgit2_opts failed");
71+
}
72+
to = Nan::New<v8::String>(option_value.ptr, option_value.size).ToLocalChecked();
73+
git_buf_dispose(&option_value);
74+
break;
75+
}
76+
case GIT_OPT_GET_SEARCH_PATH:
77+
{
78+
git_buf option_value = {0};
79+
if (info.Length() < 2 || !info[1]->IsNumber())
80+
{
81+
return Nan::ThrowError("Number option is required.");
82+
}
83+
int level = (int)info[1].As<v8::Number>()->Value();
84+
if (git_libgit2_opts(from_option, level, &option_value))
85+
{
86+
return Nan::ThrowError("git_libgit2_opts failed");
87+
}
88+
to = Nan::New<v8::String>(option_value.ptr, option_value.size).ToLocalChecked();
89+
git_buf_dispose(&option_value);
90+
break;
91+
}
92+
// SET int
93+
case GIT_OPT_ENABLE_CACHING:
94+
case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION:
95+
case GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION:
96+
case GIT_OPT_ENABLE_OFS_DELTA:
97+
case GIT_OPT_ENABLE_FSYNC_GITDIR:
98+
case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION:
99+
case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY:
100+
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS:
101+
case GIT_OPT_SET_WINDOWS_LONGPATHS:
102+
{
103+
if (info.Length() < 2 || !info[1]->IsNumber())
104+
{
105+
return Nan::ThrowError("Number option is required.");
106+
}
107+
int option_arg = (int)info[1].As<v8::Number>()->Value();
108+
if (git_libgit2_opts(from_option, option_arg))
109+
{
110+
return Nan::ThrowError("git_libgit2_opts failed");
111+
}
112+
to = Nan::New<Number>(0);
113+
break;
114+
}
115+
// SET size_t
116+
case GIT_OPT_SET_MWINDOW_SIZE:
117+
case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT:
118+
case GIT_OPT_SET_PACK_MAX_OBJECTS:
119+
{
120+
if (info.Length() < 2 || !info[1]->IsNumber())
121+
{
122+
return Nan::ThrowError("Number option is required.");
123+
}
124+
size_t option_arg = (size_t)info[1].As<v8::Number>()->Value();
125+
if (git_libgit2_opts(from_option, option_arg))
126+
{
127+
return Nan::ThrowError("git_libgit2_opts failed");
128+
}
129+
to = Nan::New<Number>(0);
130+
break;
131+
}
132+
default:
133+
{
134+
return Nan::ThrowError("Unsupported option");
135+
}
136+
}
137+
138+
return info.GetReturnValue().Set(scope.Escape(to));
139+
}

0 commit comments

Comments
 (0)