Skip to content

Commit 53bfaab

Browse files
committed
Changed LookupBaton->sha to std::string, use string functions to convert
1 parent a4fe999 commit 53bfaab

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

include/commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class GitCommit : public ObjectWrap {
7878

7979
git_repository* repo;
8080
git_oid oid;
81-
const char* sha;
81+
std::string sha;
8282
git_commit* rawCommit;
8383

8484
Persistent<Function> callback;

src/commit.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "../include/commit.h"
2121
#include "../include/error.h"
2222

23+
#include "../include/functions/string.h"
24+
2325
using namespace v8;
2426
using namespace cvv8;
2527
using namespace node;
@@ -273,14 +275,10 @@ Handle<Value> GitCommit::Lookup(const Arguments& args) {
273275

274276
if (args[1]->IsObject()) {
275277
baton->oid = ObjectWrap::Unwrap<GitOid>(args[1]->ToObject())->GetValue();
276-
baton->sha = NULL;
277278
} else {
278-
// Make this less ugly
279-
String::AsciiValue shaValue(args[1]->ToString());
280-
char *sha = (char *) malloc(shaValue.length() + 1);
281-
strcpy(sha, *shaValue);
282-
baton->sha = sha;
279+
baton->sha = stringArgToString(args[1]->ToString());
283280
}
281+
284282
baton->callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
285283

286284
uv_queue_work(uv_default_loop(), &baton->request, LookupWork, LookupAfterWork);
@@ -292,8 +290,8 @@ void GitCommit::LookupWork(uv_work_t *req) {
292290
LookupBaton *baton = static_cast<LookupBaton *>(req->data);
293291

294292
git_oid oid = baton->oid;
295-
if (baton->sha != NULL) {
296-
int returnCode = git_oid_fromstr(&oid, baton->sha);
293+
if (!baton->sha.empty()) {
294+
int returnCode = git_oid_fromstr(&oid, baton->sha.c_str());
297295
if (returnCode != GIT_OK) {
298296
baton->error = giterr_last();
299297
return;
@@ -353,6 +351,9 @@ Handle<Value> GitCommit::Close(const Arguments& args) {
353351
return scope.Close(Undefined());
354352
}
355353

354+
/**
355+
* @todo asynchronize
356+
*/
356357
Handle<Value> GitCommit::Tree(const Arguments& args) {
357358
HandleScope scope;
358359

0 commit comments

Comments
 (0)