Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 147 lines (100 sloc) 3.66 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 #include <node_events.h>
8
9 #include <git2.h>
10
11 #include "revwalk.h"
12 #include "repo.h"
13 #include "commit.h"
14
15 using namespace v8;
16 using namespace node;
17
18 void RevWalk::Initialize(Handle<Object> target) {
19 HandleScope scope;
20
21 Local<FunctionTemplate> t = FunctionTemplate::New(New);
22
23 constructor_template = Persistent<FunctionTemplate>::New(t);
24 constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
25 constructor_template->SetClassName(String::NewSymbol("RevWalk"));
26
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);
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
29
30 target->Set(String::NewSymbol("RevWalk"), constructor_template->GetFunction());
31 }
32
33 git_revwalk* RevWalk::GetValue() {
34 return this->revwalk;
35 }
36
5a764b6 @tbranyen Updated getters and setters Closes #8
tbranyen authored
37 void RevWalk::SetValue(git_revwalk* revwalk) {
38 this->revwalk = revwalk;
39 }
40
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
41 int RevWalk::New(Repo *repo) {
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
42 return git_revwalk_new(&this->revwalk, repo->GetValue());
43 }
44
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
45 int RevWalk::Push(Commit *commit) {
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
46 return git_revwalk_push(this->revwalk, commit->GetValue());
47 }
48
49 int RevWalk::Next(Commit *commit) {
50 return git_revwalk_next((git_commit **)commit->GetValue(), this->revwalk);
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
51 }
52
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
53 Handle<Value> RevWalk::New(const Arguments& args) {
54 HandleScope scope;
55
56 RevWalk *revwalk = new RevWalk();
57
58 if(args.Length() == 0 || !args[0]->IsObject()) {
59 return ThrowException(Exception::Error(String::New("Repo is required and must be an Object.")));
60 }
61
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
62 Repo *repo = ObjectWrap::Unwrap<Repo>(args[0]->ToObject());
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
63 int err = revwalk->New(repo);
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
64
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
65 revwalk->Wrap(args.This());
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
66
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
67 return args.This();
68 }
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
69
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
70 Handle<Value> RevWalk::Push(const Arguments& args) {
71 HandleScope scope;
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
72
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
73 RevWalk *revwalk = new RevWalk();
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
74
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
75 if(args.Length() == 0 || !args[0]->IsObject()) {
76 return ThrowException(Exception::Error(String::New("Commit is required and must be an Object.")));
77 }
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
78
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
79 Commit *commit = ObjectWrap::Unwrap<Commit>(args[0]->ToObject());
80 int err = revwalk->Push(commit);
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
81
3138b0d @tbranyen Large updates to examples, source, and tests. Added in more revwalk …
tbranyen authored
82 return Local<Value>::New(Integer::New(err));
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
83 }
2aef79b @tbranyen Updated references and revwalker to have next method
tbranyen authored
84
85 Handle<Value> RevWalk::Next(const Arguments& args) {
86 RevWalk *revwalk = ObjectWrap::Unwrap<RevWalk>(args.This());
87 Local<Function> callback;
88
89 HandleScope scope;
90
91 if(args.Length() == 0 || !args[0]->IsObject()) {
92 return ThrowException(Exception::Error(String::New("Commit is required and must be an Object.")));
93 }
94
95 if(args.Length() == 1 || !args[1]->IsFunction()) {
96 return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
97 }
98
99 callback = Local<Function>::Cast(args[1]);
100
101 next_request *ar = new next_request();
102 ar->revwalk = revwalk;
103 ar->commit = ObjectWrap::Unwrap<Commit>(args[0]->ToObject());
104 ar->callback = Persistent<Function>::New(callback);
105
106 revwalk->Ref();
107
108 eio_custom(EIO_Next, EIO_PRI_DEFAULT, EIO_AfterNext, ar);
109 ev_ref(EV_DEFAULT_UC);
110
111 return Undefined();
112 }
113
114 int RevWalk::EIO_Next(eio_req *req) {
115 next_request *ar = static_cast<next_request *>(req->data);
116
117 ar->err = Persistent<Value>::New(Integer::New(ar->revwalk->Next(ar->commit)));
118
119 return 0;
120 }
121
122 int RevWalk::EIO_AfterNext(eio_req *req) {
123 HandleScope scope;
124
125 next_request *ar = static_cast<next_request *>(req->data);
126 ev_unref(EV_DEFAULT_UC);
127 ar->revwalk->Unref();
128
129 Local<Value> argv[1];
130 argv[0] = *ar->err;
131
132 TryCatch try_catch;
133
134 ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);
135
136 if(try_catch.HasCaught())
137 FatalException(try_catch);
138
139 ar->err.Dispose();
140 ar->callback.Dispose();
141
142 delete ar;
143
144 return 0;
145 }
ef0dcae @tbranyen Added in revwalker code, code *is* broken atm Ref issues must be figu…
tbranyen authored
146 Persistent<FunctionTemplate> RevWalk::constructor_template;
Something went wrong with that request. Please try again.