Skip to content

Commit 8ae2436

Browse files
committed
Longpaths options should take/return boolean values
1 parent e4e66f4 commit 8ae2436

File tree

1 file changed

+24
-9
lines changed
  • generate/templates/manual/libgit2

1 file changed

+24
-9
lines changed

generate/templates/manual/libgit2/opts.cc

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NAN_METHOD(GitLibgit2::Opts)
66
return Nan::ThrowError("Number option is required.");
77
}
88

9-
int from_option = (int)info[0].As<v8::Number>()->Value();
9+
const int from_option = (int)info[0].As<v8::Number>()->Value();
1010

1111
git_error_clear();
1212

@@ -23,13 +23,13 @@ NAN_METHOD(GitLibgit2::Opts)
2323
to = Nan::New<Number>(option_value);
2424
break;
2525
}
26-
// GET int
26+
// GET bool
2727
case GIT_OPT_GET_WINDOWS_LONGPATHS: {
2828
int option_value;
2929
if (git_libgit2_opts(from_option, &option_value)) {
3030
return Nan::ThrowError("git_libgit2_opts failed");
3131
}
32-
to = Nan::New<Number>(option_value);
32+
to = option_value ? Nan::True() : Nan::False();
3333
break;
3434
}
3535
// GET unsigned long
@@ -67,7 +67,7 @@ NAN_METHOD(GitLibgit2::Opts)
6767
if (info.Length() < 2 || !info[1]->IsNumber()) {
6868
return Nan::ThrowError("Number option is required.");
6969
}
70-
int level = (int)info[1].As<v8::Number>()->Value();
70+
const int level = (int)info[1].As<v8::Number>()->Value();
7171
if (git_libgit2_opts(from_option, level, &option_value)) {
7272
return Nan::ThrowError("git_libgit2_opts failed");
7373
}
@@ -84,30 +84,45 @@ NAN_METHOD(GitLibgit2::Opts)
8484
case GIT_OPT_ENABLE_FSYNC_GITDIR:
8585
case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION:
8686
case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY:
87-
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS:
88-
case GIT_OPT_SET_WINDOWS_LONGPATHS: {
87+
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS: {
8988
if (info.Length() < 2 || !info[1]->IsNumber()) {
9089
return Nan::ThrowError("Number option is required.");
9190
}
92-
int option_arg = (int)info[1].As<v8::Number>()->Value();
91+
const int option_arg = (int)info[1].As<v8::Number>()->Value();
9392
if (git_libgit2_opts(from_option, option_arg)) {
9493
return Nan::ThrowError("git_libgit2_opts failed");
9594
}
9695
to = Nan::New<Number>(0);
9796
break;
9897
}
98+
// SET bool
99+
case GIT_OPT_SET_WINDOWS_LONGPATHS: {
100+
int option_arg;
101+
if (info.Length() < 2) {
102+
option_arg = 0;
103+
} else {
104+
const Nan::Maybe<bool> maybeIsTruthy = Nan::To<bool>(info[1]);
105+
const bool isTruthy = maybeIsTruthy.IsJust() && maybeIsTruthy.FromJust();
106+
option_arg = isTruthy ? 1 : 0;
107+
}
108+
if (git_libgit2_opts(from_option, option_arg)) {
109+
return Nan::ThrowError("git_libgit2_opts failed");
110+
}
111+
to = Nan::Undefined();
112+
break;
113+
}
99114
// SET size_t
100115
case GIT_OPT_SET_MWINDOW_SIZE:
101116
case GIT_OPT_SET_MWINDOW_MAPPED_LIMIT:
102117
case GIT_OPT_SET_PACK_MAX_OBJECTS: {
103118
if (info.Length() < 2 || !info[1]->IsNumber()) {
104119
return Nan::ThrowError("Number option is required.");
105120
}
106-
size_t option_arg = (size_t)info[1].As<v8::Number>()->Value();
121+
const size_t option_arg = (size_t)info[1].As<v8::Number>()->Value();
107122
if (git_libgit2_opts(from_option, option_arg)) {
108123
return Nan::ThrowError("git_libgit2_opts failed");
109124
}
110-
to = Nan::New<Number>(0);
125+
to = Nan::Undefined();
111126
break;
112127
}
113128
default: {

0 commit comments

Comments
 (0)