Skip to content

Commit cb1d6dd

Browse files
committed
Cleaned out tree
1 parent 2741df1 commit cb1d6dd

2 files changed

Lines changed: 1 addition & 251 deletions

File tree

include/tree.h

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -48,88 +48,22 @@ class GitTree : public ObjectWrap {
4848
* @param obj a git_tree object
4949
*/
5050
void SetValue(git_tree* tree);
51-
/**
52-
* Lookup a tree object from a repository.
53-
*
54-
* @param repo the repo to use when locating the tree.
55-
* @param id identity of the tree to locate.
56-
*
57-
* @return 0 on success; error code otherwise
58-
*/
59-
int Lookup(git_repository* repo, const git_oid* id);
60-
/**
61-
* Get number of entries in the looked up tree.
62-
*
63-
* @return number of entries
64-
*/
65-
size_t EntryCount();
66-
/**
67-
* Get entry by index in the looked up tree.
68-
*
69-
* @param idx index of the entry
70-
*
71-
* @return git tree entry
72-
*/
73-
git_tree_entry* EntryByIndex(int idx);
74-
75-
int SortEntries();
76-
void ClearEntries();
7751

7852
protected:
79-
/**
80-
* Constructor
81-
*/
8253
GitTree() {};
83-
/**
84-
* Deconstructor
85-
*/
8654
~GitTree() {};
87-
/**
88-
* Creates a new instance of GitTree to Node.js
89-
*
90-
* @param args v8::Arguments function call arguments from Node.js
91-
*
92-
* @return v8::Object args.This()
93-
*/
55+
9456
static Handle<Value> New(const Arguments& args);
9557

96-
static Handle<Value> Lookup(const Arguments& args);
97-
static void EIO_Lookup(uv_work_t *req);
98-
static void EIO_AfterLookup(uv_work_t *req);
99-
static Handle<Value> EntryCount(const Arguments& args);
100-
static Handle<Value> EntryByIndex(const Arguments& args);
101-
static void EIO_EntryByIndex(uv_work_t *req);
102-
static void EIO_AfterEntryByIndex(uv_work_t *req);
10358
static Handle<Value> EntryByPath(const Arguments& args);
10459
static void EntryByPathWork(uv_work_t *req);
10560
static void EntryByPathAfterWork(uv_work_t *req);
106-
static Handle<Value> SortEntries(const Arguments& args);
107-
static Handle<Value> ClearEntries(const Arguments& args);
10861

10962
private:
11063
/**
11164
* Internal reference to git_tree object
11265
*/
11366
git_tree* tree;
114-
/**
115-
* Structure to handle async lookups
116-
*/
117-
struct lookup_request {
118-
GitTree* tree;
119-
GitRepo* repo;
120-
GitOid* oid;
121-
int err;
122-
Persistent<Function> callback;
123-
};
124-
/**
125-
* Structure to handle async entryByIndex
126-
*/
127-
struct entryindex_request {
128-
GitTree* tree;
129-
GitTreeEntry* entry;
130-
int idx;
131-
Persistent<Function> callback;
132-
};
13367

13468
struct EntryByPathBaton {
13569
uv_work_t request;

src/tree.cc

Lines changed: 0 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ void GitTree::Initialize (Handle<v8::Object> target) {
3030
tpl->InstanceTemplate()->SetInternalFieldCount(1);
3131
tpl->SetClassName(String::NewSymbol("Tree"));
3232

33-
NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup);
34-
NODE_SET_PROTOTYPE_METHOD(tpl, "entryCount", EntryCount);
35-
NODE_SET_PROTOTYPE_METHOD(tpl, "entryByIndex", EntryByIndex);
3633
NODE_SET_PROTOTYPE_METHOD(tpl, "entryByPath", EntryByPath);
37-
NODE_SET_PROTOTYPE_METHOD(tpl, "sortEntries", EntryCount);
3834

3935
constructor_template = Persistent<Function>::New(tpl->GetFunction());
4036
target->Set(String::NewSymbol("Tree"), constructor_template);
@@ -43,28 +39,10 @@ void GitTree::Initialize (Handle<v8::Object> target) {
4339
git_tree* GitTree::GetValue() {
4440
return this->tree;
4541
}
46-
4742
void GitTree::SetValue(git_tree* tree) {
4843
this->tree = tree;
4944
}
5045

51-
int GitTree::Lookup(git_repository* repo, const git_oid* id) {
52-
return git_tree_lookup(&this->tree, repo, id);
53-
}
54-
55-
size_t GitTree::EntryCount() {
56-
return git_tree_entrycount(this->tree);
57-
}
58-
59-
git_tree_entry* GitTree::EntryByIndex(int idx) {
60-
return const_cast<git_tree_entry*>(git_tree_entry_byindex(this->tree, idx));
61-
}
62-
63-
int GitTree::SortEntries() {
64-
//return git_tree_sort_entries(this->tree);
65-
return 0;
66-
}
67-
6846
Handle<Value> GitTree::New(const Arguments& args) {
6947
HandleScope scope;
7048

@@ -75,149 +53,6 @@ Handle<Value> GitTree::New(const Arguments& args) {
7553
return scope.Close(args.This());
7654
}
7755

78-
Handle<Value> GitTree::Lookup(const Arguments& args) {
79-
HandleScope scope;
80-
81-
GitTree *tree = ObjectWrap::Unwrap<GitTree>(args.This());
82-
83-
if(args.Length() == 0 || !args[0]->IsObject()) {
84-
return ThrowException(Exception::Error(String::New("Repo is required and must be an Object.")));
85-
}
86-
87-
if(args.Length() == 1 || !args[1]->IsObject()) {
88-
return ThrowException(Exception::Error(String::New("Oid is required and must be an Object.")));
89-
}
90-
91-
GitRepo* repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject());
92-
GitOid* oid = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject());
93-
94-
git_oid ref_oid = oid->GetValue();
95-
int err = tree->Lookup(repo->GetValue(), &ref_oid);
96-
97-
return scope.Close( Integer::New(err) );
98-
99-
// if(args.Length() == 2 || !args[2]->IsFunction()) {
100-
// return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
101-
// }
102-
//
103-
// callback = Local<Function>::Cast(args[2]);
104-
//
105-
// lookup_request *lr = new lookup_request();
106-
// lr->tree = tree;
107-
// lr->repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject());
108-
// lr->oid = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject());
109-
// lr->callback = Persistent<Function>::New(callback);
110-
//
111-
// tree->Ref();
112-
//
113-
// eio_custom(EIO_Lookup, EIO_PRI_DEFAULT, EIO_AfterLookup, lr);
114-
// ev_ref(EV_DEFAULT_UC);
115-
//
116-
// return scope.Close( Undefined() );
117-
}
118-
119-
//void GitTree::EIO_Lookup(uv_work_t *req) {
120-
// lookup_request *lr = static_cast<lookup_request *>(req->data);
121-
//
122-
// git_oid oid = lr->oid->GetValue();
123-
// lr->err = lr->tree->Lookup(lr->repo->GetValue(), &oid);
124-
//
125-
// return 0;
126-
//}
127-
128-
//void GitTree::EIO_AfterLookup(uv_work_t *req) {
129-
// lookup_request *lr = static_cast<lookup_request *>(req->data);
130-
//
131-
// ev_unref(EV_DEFAULT_UC);
132-
// lr->tree->Unref();
133-
//
134-
// Handle<Value> argv[1];
135-
// argv[0] = Integer::New(lr->err);
136-
//
137-
// TryCatch try_catch;
138-
//
139-
// lr->callback->Call(Context::GetCurrent()->Global(), 1, argv);
140-
//
141-
// if(try_catch.HasCaught())
142-
// FatalException(try_catch);
143-
//
144-
// lr->callback.Dispose();
145-
//
146-
// delete lr;
147-
//
148-
// return 0;
149-
//}
150-
151-
Handle<Value> GitTree::EntryCount(const Arguments& args) {
152-
HandleScope scope;
153-
154-
GitTree *tree = ObjectWrap::Unwrap<GitTree>(args.This());
155-
156-
int count = tree->EntryCount();
157-
158-
return scope.Close( Integer::New(count) );
159-
}
160-
161-
Handle<Value> GitTree::EntryByIndex(const Arguments& args) {
162-
HandleScope scope;
163-
164-
GitTree *tree = ObjectWrap::Unwrap<GitTree>(args.This());
165-
Local<Function> callback;
166-
167-
if(args.Length() == 0 || !args[0]->IsObject()) {
168-
return ThrowException(Exception::Error(String::New("TreeEntry is required and must be a Object.")));
169-
}
170-
171-
if(args.Length() == 1 || !args[1]->IsNumber()) {
172-
return ThrowException(Exception::Error(String::New("Index is required and must be a Number.")));
173-
}
174-
175-
if(args.Length() == 2 || !args[2]->IsFunction()) {
176-
return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
177-
}
178-
179-
callback = Local<Function>::Cast(args[2]);
180-
181-
entryindex_request *er = new entryindex_request();
182-
er->tree = tree;
183-
er->entry = ObjectWrap::Unwrap<GitTreeEntry>(args[0]->ToObject());
184-
er->idx = args[1]->ToInteger()->Value();
185-
er->callback = Persistent<Function>::New(callback);
186-
187-
tree->Ref();
188-
189-
uv_work_t *req = new uv_work_t;
190-
req->data = er;
191-
uv_queue_work(uv_default_loop(), req, EIO_EntryByIndex, (uv_after_work_cb)EIO_AfterEntryByIndex);
192-
193-
return scope.Close( Undefined() );
194-
}
195-
196-
void GitTree::EIO_EntryByIndex(uv_work_t *req) {
197-
entryindex_request *er = static_cast<entryindex_request *>(req->data);
198-
199-
er->entry->SetValue(er->tree->EntryByIndex(er->idx));
200-
}
201-
202-
void GitTree::EIO_AfterEntryByIndex(uv_work_t *req) {
203-
entryindex_request *er = static_cast<entryindex_request *>(req->data);
204-
205-
Handle<Value> argv[0];
206-
207-
TryCatch try_catch;
208-
209-
er->callback->Call(Context::GetCurrent()->Global(), 0, argv);
210-
211-
if(try_catch.HasCaught())
212-
FatalException(try_catch);
213-
214-
er->callback.Dispose();
215-
216-
delete req;
217-
er->tree->Unref();
218-
delete er;
219-
}
220-
22156
Handle<Value> GitTree::EntryByPath(const Arguments& args) {
22257
HandleScope scope;
22358

@@ -276,23 +111,4 @@ void GitTree::EntryByPathAfterWork(uv_work_t *req) {
276111
delete req;
277112
}
278113

279-
Handle<Value> GitTree::SortEntries(const Arguments& args) {
280-
HandleScope scope;
281-
282-
GitTree *tree = ObjectWrap::Unwrap<GitTree>(args.This());
283-
284-
int err = tree->SortEntries();
285-
286-
return scope.Close( Integer::New(err) );
287-
}
288-
289-
Handle<Value> GitTree::ClearEntries(const Arguments& args) {
290-
HandleScope scope;
291-
292-
//GitTree *tree = ObjectWrap::Unwrap<GitTree>(args.This());
293-
294-
//tree->ClearEntries();
295-
296-
return scope.Close( Undefined() );
297-
}
298114
Persistent<Function> GitTree::constructor_template;

0 commit comments

Comments
 (0)