Skip to content

Commit eaeec38

Browse files
committed
Added tree entry filemode methods' body
1 parent 31746e2 commit eaeec38

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

include/tree_entry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class GitTreeEntry : ObjectWrap {
7474
uv_work_t request;
7575

7676
git_tree_entry* rawEntry;
77-
int fileMode;
77+
git_filemode_t fileMode;
7878

7979
Persistent<Function> callback;
8080
};

src/tree_entry.cc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,41 @@ void GitTreeEntry::NameAfterWork(uv_work_t* req) {
145145
}
146146

147147
Handle<Value> GitTreeEntry::FileMode(const Arguments& args) {
148-
// HandleScope scope;
148+
HandleScope scope;
149149

150-
// GitTreeEntry *entry = ObjectWrap::Unwrap<GitTreeEntry>(args.This());
150+
if(args.Length() == 0 || !args[0]->IsFunction()) {
151+
return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
152+
}
153+
154+
FileModeBaton *baton = new FileModeBaton;
155+
baton->request.data = baton;
156+
baton->rawEntry = ObjectWrap::Unwrap<GitTreeEntry>(args.This())->GetValue();
157+
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[0]));
158+
159+
uv_queue_work(uv_default_loop(), &baton->request, FileModeWork, (uv_after_work_cb)FileModeAfterWork);
151160

152-
// return scope.Close(Number::New(git_tree_entry_filemode(entry->entry)));
153161
return Undefined();
154162
}
155163
void GitTreeEntry::FileModeWork(uv_work_t* req) {
164+
FileModeBaton *baton = static_cast<FileModeBaton *>(req->data);
156165

157-
166+
baton->fileMode = git_tree_entry_filemode(baton->rawEntry);
158167
}
159168
void GitTreeEntry::FileModeAfterWork(uv_work_t* req) {
169+
HandleScope scope;
170+
FileModeBaton *baton = static_cast<FileModeBaton *>(req->data);
160171

172+
Handle<Value> argv[2] = {
173+
Local<Value>::New(Null()),
174+
Integer::New(baton->fileMode)
175+
};
176+
177+
TryCatch try_catch;
178+
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
179+
if (try_catch.HasCaught()) {
180+
node::FatalException(try_catch);
181+
}
182+
delete req;
161183
}
162184

163185
Handle<Value> GitTreeEntry::Oid(const Arguments& args) {

0 commit comments

Comments
 (0)