| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,6 +120,7 @@ Release information | |||
| 120 | 120 | ### v0.0.1: ### | |
| 121 | 121 | * 1:1 mapping of libgit2 read methods | |
| 122 | 122 | * An API that can be easily extended with convenience methods in JS | |
| 123 | + * An API that offers a familiar clean syntax that will make adoption and use much more likely | ||
| 123 | 124 | ||
| 124 | 125 | ### v0.0.2: ### | |
| 125 | 126 | * Write capabilities | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,10 +2,15 @@ var git = require('nodegit2'); | |||
| 2 | 2 | ||
| 3 | 3 | // Read the current repository | |
| 4 | 4 | git.repo( '.git', function( err, path, repo ) { | |
| 5 | - // Read a commit | ||
| 6 | - this.commit( '5f2aa9407f7b3aeb531c621c3358953841ccfc98', function( err, details, commit ) { | ||
| 7 | - console.log( 'Message', details.message ); | ||
| 8 | - console.log( 'Author\'s name', details.author.name ); | ||
| 9 | - console.log( 'Author\'s email', details.author.email ); | ||
| 10 | - }); | ||
| 5 | + // | ||
| 6 | + this.find( 'HEAD', function( err, name, ref ) { | ||
| 7 | + // console.log( ref ); | ||
| 8 | + }); | ||
| 9 | + | ||
| 10 | + // Read a commit | ||
| 11 | + this.commit( '5f2aa9407f7b3aeb531c621c3358953841ccfc98', function( err, details, commit ) { | ||
| 12 | + console.log( 'Message', details.message.trim() ); | ||
| 13 | + console.log( 'Author\'s name', details.author.name ); | ||
| 14 | + console.log( 'Author\'s email', details.author.email ); | ||
| 15 | + }); | ||
| 11 | 16 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | - var repo = require( './repo.js' ); | ||
| 1 | + var repo = require( './repo.js' ).repo; | ||
| 2 | 2 | //commit = require( 'commit.js' ); | |
| 3 | 3 | ||
| 4 | 4 | exports.git2 = require( '../build/default/git2' ); | |
| 5 | - exports.repo = repo.repo; | ||
| 5 | + exports.repo = repo; | ||
| 6 | 6 | //exports.commit = commit.commit; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + var git2 = require('../build/default/git2'); | ||
| 2 | + | ||
| 3 | + var Ref = function( ref ) { | ||
| 4 | + var self = {}; | ||
| 5 | + | ||
| 6 | + // Internal reference to a Git reference | ||
| 7 | + self.ref = ref || new git2.Ref(); | ||
| 8 | + | ||
| 9 | + return self; | ||
| 10 | + }; | ||
| 11 | + | ||
| 12 | + exports.ref = Ref; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,14 @@ | |||
| 1 | - var git2 = require('../build/default/git2'); | ||
| 1 | + var git = require( 'nodegit2' ); | ||
| 2 | 2 | ||
| 3 | 3 | var Repo = function( path, callback ) { | |
| 4 | 4 | var self = {}; | |
| 5 | 5 | ||
| 6 | 6 | // Internal reference to a Git repository | |
| 7 | - self.repo = new git2.Repo(); | ||
| 7 | + self.repo = new git.git2.Repo(); | ||
| 8 | 8 | ||
| 9 | 9 | self.commit = function( sha, callback ) { | |
| 10 | - var oid = new git2.Oid(), | ||
| 11 | - commit = new git2.Commit(); | ||
| 10 | + var oid = new git.git2.Oid(), | ||
| 11 | + commit = new git.git2.Commit(); | ||
| 12 | 12 | ||
| 13 | 13 | oid.mkstr( sha ); | |
| 14 | 14 | ||
@@ -18,6 +18,14 @@ var Repo = function( path, callback ) { | |||
| 18 | 18 | }); | |
| 19 | 19 | }; | |
| 20 | 20 | ||
| 21 | + self.find = function( name ) { | ||
| 22 | + var ref = new git.git2.Ref(); | ||
| 23 | + self.repo.lookup_ref( ref, name, function( ref ) { | ||
| 24 | + var args = Array.prototype.slice.call( arguments ); | ||
| 25 | + callback && callback.apply( ref, (args.push( git.ref(ref) ), args) ); | ||
| 26 | + }); | ||
| 27 | + }; | ||
| 28 | + | ||
| 21 | 29 | self.init = function( path, is_bare, callback ) { | |
| 22 | 30 | self.repo.init( path, is_bare, function() { | |
| 23 | 31 | var args = Array.prototype.slice.call( arguments ); | |
@@ -27,7 +35,10 @@ var Repo = function( path, callback ) { | |||
| 27 | 35 | return self; | |
| 28 | 36 | }; | |
| 29 | 37 | ||
| 30 | - self.free = function() { }; | ||
| 38 | + self.free = function() { | ||
| 39 | + self.repo.free(); | ||
| 40 | + delete self.repo; | ||
| 41 | + }; | ||
| 31 | 42 | ||
| 32 | 43 | // Constructor use | |
| 33 | 44 | if( path && callback ) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,8 +64,9 @@ Handle<Value> Commit::Lookup(const Arguments& args) { | |||
| 64 | 64 | return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); | |
| 65 | 65 | } | |
| 66 | 66 | ||
| 67 | - lookup_request *ar = new lookup_request(); | ||
| 68 | 67 | callback = Local<Function>::Cast(args[2]); | |
| 68 | + | ||
| 69 | + lookup_request *ar = new lookup_request(); | ||
| 69 | 70 | ar->commit = commit; | |
| 70 | 71 | ar->repo = ObjectWrap::Unwrap<Repo>(args[0]->ToObject()); | |
| 71 | 72 | ar->oid = ObjectWrap::Unwrap<Oid>(args[1]->ToObject()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> | |||
| 8 | 8 | ||
| 9 | 9 | #include <git2.h> | |
| 10 | 10 | ||
| 11 | + #include "ref.h" | ||
| 11 | 12 | #include "repo.h" | |
| 12 | 13 | #include "oid.h" | |
| 13 | 14 | #include "commit.h" | |
@@ -18,7 +19,8 @@ using namespace v8; | |||
| 18 | 19 | extern "C" void init(Handle<Object> target) { | |
| 19 | 20 | HandleScope scope; | |
| 20 | 21 | ||
| 21 | - Repo::Initialize(target); | ||
| 22 | + Ref::Initialize(target); | ||
| 22 | 23 | Oid::Initialize(target); | |
| 24 | + Repo::Initialize(target); | ||
| 23 | 25 | Commit::Initialize(target); | |
| 24 | 26 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,45 @@ | |||
| 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 "ref.h" | ||
| 12 | + | ||
| 13 | + using namespace v8; | ||
| 14 | + using namespace node; | ||
| 15 | + | ||
| 16 | + void Ref::Initialize(Handle<Object> target) { | ||
| 17 | + HandleScope scope; | ||
| 18 | + | ||
| 19 | + Local<FunctionTemplate> t = FunctionTemplate::New(New); | ||
| 20 | + | ||
| 21 | + constructor_template = Persistent<FunctionTemplate>::New(t); | ||
| 22 | + constructor_template->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 23 | + constructor_template->SetClassName(String::NewSymbol("Ref")); | ||
| 24 | + | ||
| 25 | + target->Set(String::NewSymbol("Ref"), constructor_template->GetFunction()); | ||
| 26 | + } | ||
| 27 | + | ||
| 28 | + git_reference* Ref::GetValue() { | ||
| 29 | + return this->ref; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + void Ref::SetValue(git_reference *ref) { | ||
| 33 | + this->ref = ref; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + Handle<Value> Ref::New(const Arguments& args) { | ||
| 37 | + HandleScope scope; | ||
| 38 | + | ||
| 39 | + Ref *ref = new Ref(); | ||
| 40 | + ref->Wrap(args.This()); | ||
| 41 | + | ||
| 42 | + return args.This(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + Persistent<FunctionTemplate> Ref::constructor_template; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + /* | ||
| 2 | + Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> | ||
| 3 | + */ | ||
| 4 | + | ||
| 5 | + #ifndef REF_H | ||
| 6 | + #define REF_H | ||
| 7 | + | ||
| 8 | + #include <v8.h> | ||
| 9 | + #include <node.h> | ||
| 10 | + #include <node_events.h> | ||
| 11 | + | ||
| 12 | + #include <git2.h> | ||
| 13 | + | ||
| 14 | + using namespace node; | ||
| 15 | + using namespace v8; | ||
| 16 | + | ||
| 17 | + class Ref : public EventEmitter { | ||
| 18 | + public: | ||
| 19 | + static Persistent<FunctionTemplate> constructor_template; | ||
| 20 | + static void Initialize (Handle<v8::Object> target); | ||
| 21 | + git_reference* GetValue(); | ||
| 22 | + void SetValue(git_reference* ref); | ||
| 23 | + | ||
| 24 | + protected: | ||
| 25 | + Ref() {} | ||
| 26 | + ~Ref() {} | ||
| 27 | + static Handle<Value> New(const Arguments& args); | ||
| 28 | + | ||
| 29 | + private: | ||
| 30 | + git_reference *ref; | ||
| 31 | + }; | ||
| 32 | + | ||
| 33 | + #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,8 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> | |||
| 9 | 9 | #include <git2.h> | |
| 10 | 10 | ||
| 11 | 11 | #include "repo.h" | |
| 12 | + #include "ref.h" | ||
| 13 | + #include "commit.h" | ||
| 12 | 14 | ||
| 13 | 15 | using namespace v8; | |
| 14 | 16 | using namespace node; | |
@@ -25,6 +27,7 @@ void Repo::Initialize(Handle<Object> target) { | |||
| 25 | 27 | NODE_SET_PROTOTYPE_METHOD(constructor_template, "open", Open); | |
| 26 | 28 | NODE_SET_PROTOTYPE_METHOD(constructor_template, "free", Free); | |
| 27 | 29 | NODE_SET_PROTOTYPE_METHOD(constructor_template, "init", Init); | |
| 30 | + NODE_SET_PROTOTYPE_METHOD(constructor_template, "lookup_ref", LookupRef); | ||
| 28 | 31 | ||
| 29 | 32 | target->Set(String::NewSymbol("Repo"), constructor_template->GetFunction()); | |
| 30 | 33 | } | |
@@ -52,6 +55,12 @@ int Repo::Init(const char* path, bool is_bare) { | |||
| 52 | 55 | return err; | |
| 53 | 56 | } | |
| 54 | 57 | ||
| 58 | + int Repo::LookupRef(git_reference* ref, const char* name) { | ||
| 59 | + int err = git_repository_lookup_ref(&ref, this->repo, name); | ||
| 60 | + | ||
| 61 | + return err; | ||
| 62 | + } | ||
| 63 | + | ||
| 55 | 64 | Handle<Value> Repo::New(const Arguments& args) { | |
| 56 | 65 | HandleScope scope; | |
| 57 | 66 | ||
@@ -209,4 +218,80 @@ int Repo::EIO_AfterInit(eio_req *req) { | |||
| 209 | 218 | return 0; | |
| 210 | 219 | } | |
| 211 | 220 | ||
| 221 | + Handle<Value> Repo::LookupRef(const Arguments& args) { | ||
| 222 | + Repo *repo = ObjectWrap::Unwrap<Repo>(args.This()); | ||
| 223 | + Local<Function> callback; | ||
| 224 | + | ||
| 225 | + HandleScope scope; | ||
| 226 | + | ||
| 227 | + if(args.Length() == 0 || !args[0]->IsObject()) { | ||
| 228 | + return ThrowException(Exception::Error(String::New("Ref is required and must be an Object."))); | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + if(args.Length() == 1 || !args[1]->IsString()) { | ||
| 232 | + return ThrowException(Exception::Error(String::New("Name is required and must be a String."))); | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + if(args.Length() == 2 || !args[2]->IsFunction()) { | ||
| 236 | + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + callback = Local<Function>::Cast(args[2]); | ||
| 240 | + | ||
| 241 | + lookupref_request *ar = new lookupref_request(); | ||
| 242 | + ar->repo = repo; | ||
| 243 | + //git_reference* ref; | ||
| 244 | + //ar->ref = ObjectWrap::Unwrap<Ref>(args[0]->ToObject()); | ||
| 245 | + ar->name = Persistent<Value>::New(args[1]); | ||
| 246 | + ar->callback = Persistent<Function>::New(callback); | ||
| 247 | + | ||
| 248 | + repo->Ref(); | ||
| 249 | + | ||
| 250 | + eio_custom(EIO_LookupRef, EIO_PRI_DEFAULT, EIO_AfterLookupRef, ar); | ||
| 251 | + ev_ref(EV_DEFAULT_UC); | ||
| 252 | + | ||
| 253 | + return Undefined(); | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + int Repo::EIO_LookupRef(eio_req *req) { | ||
| 257 | + lookupref_request *ar = static_cast<lookupref_request *>(req->data); | ||
| 258 | + | ||
| 259 | + String::Utf8Value name(ar->name); | ||
| 260 | + ar->err = Persistent<Value>::New(Integer::New(ar->repo->LookupRef(ar->ref->GetValue(), *name))); | ||
| 261 | + | ||
| 262 | + //if(Int32::Cast(*ar->err)->Value() == 0) { | ||
| 263 | + // //ar->ref->SetValue(ref); | ||
| 264 | + //} | ||
| 265 | + | ||
| 266 | + return 0; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + int Repo::EIO_AfterLookupRef(eio_req *req) { | ||
| 270 | + HandleScope scope; | ||
| 271 | + | ||
| 272 | + lookupref_request *ar = static_cast<lookupref_request *>(req->data); | ||
| 273 | + ev_unref(EV_DEFAULT_UC); | ||
| 274 | + ar->repo->Unref(); | ||
| 275 | + | ||
| 276 | + Local<Value> argv[2]; | ||
| 277 | + argv[0] = Number::Cast(*ar->err); | ||
| 278 | + argv[1] = String::Cast(*ar->name); | ||
| 279 | + //argv[2] = ref->Wrap(*ar->ref); | ||
| 280 | + | ||
| 281 | + TryCatch try_catch; | ||
| 282 | + | ||
| 283 | + ar->callback->Call(Context::GetCurrent()->Global(), 2, argv); | ||
| 284 | + | ||
| 285 | + if(try_catch.HasCaught()) | ||
| 286 | + FatalException(try_catch); | ||
| 287 | + | ||
| 288 | + ar->err.Dispose(); | ||
| 289 | + ar->name.Dispose(); | ||
| 290 | + ar->callback.Dispose(); | ||
| 291 | + | ||
| 292 | + delete ar; | ||
| 293 | + | ||
| 294 | + return 0; | ||
| 295 | + } | ||
| 296 | + | ||
| 212 | 297 | Persistent<FunctionTemplate> Repo::constructor_template; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments