Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Basic git_remote ObjectWrap, fn/async stuff in Repository, and a basi…

…c example to open a remote.
  • Loading branch information...
commit 1ebab5ddf963d79abd041a8c3bf3f3efe0ba030b 1 parent 32ed3f4
@samcday samcday authored
View
2  TODO.md
@@ -1,7 +1,7 @@
TODO:
* Lookup lightweight/annotated tag by name.
-
+* V8 AdjustForMemoryByCompensatingWithAReallyLongMethodName when we allocate libgit2 stuff
# (Old) TODO - probably still relevant
View
1  binding.gyp
@@ -11,6 +11,7 @@
'src/tree.cc',
'src/blob.cc',
'src/tag.cc',
+ 'src/remote.cc',
],
'todosources': [
'src/index.cc',
View
8 examples/show_remote.js
@@ -0,0 +1,8 @@
+var gitteh = require("../lib/gitteh");
+var path = require("path");
+
+gitteh.openRepository(path.join(__dirname, ".."), function(err, repo) {
+ repo.remote("origin", function(err, remote) {
+ console.log(remote);
+ });
+});
View
2  src/gitteh.cc
@@ -29,6 +29,7 @@
#include "tree.h"
#include "blob.h"
#include "tag.h"
+#include "remote.h"
namespace gitteh {
@@ -58,6 +59,7 @@ init(Handle<Object> target) {
Tree::Init(target);
Blob::Init(target);
Tag::Init(target);
+ Remote::Init(target);
ImmutableSet(target, String::NewSymbol("minOidLength"), Integer::New(GIT_OID_MINPREFIXLEN));
ImmutableSet(target, String::NewSymbol("types"), CreateTypeObject());
View
55 src/remote.cc
@@ -0,0 +1,55 @@
+#include "remote.h"
+
+static Persistent<String> class_symbol;
+static Persistent<String> name_symbol;
+static Persistent<String> url_symbol;
+static Persistent<String> fetchspec_symbol;
+static Persistent<String> pushspec_symbol;
+
+namespace gitteh {
+ Persistent<FunctionTemplate> Remote::constructor_template;
+ void Remote::Init(Handle<Object> target) {
+ HandleScope scope;
+
+ class_symbol = NODE_PSYMBOL("Remote");
+ name_symbol = NODE_PSYMBOL("name");
+ url_symbol = NODE_PSYMBOL("url");
+ fetchspec_symbol = NODE_PSYMBOL("fetchSpec");
+ pushspec_symbol = NODE_PSYMBOL("pushSpec");
+
+ Local<FunctionTemplate> t = FunctionTemplate::New(New);
+ constructor_template = Persistent<FunctionTemplate>::New(t);
+ constructor_template->SetClassName(class_symbol);
+ t->InstanceTemplate()->SetInternalFieldCount(1);
+
+ target->Set(class_symbol, constructor_template->GetFunction());
+ }
+
+ Handle<Value> Remote::New(const Arguments& args) {
+ HandleScope scope;
+ REQ_EXT_ARG(0, remoteArg);
+ Handle<Object> me = args.This();
+
+ git_remote *remote = static_cast<git_remote*>(remoteArg->Value());
+ Remote *remoteObj = new Remote(remote);
+ remoteObj->Wrap(me);
+
+ me->Set(name_symbol, CastToJS(git_remote_name(remote)));
+ me->Set(url_symbol, CastToJS(git_remote_url(remote)));
+ /*me->Set(fetchspec_symbol, CastToJS(git_remote_fetchspec(remote)));
+ me->Set(pushspec_symbol, CastToJS(git_remote_pushspec(remote)));*/
+
+ return scope.Close(me);
+ }
+
+ Remote::Remote(git_remote *remote) : ObjectWrap() {
+ remote_ = remote;
+ }
+
+ Remote::~Remote() {
+ if(remote_ != NULL) {
+ git_remote_free(remote_);
+ remote_ = NULL;
+ }
+ }
+}; // namespace gitteh
View
22 src/remote.h
@@ -0,0 +1,22 @@
+#ifndef GITTEH_REMOTE_H
+#define GITTEH_REMOTE_H
+
+#include "gitteh.h"
+
+namespace gitteh {
+ class Remote : public ObjectWrap {
+ public:
+ static Persistent<FunctionTemplate> constructor_template;
+ static void Init(Handle<Object>);
+ Remote(git_remote*);
+ ~Remote();
+
+ protected:
+ static Handle<Value> New(const Arguments&);
+
+ private:
+ git_remote *remote_;
+ };
+};
+
+#endif
View
50 src/repository.cc
@@ -27,6 +27,7 @@
#include "tree.h"
#include "blob.h"
#include "tag.h"
+#include "remote.h"
using std::vector;
@@ -103,6 +104,14 @@ class GetReferenceBaton : public RepositoryBaton {
GetReferenceBaton(Repository *r, string _name) : RepositoryBaton(r), name(_name) {}
};
+class GetRemoteBaton : public RepositoryBaton {
+public:
+ string name;
+ git_remote *remote;
+
+ GetRemoteBaton(Repository *r, string _name) : RepositoryBaton(r), name(_name) {}
+};
+
Persistent<FunctionTemplate> Repository::constructor_template;
Repository::Repository() {
@@ -164,6 +173,7 @@ void Repository::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(t, "object", GetObject);
NODE_SET_PROTOTYPE_METHOD(t, "exists", Exists);
NODE_SET_PROTOTYPE_METHOD(t, "reference", GetReference);
+ NODE_SET_PROTOTYPE_METHOD(t, "remote", GetRemote);
NODE_SET_METHOD(target, "openRepository", OpenRepository);
NODE_SET_METHOD(target, "initRepository", InitRepository);
@@ -437,6 +447,46 @@ Handle<Object> Repository::CreateReferenceObject(git_reference *ref) {
return scope.Close(obj);
}
+Handle<Value> Repository::GetRemote(const Arguments& args) {
+ HandleScope scope;
+ Repository *repo = ObjectWrap::Unwrap<Repository>(args.This());
+
+ GetRemoteBaton *baton = new GetRemoteBaton(repo,
+ CastFromJS<string>(args[0]));
+ baton->setCallback(args[1]);
+
+ uv_queue_work(uv_default_loop(), &baton->req, AsyncGetRemote,
+ AsyncAfterGetRemote);
+ return Undefined();
+}
+
+void Repository::AsyncGetRemote(uv_work_t *req) {
+ GetRemoteBaton *baton = GetBaton<GetRemoteBaton>(req);
+
+ AsyncLibCall(git_remote_load(&baton->remote, baton->repo->repo_,
+ baton->name.c_str()), baton);
+}
+
+void Repository::AsyncAfterGetRemote(uv_work_t *req) {
+ HandleScope scope;
+ GetRemoteBaton *baton = GetBaton<GetRemoteBaton>(req);
+
+ if(baton->isErrored()) {
+ Handle<Value> argv[] = { baton->createV8Error() };
+ FireCallback(baton->callback, 1, argv);
+ }
+ else {
+ Handle<Value> constructorArgs[] = { External::New(baton->remote) };
+ Local<Object> obj = Remote::constructor_template->GetFunction()
+ ->NewInstance(1, constructorArgs);
+
+ Handle<Value> argv[] = { Null(), obj };
+ FireCallback(baton->callback, 2, argv);
+ }
+
+ delete baton;
+}
+
Handle<Value> Repository::Exists(const Arguments& args) {
HandleScope scope;
Repository *repo = ObjectWrap::Unwrap<Repository>(args.This());
View
4 src/repository.h
@@ -34,6 +34,7 @@ class Repository : public ObjectWrap {
static Handle<Value> New(const Arguments&);
static Handle<Value> GetObject(const Arguments&);
static Handle<Value> GetReference(const Arguments&);
+ static Handle<Value> GetRemote(const Arguments&);
static Handle<Value> Exists(const Arguments&);
void close();
@@ -56,6 +57,9 @@ class Repository : public ObjectWrap {
static void AsyncGetReference(uv_work_t*);
static void AsyncAfterGetReference(uv_work_t*);
+ static void AsyncGetRemote(uv_work_t*);
+ static void AsyncAfterGetRemote(uv_work_t*);
+
static Handle<Object> CreateReferenceObject(git_reference*);
// For now, I'm using one lock for anything that calls a git_* api function.
Please sign in to comment.
Something went wrong with that request. Please try again.