@@ -33,6 +33,7 @@ void GitTree::Initialize (Handle<v8::Object> target) {
3333 tpl->InstanceTemplate ()->SetInternalFieldCount (1 );
3434 tpl->SetClassName (String::NewSymbol (" Tree" ));
3535
36+ NODE_SET_PROTOTYPE_METHOD (tpl, " lookup" , Lookup);
3637 NODE_SET_PROTOTYPE_METHOD (tpl, " walk" , Walk);
3738 NODE_SET_PROTOTYPE_METHOD (tpl, " entryByPath" , EntryByPath);
3839
@@ -57,6 +58,64 @@ Handle<Value> GitTree::New(const Arguments& args) {
5758 return scope.Close (args.This ());
5859}
5960
61+ Handle<Value> GitTree::Lookup (const Arguments& args) {
62+ HandleScope scope;
63+
64+ if (args.Length () == 0 || !args[0 ]->IsObject ()) {
65+ return ThrowException (Exception::Error (String::New (" Oid is required and must be a Object." )));
66+ }
67+
68+ if (args.Length () == 1 || !args[1 ]->IsObject ()) {
69+ return ThrowException (Exception::Error (String::New (" Repository is required and must be a Object." )));
70+ }
71+
72+ if (args.Length () == 2 || !args[2 ]->IsFunction ()) {
73+ return ThrowException (Exception::Error (String::New (" Callback is required and must be a Function." )));
74+ }
75+
76+ LookupBaton* baton = new LookupBaton;
77+ baton->request .data = baton;
78+ baton->error = NULL ;
79+ baton->rawTree = ObjectWrap::Unwrap<GitTree>(args.This ())->GetValue ();
80+ baton->rawOid = ObjectWrap::Unwrap<GitOid>(args[0 ]->ToObject ())->GetValue ();
81+ baton->rawRepo = ObjectWrap::Unwrap<GitRepo>(args[1 ]->ToObject ())->GetValue ();
82+ baton->callback = Persistent<Function>::New (Local<Function>::Cast (args[2 ]));
83+
84+ uv_queue_work (uv_default_loop (), &baton->request , LookupWork, (uv_after_work_cb)LookupAfterWork);
85+
86+ return Undefined ();
87+ }
88+ void GitTree::LookupWork (uv_work_t * req) {
89+ LookupBaton* baton = static_cast <LookupBaton*>(req->data );
90+
91+ int returnCode = git_tree_lookup (&baton->rawTree , baton->rawRepo , &baton->rawOid );
92+ if (returnCode != GIT_OK) {
93+ baton->error = giterr_last ();
94+ }
95+ }
96+ void GitTree::LookupAfterWork (uv_work_t * req) {
97+ HandleScope scope;
98+ LookupBaton* baton = static_cast <LookupBaton* >(req->data );
99+
100+ if (success (baton->error , baton->callback )) {
101+ Local<Object> tree = GitTree::constructor_template->NewInstance ();
102+ GitTree *treeInstance = ObjectWrap::Unwrap<GitTree>(tree);
103+ treeInstance->SetValue (baton->rawTree );
104+
105+ Handle<Value> argv[2 ] = {
106+ Local<Value>::New (Null ()),
107+ tree
108+ };
109+
110+ TryCatch try_catch;
111+ baton->callback ->Call (Context::GetCurrent ()->Global (), 2 , argv);
112+ if (try_catch.HasCaught ()) {
113+ node::FatalException (try_catch);
114+ }
115+ }
116+ delete req;
117+ }
118+
60119Handle<Value> GitTree::Walk (const Arguments& args) {
61120 HandleScope scope;
62121
0 commit comments