Skip to content

Commit 3467803

Browse files
committed
Removed sha method from C++ commit, commit js uses commit's Oid sha method
1 parent b815a06 commit 3467803

File tree

3 files changed

+11
-59
lines changed

3 files changed

+11
-59
lines changed

include/commit.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "oid.h"
1717
#include "tree.h"
1818

19-
#include "../include/functions/string.h"
20-
2119
using namespace node;
2220
using namespace v8;
2321

@@ -55,10 +53,6 @@ class GitCommit : public ObjectWrap {
5553

5654
static Handle<Value> Oid(const Arguments& args);
5755

58-
static Handle<Value> Sha(const Arguments& args);
59-
static void ShaWork(uv_work_t* req);
60-
static void ShaAfterWork(uv_work_t* req);
61-
6256
static Handle<Value> Message(const Arguments& args);
6357
static void MessageWork(uv_work_t* req);
6458
static void MessageAfterWork(uv_work_t* req);
@@ -103,15 +97,6 @@ class GitCommit : public ObjectWrap {
10397
Persistent<Function> callback;
10498
};
10599

106-
struct ShaBaton {
107-
uv_work_t request;
108-
109-
git_oid* rawOid;
110-
char sha[GIT_OID_HEXSZ + 1];
111-
112-
Persistent<Function> callback;
113-
};
114-
115100
struct MessageBaton {
116101
uv_work_t request;
117102

lib/commit.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ Commit.prototype.sha = function(callback) {
7474
* @param {GitError|null} error An Error or null if successful.
7575
* @param {String|null} sha Retrieved SHA.
7676
*/
77-
this.rawCommit.sha(function(error, sha) {
78-
if (success(error, callback)) {
79-
callback(null, sha);
77+
this.oid(function(error, oid) {
78+
if (!success(error, callback)) {
79+
return;
8080
}
81+
oid.sha(function(error, sha) {
82+
if (!success(error, callback)) {
83+
return;
84+
}
85+
callback(null, sha);
86+
});
8187
});
8288
};
8389

src/commit.cc

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Dual licensed under the MIT and GPL licenses.
66
*/
77

8-
#include <string.h>
98
#include <v8.h>
109
#include <node.h>
10+
#include <string.h>
1111

1212
#include "git2.h"
1313
#include "cvv8/v8-convert.hpp"
@@ -21,6 +21,7 @@
2121
#include "../include/error.h"
2222

2323
#include "../include/functions/utilities.h"
24+
#include "../include/functions/string.h"
2425

2526
using namespace v8;
2627
using namespace cvv8;
@@ -36,7 +37,6 @@ void GitCommit::Initialize(Handle<Object> target) {
3637

3738
NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup);
3839
NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid);
39-
NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha);
4040
NODE_SET_PROTOTYPE_METHOD(tpl, "message", Message);
4141
NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time);
4242
NODE_SET_PROTOTYPE_METHOD(tpl, "offset", Offset);
@@ -162,45 +162,6 @@ Handle<Value> GitCommit::Oid(const Arguments& args) {
162162
return scope.Close(oid);
163163
}
164164

165-
Handle<Value> GitCommit::Sha(const Arguments& args) {
166-
HandleScope scope;
167-
168-
if(args.Length() == 0 || !args[0]->IsFunction()) {
169-
return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
170-
}
171-
172-
ShaBaton* baton = new ShaBaton;
173-
baton->request.data = baton;
174-
baton->rawOid = ObjectWrap::Unwrap<GitCommit>(args.This())->oid;
175-
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[0]));
176-
177-
uv_queue_work(uv_default_loop(), &baton->request, ShaWork, (uv_after_work_cb)ShaAfterWork);
178-
179-
return Undefined();
180-
}
181-
void GitCommit::ShaWork(uv_work_t* req) {
182-
ShaBaton *baton = static_cast<ShaBaton *>(req->data);
183-
184-
baton->sha[GIT_OID_HEXSZ] = '\0';
185-
git_oid_fmt(baton->sha, baton->rawOid);
186-
}
187-
void GitCommit::ShaAfterWork(uv_work_t* req) {
188-
HandleScope scope;
189-
ShaBaton *baton = static_cast<ShaBaton *>(req->data);
190-
191-
Handle<Value> argv[2] = {
192-
Local<Value>::New(Null()),
193-
String::New(baton->sha)
194-
};
195-
196-
TryCatch try_catch;
197-
baton->callback->Call(Context::GetCurrent()->Global(), 2, argv);
198-
if (try_catch.HasCaught()) {
199-
node::FatalException(try_catch);
200-
}
201-
delete req;
202-
}
203-
204165
Handle<Value> GitCommit::Message(const Arguments& args) {
205166
HandleScope scope;
206167

0 commit comments

Comments
 (0)