Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 216 lines (147 sloc) 5.571 kb
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
1 /*
2 Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
3 */
4
5 #include <v8.h>
6 #include <node.h>
7
7ddcc75 @tbranyen Updated libgit2 to version 0.8.0, head is currently not stable
tbranyen authored
8 #include "../vendor/libgit2/include/git2.h"
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
9
9e60c82 @tbranyen Updated all header files to include folder
tbranyen authored
10 #include "../include/revwalk.h"
11 #include "../include/repo.h"
12 #include "../include/commit.h"
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
13
14 using namespace v8;
15 using namespace node;
16
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
17 void GitRevWalk::Initialize(Handle<Object> target) {
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
18 HandleScope scope;
19
20 Local<FunctionTemplate> t = FunctionTemplate::New(New);
21
22 constructor_template = Persistent<FunctionTemplate>::New(t);
23 constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
91c2282 @tbranyen Updated src to not send prefix to node
tbranyen authored
24 constructor_template->SetClassName(String::NewSymbol("RevWalk"));
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
25
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
26 NODE_SET_PROTOTYPE_METHOD(constructor_template, "reset", Reset);
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
27 NODE_SET_PROTOTYPE_METHOD(constructor_template, "push", Push);
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
28 NODE_SET_PROTOTYPE_METHOD(constructor_template, "next", Next);
be4af81 @tbranyen Added in revwalk free
tbranyen authored
29 NODE_SET_PROTOTYPE_METHOD(constructor_template, "free", Free);
c0bd6cd Potential build fix
U-tim-thinkpad\Tim Branyen authored
30 NODE_SET_PROTOTYPE_METHOD(constructor_template, "repository", Repository);
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
31
c063ef4 @tbranyen updated npmignore and package.json to ready for npm deployment - upda…
tbranyen authored
32 Local<Object> sort = Object::New();
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
33
c063ef4 @tbranyen updated npmignore and package.json to ready for npm deployment - upda…
tbranyen authored
34 sort->Set(String::New("NONE"), Integer::New(0));
35 sort->Set(String::New("TOPOLOGICAL"), Integer::New(1));
36 sort->Set(String::New("TIME"), Integer::New(2));
37 sort->Set(String::New("REVERSE"), Integer::New(4));
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
38
c063ef4 @tbranyen updated npmignore and package.json to ready for npm deployment - upda…
tbranyen authored
39 constructor_template->Set(String::New("sort"), sort);
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
40
91c2282 @tbranyen Updated src to not send prefix to node
tbranyen authored
41 target->Set(String::NewSymbol("RevWalk"), constructor_template->GetFunction());
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
42 }
43
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
44 git_revwalk* GitRevWalk::GetValue() {
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
45 return this->revwalk;
46 }
47
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
48 void GitRevWalk::SetValue(git_revwalk* revwalk) {
5a764b6 @tbranyen Updated getters and setters Closes #8
tbranyen authored
49 this->revwalk = revwalk;
50 }
51
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
52 int GitRevWalk::New(git_repository* repo) {
85d6575 Updates to stress test revwalk and commit fixed unit tests
Tim Branyen authored
53 this->repo = repo;
54
55 return git_revwalk_new(&this->revwalk, this->repo);
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
56 }
57
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
58 void GitRevWalk::Reset() {
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
59 git_revwalk_reset(this->revwalk);
60 }
61
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
62 int GitRevWalk::Push(git_oid* oid) {
23015f4 @tbranyen updates
tbranyen authored
63 // Test
64 git_revwalk_sorting(this->revwalk, GIT_SORT_TIME | GIT_SORT_REVERSE);
65
d149947 @tbranyen Updated to work with libgit2 0.10.0
tbranyen authored
66 return git_revwalk_push(this->revwalk, oid);
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
67 }
68
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
69 // Not for 0.0.1
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
70 //int GitRevWalk::Hide() {
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
71 // git_revwalk_hide(this->revwalk);
72 //}
73
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
74 int GitRevWalk::Next(git_oid *oid) {
d149947 @tbranyen Updated to work with libgit2 0.10.0
tbranyen authored
75 return git_revwalk_next(oid, this->revwalk);
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
76 }
77
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
78 void GitRevWalk::Free() {
be4af81 @tbranyen Added in revwalk free
tbranyen authored
79 git_revwalk_free(this->revwalk);
80 }
81
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
82 git_repository* GitRevWalk::Repository() {
c0bd6cd Potential build fix
U-tim-thinkpad\Tim Branyen authored
83 return git_revwalk_repository(this->revwalk);
84 }
85
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
86 Handle<Value> GitRevWalk::New(const Arguments& args) {
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
87 HandleScope scope;
88
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
89 GitRevWalk *revwalk = new GitRevWalk();
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
90
91 if(args.Length() == 0 || !args[0]->IsObject()) {
92 return ThrowException(Exception::Error(String::New("Repo is required and must be an Object.")));
93 }
94
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
95 GitRepo *repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject());
85d6575 Updates to stress test revwalk and commit fixed unit tests
Tim Branyen authored
96 revwalk->New(repo->GetValue());
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
97
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
98 revwalk->Wrap(args.This());
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
99
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
100 return scope.Close( args.This() );
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
101 }
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
102
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
103 Handle<Value> GitRevWalk::Reset(const Arguments& args) {
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
104 HandleScope scope;
105
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
106 GitRevWalk *revwalk = ObjectWrap::Unwrap<GitRevWalk>(args.This());
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
107
108 revwalk->Reset();
109
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
110 return scope.Close( Undefined() );
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
111 }
112
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
113 Handle<Value> GitRevWalk::Push(const Arguments& args) {
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
114 HandleScope scope;
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
115
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
116 GitRevWalk *revwalk = ObjectWrap::Unwrap<GitRevWalk>(args.This());
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
117 if(args.Length() == 0 || !args[0]->IsObject()) {
d149947 @tbranyen Updated to work with libgit2 0.10.0
tbranyen authored
118 return ThrowException(Exception::Error(String::New("Oid is required and must be an Object.")));
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
119 }
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
120
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
121 GitOid *oid = ObjectWrap::Unwrap<GitOid>(args[0]->ToObject());
3eac224 @tbranyen using valgrind to test existing code for memory leaks, updating sourc…
tbranyen authored
122
123 git_oid tmp = oid->GetValue();
124 int err = revwalk->Push(&tmp);
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
125
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
126 return scope.Close( Integer::New(err) );
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
127 }
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
128
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
129 Handle<Value> GitRevWalk::Next(const Arguments& args) {
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
130 HandleScope scope;
131
3736ee1 @tbranyen fixes for 0.0.3
tbranyen authored
132 GitRevWalk* revwalk = ObjectWrap::Unwrap<GitRevWalk>(args.This());
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
133 Local<Function> callback;
134
135 if(args.Length() == 0 || !args[0]->IsObject()) {
d149947 @tbranyen Updated to work with libgit2 0.10.0
tbranyen authored
136 return ThrowException(Exception::Error(String::New("Oid is required and must be an Object.")));
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
137 }
138
139 if(args.Length() == 1 || !args[1]->IsFunction()) {
140 return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
141 }
142
143 callback = Local<Function>::Cast(args[1]);
144
3736ee1 @tbranyen fixes for 0.0.3
tbranyen authored
145 next_request* ar = new next_request();
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
146 ar->revwalk = revwalk;
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
147 ar->oid = ObjectWrap::Unwrap<GitOid>(args[0]->ToObject());
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
148 ar->callback = Persistent<Function>::New(callback);
149
150 revwalk->Ref();
151
152 eio_custom(EIO_Next, EIO_PRI_DEFAULT, EIO_AfterNext, ar);
153 ev_ref(EV_DEFAULT_UC);
154
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
155 return scope.Close( Undefined() );
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
156 }
157
a93d5f1 @moneal Updates for node 0.0.6x
moneal authored
158 void GitRevWalk::EIO_Next(eio_req *req) {
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
159 next_request *ar = static_cast<next_request *>(req->data);
3eac224 @tbranyen using valgrind to test existing code for memory leaks, updating sourc…
tbranyen authored
160 git_oid oid = ar->oid->GetValue();
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
161
3eac224 @tbranyen using valgrind to test existing code for memory leaks, updating sourc…
tbranyen authored
162 ar->err = ar->revwalk->Next(&oid);
d149947 @tbranyen Updated to work with libgit2 0.10.0
tbranyen authored
163 ar->oid->SetValue(oid);
0e7aadf @tbranyen Updated logic to have commits referenced properly and display their m…
tbranyen authored
164
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
165 }
166
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
167 int GitRevWalk::EIO_AfterNext(eio_req *req) {
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
168 HandleScope scope;
169
170 next_request *ar = static_cast<next_request *>(req->data);
171 ev_unref(EV_DEFAULT_UC);
172 ar->revwalk->Unref();
173
174 Local<Value> argv[1];
ceeae12 @tbranyen several updates to add sigificant stablility and performance; removed…
tbranyen authored
175 argv[0] = Integer::New(ar->err);
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
176
177 TryCatch try_catch;
178
179 ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);
180
181 if(try_catch.HasCaught())
182 FatalException(try_catch);
183
184 ar->callback.Dispose();
185
186 delete ar;
187
188 return 0;
189 }
be4af81 @tbranyen Added in revwalk free
tbranyen authored
190
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
191 Handle<Value> GitRevWalk::Free(const Arguments& args) {
be4af81 @tbranyen Added in revwalk free
tbranyen authored
192 HandleScope scope;
193
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
194 GitRevWalk *revwalk = ObjectWrap::Unwrap<GitRevWalk>(args.This());
195
be4af81 @tbranyen Added in revwalk free
tbranyen authored
196 revwalk->Free();
197
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
198 return scope.Close( Undefined() );
be4af81 @tbranyen Added in revwalk free
tbranyen authored
199 }
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
200
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
201 Handle<Value> GitRevWalk::Repository(const Arguments& args) {
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
202 HandleScope scope;
203
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
204 GitRevWalk *revwalk = new GitRevWalk();
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
205
206 if(args.Length() == 0 || !args[0]->IsObject()) {
207 return ThrowException(Exception::Error(String::New("Repo is required and must be an Object.")));
208 }
209
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
210 GitRepo *repo = ObjectWrap::Unwrap<GitRepo>(args[0]->ToObject());
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
211 repo->SetValue(revwalk->Repository());
212
9cd642e @tbranyen updated to use scope.Close everywhere fixes #19
tbranyen authored
213 return scope.Close( Undefined() );
dd4181b @tbranyen Updated revwalker started on sorting, started on trees
tbranyen authored
214 }
7a481bf @tbranyen Updated all classes to have git prefix. Closes #13
tbranyen authored
215 Persistent<FunctionTemplate> GitRevWalk::constructor_template;
Something went wrong with that request. Please try again.