Skip to content

Commit

Permalink
Async reading repo complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Branyen committed Feb 16, 2011
1 parent baddc4f commit 4b54717
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Empty file modified build/.conf_check_0/testbuild/default/testprog
100755 → 100644
Empty file.
Binary file modified build/default/git2.node
100755 → 100644
Binary file not shown.
Binary file modified build/default/src/git2_1.o
Binary file not shown.
4 changes: 2 additions & 2 deletions example/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ var git2 = require('../build/default/git2');
var g = new git2.Git2();

// This is invalid
g.repo('/etc/hosts', function(err, path) {
g.git_repository_open('/etc/hosts', function(err, path) {
console.log(err, path);
});

// This is valid
g.repo('/home/tim/Dropbox/Projects/TabDeveloper/V4/.git', function(err, path) {
g.git_repository_open('/home/tim/Dropbox/Projects/TabDeveloper/V4/.git', function(err, path) {
console.log(err, path);
});
23 changes: 21 additions & 2 deletions src/git2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class Git2 : public ObjectWrap {
s_ct->InstanceTemplate()->SetInternalFieldCount(1);
s_ct->SetClassName(String::NewSymbol("Git2"));

NODE_SET_PROTOTYPE_METHOD(s_ct, "repo", Repo);
NODE_SET_PROTOTYPE_METHOD(s_ct, "git_repository_open", Repo);
NODE_SET_PROTOTYPE_METHOD(s_ct, "git_strerror", Repo);

target->Set(String::NewSymbol("Git2"), s_ct->GetFunction());
}
Expand Down Expand Up @@ -94,7 +95,6 @@ class Git2 : public ObjectWrap {

Local<Value> argv[2];
argv[0] = Number::Cast(*ar->err);
//argv[0] = Number::New(0);
argv[1] = String::Cast(*ar->path);

TryCatch try_catch;
Expand All @@ -113,6 +113,25 @@ class Git2 : public ObjectWrap {
return 0;
}

static Handle<Value> strerror (const Arguments& args) {
Git2 *git2 = ObjectWrap::Unwrap<Git2>(args.This());

HandleScope scope;

if (args.Length() == 0 || !args[0]->IsString()) {
return ThrowException(
Exception::Error(String::New("Error code required.")));
}

if (args[0] != 0) {
return scope.Close(String::New(git_strerror(Number::New(args[0]))));
}
else {
return scope.Close(String::New("Successfully loaded repo."));
}
}


private:
git_repository *repo;
};
Expand Down

0 comments on commit 4b54717

Please sign in to comment.