From e6e738806ef8b734fb009c1594087633251d7608 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 22 Mar 2013 15:55:49 +1300 Subject: [PATCH 01/24] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2442f8583..8921c3797 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ nodegit > Node.js libgit2 bindings -**v0.0.72** [![Build +**v0.0.74** [![Build Status](https://travis-ci.org/tbranyen/nodegit.png)](https://travis-ci.org/tbranyen/nodegit) Maintained by Tim Branyen [@tbranyen](http://twitter.com/tbranyen) and Michael From 8935460330f6aac0e35ede2794d3ffec050a6afc Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 22 Mar 2013 21:55:27 +1300 Subject: [PATCH 02/24] Added note about python requirement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8921c3797..9c5673c98 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Building and installing ----------------------- ### Dependencies ### -To install `nodegit` you need `Node.js` and `cmake`. To run unit tests you will need to have +To install `nodegit` you need `Node.js`, `python` and `cmake`. To run unit tests you will need to have `git` installed and accessible from your `PATH` to fetch any `vendor/` addons. ### Easy install (Recommended) ### From c716096d8790a718512d0a73ce561537beb4d93a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 22 Mar 2013 22:00:28 +1300 Subject: [PATCH 03/24] Updated example in readme --- README.md | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9c5673c98..cd3769037 100644 --- a/README.md +++ b/README.md @@ -69,34 +69,32 @@ API Example Usage #### Convenience API #### -```` javascript +```JavaScript var git = require("nodegit"); // Read a repository -git.repo('.git', function(err, repo) { - // Success is always 0, failure is always an error string +var git = require('nodegit'); + +// nodegit follows the error, values ... callback argument convention +git.repo('.git', function(error, repo) { if (error) { throw error; } // Use the master branch - repo.branch('master', function(err, branch) { + repo.branch('master', function(error, branch) { if (error) { throw error; } - // Iterate over the revision history - var history = branch.history(); - - // Commit event emits commit object - history.on('commit', function(commit) { - // Print out `git log` emulation + // Print out `git log` emulation for each commit in the branch's history + branch.history().on('commit', function(error, commit) { console.log('commit ' + commit.sha); console.log(commit.author.name + '<' + commit.author.email + '>'); - console.log(commit.time); + console.log(new Date(commit.time * 1000)); console.log("\n"); console.log(commit.message); console.log("\n"); }); }); }); -```` +``` #### Raw API #### From 5bc0a2426e6244c80dbe964c35ac1d85b0eb48e3 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 22 Mar 2013 22:01:44 +1300 Subject: [PATCH 04/24] Allow libgit2 to handle invalid directory errors, fixes #57 --- lib/repo.js | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/repo.js b/lib/repo.js index 2420ba45b..b1864189b 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -14,25 +14,13 @@ exports.repo = function(directory, callback) { if (!callback || typeof callback !== 'function') { throw new Error('If directory is provided, callback function is required'); } - fs.exists(directory, function directoryExists(exists) { - if (!exists) { - callback(new Error('Directory must exist'), null); + self.repo.open(directory, function(error, rawRepo) { + if (error) { + callback(git.error(error), null); return; } - fs.realpath(directory, function realpathCallback(error, directory) { - if (error) { - callback(git.error(error), null); - return; - } - self.repo.open(directory, function(error, rawRepo) { - if (error) { - callback(git.error(error), null); - return; - } - self.repo = rawRepo; - callback(null, self); - }); - }); + self.repo = rawRepo; + callback(null, self); }); } From 9afc6f27f5c861cba88f204be7bc8294360fecba Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 10:29:55 +1300 Subject: [PATCH 05/24] Renamed ref to reference --- lib/index.js | 2 +- lib/{ref.js => reference.js} | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) rename lib/{ref.js => reference.js} (82%) diff --git a/lib/index.js b/lib/index.js index 37c6e39c0..db435dc9f 100755 --- a/lib/index.js +++ b/lib/index.js @@ -15,7 +15,7 @@ exports.repo = require("./repo.js").repo; exports.sig = require("./sig.js").sig; exports.oid = require("./oid.js").oid; exports.object = require("./object.js").object; -exports.ref = require("./ref.js").ref; +exports.ref = require("./reference.js").ref; exports.revwalk = require("./revwalk.js").revwalk; exports.commit = require("./commit.js").commit; exports.tree = require("./tree.js").tree; diff --git a/lib/ref.js b/lib/reference.js similarity index 82% rename from lib/ref.js rename to lib/reference.js index 5c244cece..7a35d1637 100644 --- a/lib/ref.js +++ b/lib/reference.js @@ -11,11 +11,8 @@ var _Ref = function(obj) { } self.lookup = function(name, callback) { - if(!callback || typeof callback !== 'function') { - throw new Error('Callback is required and must be a function'); - } - self.ref.lookup(self.repo, name, function(error) { + console.log('1', arguments); if (error) { callback(git.error(error), self); return; From 038459eca15bfc99501234afade069d290391774 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 12:16:51 +1300 Subject: [PATCH 06/24] Updated node version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b54c37a7..01dc79657 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "lib": "./lib" }, "engines": { - "node": "~0.8" + "node": ">= 0.8" }, "dependencies": { "async": ">= 0.1.21", From cbcf6196ac1151598e6ceb1c3ce9eb59777c476d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 12:17:06 +1300 Subject: [PATCH 07/24] Renamed LookupBaton->oid to rawOid --- include/commit.h | 2 +- src/commit.cc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/commit.h b/include/commit.h index da626c8ac..84e20a829 100755 --- a/include/commit.h +++ b/include/commit.h @@ -77,7 +77,7 @@ class GitCommit : public ObjectWrap { const git_error* error; git_repository* repo; - git_oid oid; + git_oid rawOid; std::string sha; git_commit* rawCommit; diff --git a/src/commit.cc b/src/commit.cc index 2d0f32142..7573a2e8f 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -274,7 +274,7 @@ Handle GitCommit::Lookup(const Arguments& args) { baton->repo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); if (args[1]->IsObject()) { - baton->oid = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->rawOid = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); } else { baton->sha = stringArgToString(args[1]->ToString()); } @@ -289,9 +289,9 @@ Handle GitCommit::Lookup(const Arguments& args) { void GitCommit::LookupWork(uv_work_t *req) { LookupBaton *baton = static_cast(req->data); - git_oid oid = baton->oid; + git_oid rawOid = baton->rawOid; if (!baton->sha.empty()) { - int returnCode = git_oid_fromstr(&oid, baton->sha.c_str()); + int returnCode = git_oid_fromstr(&rawOid, baton->sha.c_str()); if (returnCode != GIT_OK) { baton->error = giterr_last(); return; @@ -299,7 +299,7 @@ void GitCommit::LookupWork(uv_work_t *req) { } baton->rawCommit = NULL; - int returnCode = git_commit_lookup(&baton->rawCommit, baton->repo, &oid); + int returnCode = git_commit_lookup(&baton->rawCommit, baton->repo, &rawOid); if (returnCode != GIT_OK) { baton->error = giterr_last(); } From 18ab92ea9db748403d28714c7ffadeb2497c637e Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 12:17:56 +1300 Subject: [PATCH 08/24] Renamed ref to reference --- include/reference.h | 11 +++++++---- lib/index.js | 2 +- src/reference.cc | 14 +++++++------- 3 files changed, 15 insertions(+), 12 deletions(-) mode change 100755 => 100644 include/reference.h diff --git a/include/reference.h b/include/reference.h old mode 100755 new mode 100644 index 8037f2dad..d289adc0a --- a/include/reference.h +++ b/include/reference.h @@ -1,6 +1,9 @@ -/* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef REF_H #define REF_H @@ -19,7 +22,7 @@ using namespace v8; class GitReference : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize(Handle target); git_reference* GetValue(); void SetValue(git_reference* ref); diff --git a/lib/index.js b/lib/index.js index db435dc9f..ba04f7364 100755 --- a/lib/index.js +++ b/lib/index.js @@ -15,7 +15,7 @@ exports.repo = require("./repo.js").repo; exports.sig = require("./sig.js").sig; exports.oid = require("./oid.js").oid; exports.object = require("./object.js").object; -exports.ref = require("./reference.js").ref; +exports.reference = require("./reference.js").reference; exports.revwalk = require("./revwalk.js").revwalk; exports.commit = require("./commit.js").commit; exports.tree = require("./tree.js").tree; diff --git a/src/reference.cc b/src/reference.cc index 0993635d9..988d08cc6 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -21,16 +21,16 @@ using namespace node; void GitReference::Initialize(Handle target) { HandleScope scope; - Local t = FunctionTemplate::New(New); + Local tpl = FunctionTemplate::New(New); - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("Ref")); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->SetClassName(String::NewSymbol("Reference")); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "oid", Oid); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "lookup", Lookup); + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); + NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); - target->Set(String::NewSymbol("Ref"), constructor_template->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Reference"), constructor_template); } git_reference* GitReference::GetValue() { From 5392d17c8e2f56457940f0f6582544eb8cb83a63 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 18:02:50 +1300 Subject: [PATCH 09/24] Removed sync lookup function --- include/reference.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/reference.h b/include/reference.h index d289adc0a..9194e46dd 100644 --- a/include/reference.h +++ b/include/reference.h @@ -22,12 +22,11 @@ using namespace v8; class GitReference : public ObjectWrap { public: + const git_oid* Oid(); static Persistent constructor_template; static void Initialize(Handle target); git_reference* GetValue(); void SetValue(git_reference* ref); - int Lookup(git_repository* repo, const char* name); - const git_oid* Oid(); protected: GitReference() {} From 7a599cfd23513613b6c2737574f0805afd2e14af Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 18:03:48 +1300 Subject: [PATCH 10/24] Renamed async lookup methods, updated baton --- include/reference.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/reference.h b/include/reference.h index 9194e46dd..1150c20a3 100644 --- a/include/reference.h +++ b/include/reference.h @@ -25,6 +25,7 @@ class GitReference : public ObjectWrap { const git_oid* Oid(); static Persistent constructor_template; static void Initialize(Handle target); + git_reference* GetValue(); void SetValue(git_reference* ref); @@ -34,19 +35,23 @@ class GitReference : public ObjectWrap { static Handle New(const Arguments& args); static Handle Lookup(const Arguments& args); - static void EIO_Lookup(uv_work_t* req); - static void EIO_AfterLookup(uv_work_t* req); + static void LookupWork(uv_work_t* req); + static void LookupAfterWork(uv_work_t* req); static Handle Oid(const Arguments& args); private: git_reference *ref; - struct lookup_request { + struct LookupBaton { + uv_work_t request; + const git_error* error; + GitReference* ref; - GitRepo* repo; - int err; + git_reference* rawRef; + git_repository* rawRepo; std::string name; + Persistent callback; }; }; From 393aee27c2e79c064860a5f6bda2b938f20333b3 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 18:04:40 +1300 Subject: [PATCH 11/24] Added Oid async methods & baton --- include/reference.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/reference.h b/include/reference.h index 1150c20a3..46226573a 100644 --- a/include/reference.h +++ b/include/reference.h @@ -34,11 +34,14 @@ class GitReference : public ObjectWrap { ~GitReference() {} static Handle New(const Arguments& args); + static Handle Oid(const Arguments& args); + static void OidWork(uv_work_t* req); + static void OidAfterWork(uv_work_t* req); + static Handle Lookup(const Arguments& args); static void LookupWork(uv_work_t* req); static void LookupAfterWork(uv_work_t* req); - static Handle Oid(const Arguments& args); private: git_reference *ref; @@ -54,6 +57,16 @@ class GitReference : public ObjectWrap { Persistent callback; }; + + struct OidBaton { + uv_work_t request; + const git_error* error; + + const git_oid* rawOid; + git_reference* rawRef; + + Persistent callback; + }; }; #endif From 064c982012b68e574fb2878e92ec4a2c51226337 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 18:04:50 +1300 Subject: [PATCH 12/24] Refactored reference --- src/reference.cc | 188 +++++++++++++++++++++++++++++++---------------- 1 file changed, 124 insertions(+), 64 deletions(-) diff --git a/src/reference.cc b/src/reference.cc index 988d08cc6..e9c72b403 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -14,6 +14,9 @@ #include "../include/repo.h" #include "../include/reference.h" #include "../include/oid.h" +#include "../include/error.h" + +#include "../include/functions/string.h" using namespace v8; using namespace node; @@ -41,14 +44,6 @@ void GitReference::SetValue(git_reference *ref) { this->ref = ref; } -int GitReference::Lookup(git_repository* repo, const char* name) { - return git_reference_lookup(&this->ref, repo, name); -} - -const git_oid* GitReference::Oid() { - return git_reference_target(this->ref); -} - Handle GitReference::New(const Arguments& args) { HandleScope scope; @@ -59,88 +54,153 @@ Handle GitReference::New(const Arguments& args) { return args.This(); } -Handle GitReference::Lookup(const Arguments& args) { +Handle GitReference::Oid(const Arguments& args) { HandleScope scope; - GitReference *ref = ObjectWrap::Unwrap(args.This()); - Local callback; - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repo is required and must be a Object."))); - } - - if(args.Length() == 1 || !args[1]->IsString()) { - return ThrowException(Exception::Error(String::New("Name is required and must be a String."))); - } - - if(args.Length() == 2 || !args[2]->IsFunction()) { + if(args.Length() == 0 || !args[0]->IsFunction()) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - callback = Local::Cast(args[2]); + OidBaton *baton = new OidBaton; + baton->request.data = baton; + baton->error = NULL; + baton->rawOid = NULL; + baton->rawRef = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); - lookup_request *ar = new lookup_request(); - ar->ref = ref; - ar->repo = ObjectWrap::Unwrap(args[0]->ToObject()); + uv_queue_work(uv_default_loop(), &baton->request, OidWork, (uv_after_work_cb)OidAfterWork); - String::Utf8Value name(args[1]); - ar->name = *name; + return Undefined(); +} - ar->callback = Persistent::New(callback); +void GitReference::OidWork(uv_work_t* req) { + OidBaton *baton = static_cast(req->data); - ref->Ref(); + git_ref_t referenceType = git_reference_type(baton->rawRef); - uv_work_t *req = new uv_work_t; - req->data = ar; - uv_queue_work(uv_default_loop(), req, EIO_Lookup, (uv_after_work_cb)EIO_AfterLookup); + if (referenceType == GIT_REF_INVALID) { + printf("invalid\n"); + giterr_set_str(GITERR_INVALID, "Invalid reference type"); + baton->error = giterr_last(); + return; + } - return scope.Close( Undefined() ); + if (referenceType == GIT_REF_SYMBOLIC) { + printf("symbolic\n"); + int returnCode = git_reference_resolve(&baton->rawRef, baton->rawRef); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + return; + } + } + baton->rawOid = git_reference_target(baton->rawRef); } +void GitReference::OidAfterWork(uv_work_t* req) { + HandleScope scope; + OidBaton *baton = static_cast(req->data); + + if (baton->error) { + Local argv[1] = { + GitError::WrapError(baton->error) + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } else { + + Handle oid = GitOid::constructor_template->NewInstance(); + GitOid *oidInstance = ObjectWrap::Unwrap(oid); + oidInstance->SetValue(*const_cast(baton->rawOid)); + + Handle argv[2] = { + Local::New(Null()), + oid + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } -void GitReference::EIO_Lookup(uv_work_t *req) { - lookup_request *ar = static_cast(req->data); - - git_repository* repo = ar->repo->GetValue(); - - ar->err = ar->ref->Lookup(repo, ar->name.c_str()); - + delete req; } -void GitReference::EIO_AfterLookup(uv_work_t *req) { +Handle GitReference::Lookup(const Arguments& args) { HandleScope scope; - lookup_request *ar = static_cast(req->data); - ar->ref->Unref(); - - Local argv[1]; - argv[0] = Integer::New(ar->err); + if(args.Length() == 0 || !args[0]->IsObject()) { + return ThrowException(Exception::Error(String::New("Repo is required and must be a Object."))); + } - TryCatch try_catch; + if(args.Length() == 1 || !args[1]->IsString()) { + return ThrowException(Exception::Error(String::New("Name is required and must be a String."))); + } - ar->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if(args.Length() == 2 || !args[2]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } - if(try_catch.HasCaught()) - FatalException(try_catch); + LookupBaton *baton = new LookupBaton; + baton->request.data = baton; + baton->ref = ObjectWrap::Unwrap(args.This()); + baton->ref->Ref(); + baton->error = NULL; + baton->rawRepo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->name = stringArgToString(args[1]->ToString()); + baton->callback = Persistent::New(Local::Cast(args[2])); - ar->callback.Dispose(); + uv_queue_work(uv_default_loop(), &baton->request, LookupWork, (uv_after_work_cb)LookupAfterWork); - delete ar; - delete req; + return Undefined(); } -Handle GitReference::Oid(const Arguments& args) { - HandleScope scope; - - GitReference *ref = ObjectWrap::Unwrap(args.This()); +void GitReference::LookupWork(uv_work_t *req) { + LookupBaton *baton = static_cast(req->data); - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid is required and must be an Object."))); + baton->rawRef = NULL; + int returnCode = git_reference_lookup(&baton->rawRef, baton->rawRepo, baton->name.c_str()); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); } +} - GitOid *oid = ObjectWrap::Unwrap(args[0]->ToObject()); - git_oid* in = const_cast(ref->Oid()); - oid->SetValue(*in); +void GitReference::LookupAfterWork(uv_work_t *req) { + HandleScope scope; + LookupBaton *baton = static_cast(req->data); + + if (baton->error) { + Local argv[1] = { + GitError::WrapError(baton->error) + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } else { + + baton->ref->SetValue(baton->rawRef); + + Handle argv[2] = { + Local::New(Null()), + baton->ref->handle_ + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } - return scope.Close( Undefined() ); + baton->ref->Unref(); + delete req; } -Persistent GitReference::constructor_template; + +Persistent GitReference::constructor_template; From 38c2d8e557fd390df26c5a79a0374af1c2e19176 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 23 Mar 2013 23:58:14 +1300 Subject: [PATCH 13/24] Renamed Ref to Reference --- test/raw-blob.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/raw-blob.js b/test/raw-blob.js index c8ba41a71..50629b4a3 100644 --- a/test/raw-blob.js +++ b/test/raw-blob.js @@ -41,7 +41,7 @@ exports.constructor = function(test){ // Blob::Lookup exports.lookup = function(test) { var testOid = new git.Oid(), - testRef = new git.Ref(testRepo), + testRef = new git.Reference(testRepo), testBlob = new git.Blob(); test.expect(5); From 1d10d5be7ecedd015449c8add8003d589eba8507 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:12:27 +1300 Subject: [PATCH 14/24] Updated repo.branch --- lib/repo.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/repo.js b/lib/repo.js index b1864189b..069c80c0a 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -31,18 +31,23 @@ exports.repo = function(directory, callback) { * @param {Function} */ self.branch = function(name, callback) { - git.ref(self.repo).lookup('refs/heads/' + name, function(error, ref) { + git.reference(self.repo).lookup('refs/heads/' + name, function referenceLookupCallback(error, reference) { if (error) { callback(git.error(error), null); return; } - - git.commit(self.repo).lookup(self.repo, ref.oid().oid, function(error, commit) { + reference.oid(function oidCallback(error, oid) { if (error) { callback(git.error(error), null); return; } - callback(null, commit); + git.commit().lookup(self.repo, oid, function commitLookupCallback(error, commit) { + if (error) { + callback(git.error(error), null); + return; + } + callback(null, commit); + }); }); }); }; From a580452e8c07e9b263de41ae8ab5b3779b54d4ef Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:12:44 +1300 Subject: [PATCH 15/24] Push rawOid instead of convenience in revwalk --- lib/revwalk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/revwalk.js b/lib/revwalk.js index 9659828d7..8958f9e89 100644 --- a/lib/revwalk.js +++ b/lib/revwalk.js @@ -20,7 +20,7 @@ var _RevWalk = function( obj ) { self.walk = function(oid, callback) { if(!callback) { return; } - self.revwalk.push(oid, function(error) { + self.revwalk.push(oid.getRawOid(), function(error) { if (error) { callback.apply(this, [git.error(error)]); return; From 1c997f2a257d32bd4ee39dba5bf0a9989cca2022 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:13:18 +1300 Subject: [PATCH 16/24] Use internal commit method --- lib/repo.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/repo.js b/lib/repo.js index 069c80c0a..b6541b427 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -41,7 +41,7 @@ exports.repo = function(directory, callback) { callback(git.error(error), null); return; } - git.commit().lookup(self.repo, oid, function commitLookupCallback(error, commit) { + self.commit(oid, function commitLookupCallback(error, commit) { if (error) { callback(git.error(error), null); return; @@ -53,8 +53,8 @@ exports.repo = function(directory, callback) { }; // Find a single commit - self.commit = function(sha, callback) { - git.commit().lookup(self.repo, sha, function(error, commit) { + self.commit = function(oid, callback) { + git.commit().lookup(self.repo, oid, function(error, commit) { callback(error, commit); }); }; From bfcf4639d862a7ad1fe7e0f8b59dce1b51e1aeab Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:13:32 +1300 Subject: [PATCH 17/24] Refactored reference convenience object --- lib/reference.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/reference.js b/lib/reference.js index 7a35d1637..94e8231d9 100644 --- a/lib/reference.js +++ b/lib/reference.js @@ -1,33 +1,37 @@ var git = require('../'); -var _Ref = function(obj) { +var Reference = function(rawReference) { var self = {}; - if(obj instanceof git.raw.Repo) { - self.repo = obj; - self.ref = new git.raw.Ref(obj); - } else if(obj instanceof git.raw.Ref) { - self.ref = obj; + if(rawReference instanceof git.raw.Reference) { + self.reference = rawReference; + } else if(rawReference instanceof git.raw.Repo) { + self.repo = rawReference; + self.reference = new git.raw.Reference(rawReference); } self.lookup = function(name, callback) { - self.ref.lookup(self.repo, name, function(error) { - console.log('1', arguments); + self.reference.lookup(self.repo, name, function(error, reference) { if (error) { callback(git.error(error), self); return; } + self.reference = reference; callback(null, self); }); }; - self.oid = function() { - var oid = git.oid(); - self.ref.oid(oid.oid); - return oid; + self.oid = function(callback) { + self.reference.oid(function(error, rawOid) { + if (error) { + callback(git.error(error, self)); + return; + } + callback(null, git.oid(rawOid)); + }); }; return self; }; -exports.ref = _Ref; +exports.reference = Reference; From 67c1ff501c37a20ed6d1f1e6e2e52a585f85c78d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:13:44 +1300 Subject: [PATCH 18/24] Refactored Oid convenience object --- lib/oid.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/oid.js b/lib/oid.js index cda090b15..972933392 100644 --- a/lib/oid.js +++ b/lib/oid.js @@ -1,18 +1,19 @@ var git = require( '../' ); -var _Oid = function(obj) { +var Oid = function(rawOid) { var self = {}; - if(obj instanceof git.raw.Oid) { - self.oid = obj; + if(rawOid instanceof git.raw.Oid) { + self.oid = rawOid; } else { self.oid = new git.raw.Oid(); - - if (typeof obj === 'string') { - self.oid.mkstr(obj); - } } + + self.getRawOid = function() { + return self.oid; + }; + return self; }; -exports.oid = _Oid; +exports.oid = Oid; From edefe271b68712f2a84a18863c9506b3c1a2711d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:14:03 +1300 Subject: [PATCH 19/24] Minor updates to repo.cc --- src/repo.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/repo.cc b/src/repo.cc index 42e05026f..b1d6d5db9 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -1,5 +1,5 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen * @author Michael Robinson @codeofinterest * * Dual licensed under the MIT and GPL licenses. @@ -68,7 +68,7 @@ Handle GitRepo::Open(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - OpenBaton *baton = new OpenBaton(); + OpenBaton *baton = new OpenBaton; baton->request.data = baton; baton->error = NULL; baton->path = stringArgToString(args[0]->ToString());; @@ -157,8 +157,7 @@ Handle GitRepo::Init(const Arguments& args) { baton->repo = ObjectWrap::Unwrap(args.This()); baton->repo->Ref(); baton->rawRepo = baton->repo->GetValue(); - String::Utf8Value path(args[0]); - baton->path = *path; + baton->path = stringArgToString(args[0]->ToString());; baton->isBare = args[1]->ToBoolean()->Value(); baton->callback = Persistent::New(Local::Cast(args[2])); From bdc8e468633132904434383687b9569151f2982c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:14:26 +1300 Subject: [PATCH 20/24] Wrap details raw oid in convenience object in appydetails --- lib/commit.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index 5a75b5103..c952f4d36 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -11,6 +11,10 @@ var git = require( '../' ), function applyDetails(details, context) { if (details) { for (var detailKey in details) { + if (detailKey === 'id') { + context[detailKey] = git.oid(details[detailKey]); + continue; + } context[detailKey] = details[detailKey]; } } @@ -61,11 +65,14 @@ var _Commit = function(rawCommit) { * with the result. * * @param {Repo} repo - * @param {Oid|String} oid Raw OID object or SHA string + * @param {Oid|String|RawOid} oid Raw or convenience OID object or SHA string * @param {Function} callback */ self.lookup = function(repo, oid, callback) { self.repo = repo; + if (typeof oid !== 'string' && !(oid instanceof git.raw.Oid)) { + oid = oid.getRawOid(); + } self.commit.lookup(repo, oid, function(error, commit) { if (error) { callback(git.error(error), null); From 93907060046348f126f16f36034b6ffc9f6cb00b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:14:37 +1300 Subject: [PATCH 21/24] Updated reference tests --- test/raw-reference.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/raw-reference.js b/test/raw-reference.js index 06afa0aaa..e20662f60 100644 --- a/test/raw-reference.js +++ b/test/raw-reference.js @@ -27,18 +27,19 @@ exports.constructor = function(test){ test.expect(3); // Test for function - helper.testFunction(test.equals, git.Ref, 'Ref'); + helper.testFunction(test.equals, git.Reference, 'Reference'); // Ensure we get an instance of Ref - test.ok(new git.Ref() instanceof git.Ref, 'Invocation returns an instance of Ref'); + test.ok(new git.Reference() instanceof git.Reference, 'Invocation returns an instance of Ref'); test.done(); }; // Ref::Lookup exports.lookup = function(test) { + var testRepo = new git.Repo(), - master = new git.Ref(); + master = new git.Reference(); test.expect(5); From 35dad0c65c2a9fd7973bea6f8e00eedc6f56faf7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 00:14:51 +1300 Subject: [PATCH 22/24] Code style normalization --- lib/index.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index ba04f7364..6d37ebac3 100755 --- a/lib/index.js +++ b/lib/index.js @@ -1,25 +1,25 @@ // Used to detect for Cygwin -var os = require("os"); +var os = require('os'); // Required for Windows/Cygwin support -var root = [__dirname, "/../vendor/libgit2/build/shared"].join(""), +var root = [__dirname, '/../vendor/libgit2/build/shared'].join(''), path = process.env.PATH; -if (~os.type().indexOf("CYGWIN") && !~path.indexOf(root)) { - process.env.PATH = root + ":" + path; +if (~os.type().indexOf('CYGWIN') && !~path.indexOf(root)) { + process.env.PATH = root + ':' + path; } // Import libraries -exports.blob = require("./blob.js").blob; -exports.repo = require("./repo.js").repo; -exports.sig = require("./sig.js").sig; -exports.oid = require("./oid.js").oid; -exports.object = require("./object.js").object; -exports.reference = require("./reference.js").reference; -exports.revwalk = require("./revwalk.js").revwalk; -exports.commit = require("./commit.js").commit; -exports.tree = require("./tree.js").tree; -exports.entry = require("./tree_entry.js").entry; +exports.blob = require('./blob.js').blob; +exports.repo = require('./repo.js').repo; +exports.sig = require('./sig.js').sig; +exports.oid = require('./oid.js').oid; +exports.object = require('./object.js').object; +exports.reference = require('./reference.js').reference; +exports.revwalk = require('./revwalk.js').revwalk; +exports.commit = require('./commit.js').commit; +exports.tree = require('./tree.js').tree; +exports.entry = require('./tree_entry.js').entry; // Assign raw api to module try { @@ -29,8 +29,8 @@ try { } // Initialize objects that need to access their raw counterparts -exports.diffList = require("./diff_list.js").diffList; -exports.error = require("./error.js").error; +exports.diffList = require('./diff_list.js').diffList; +exports.error = require('./error.js').error; // Set version exports.version = require('../package').version; From 87cccb3890c74ba3a0073a27048f7e04282dcdbd Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 23:03:58 +1300 Subject: [PATCH 23/24] Added python2 check, should help resolve #51 --- install.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/install.js b/install.js index 2275fff38..e5a15e53e 100644 --- a/install.js +++ b/install.js @@ -5,7 +5,8 @@ var async = require('async'), request = require('request'), zlib = require('zlib'), fs = require('fs-extra'), - tar = require('tar'); + tar = require('tar'), + exec = require('child_process').exec; function passthru() { var args = Array.prototype.slice.call(arguments); @@ -62,7 +63,28 @@ var checkoutDependencies = function(mainCallback) { }; var libgit2BuildDirectory = path.join(__dirname, 'vendor/libgit2/build'); + +// The python executable to use when building libgit2 +var pythonExecutable = 'python'; + async.series([ + function checkPython2Exists(callback) { + exec('which python2', + function (error) { + if (error !== null) { + pythonExecutable = 'python2'; + callback(); + return; + } + // python2 is not available, check for python + exec('which python', function(error) { + if (error) { + throw new Error('Python is required to build libgit2'); + } + }); + }); + + }, function prepareLibgit2Repository(callback) { // Check for presence of .git folder fs.exists(__dirname + '/.git', function(exists) { @@ -99,7 +121,7 @@ async.series([ function configureNodegit(callback) { console.log('[nodegit] Building native module.'); // shpassthru('node-gyp configure --python python2 --debug', callback); - shpassthru('node-gyp configure --python python2', callback); + shpassthru('node-gyp configure --python ' + pythonExecutable, callback); }, function buildNodegit(callback) { shpassthru('node-gyp build', callback); From 843d6d71a469a19f6bd5c6459fcbf50c908adc11 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sun, 24 Mar 2013 23:04:52 +1300 Subject: [PATCH 24/24] Updated version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 01dc79657..764267fb5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodegit", "description": "Node.js libgit2 asynchronous native bindings", - "version": "0.0.74", + "version": "0.0.75", "homepage": "https://github.com/tbranyen/nodegit", "keywords": [ "libgit2",