From 9084e38cc5df9ab66c450f1b90db0a25aec46373 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 07:45:42 +1300 Subject: [PATCH 001/186] Updated version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 025bec00e..e2d168229 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodegit", "description": "Node.js libgit2 asynchronous native bindings", - "version": "0.0.77", + "version": "0.0.78", "homepage": "https://github.com/tbranyen/nodegit", "keywords": [ "libgit2", From 5c9a2e2c0c371b9bcc832be9e352cc27e427e848 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 08:12:21 +1300 Subject: [PATCH 002/186] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd3769037..30bd1cb9a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ nodegit > Node.js libgit2 bindings -**v0.0.74** [![Build +**v0.0.78** [![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 a44c81558d0f72ccf6c1facbe2ba0b9b711586a9 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:03:45 +1300 Subject: [PATCH 003/186] Added commit helper function --- include/functions/commit.h | 29 +++++++++++++++++++++++ src/functions/commit.cc | 47 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 include/functions/commit.h create mode 100644 src/functions/commit.cc diff --git a/include/functions/commit.h b/include/functions/commit.h new file mode 100644 index 000000000..2813694e6 --- /dev/null +++ b/include/functions/commit.h @@ -0,0 +1,29 @@ +#include +#include +#include +#include + +#include "cvv8/v8-convert.hpp" + +#include "../../vendor/libgit2/include/git2.h" + +#include "../../include/functions/string.h" + +#ifndef COMMIT_FUNCTIONS +#define COMMIT_FUNCTIONS + +struct GitCommitDetails { + const git_oid *oid; + char sha[GIT_OID_HEXSZ + 1]; + const char* message; + time_t time; + int timeOffset; + const git_signature* committer; + const git_signature* author; + unsigned int parentCount; + std::vector parentShas; +}; + +v8::Local createCommitDetailsObject(GitCommitDetails* rawDetails); + +#endif diff --git a/src/functions/commit.cc b/src/functions/commit.cc new file mode 100644 index 000000000..30dff25ae --- /dev/null +++ b/src/functions/commit.cc @@ -0,0 +1,47 @@ +#include "../../include/oid.h" +#include "../../include/functions/commit.h" + +/** + * Non blocking, Converts GitCommitDetails struct into a v8::Local for JavaScript + */ +v8::Local createCommitDetailsObject(GitCommitDetails* rawDetails) { + + v8::Local details = v8::Object::New(); + + v8::Handle oid = GitOid::constructor_template->NewInstance(); + GitOid *oidInstance = node::ObjectWrap::Unwrap(oid); + oidInstance->SetValue(*const_cast(rawDetails->oid)); + + details->Set(String::NewSymbol("id"), oid); + details->Set(String::NewSymbol("sha"), String::New(rawDetails->sha)); + details->Set(String::NewSymbol("message"), cvv8::CastToJS(rawDetails->message)); + details->Set(String::NewSymbol("time"), cvv8::CastToJS(rawDetails->time)); + details->Set(String::NewSymbol("timeOffset"), cvv8::CastToJS(rawDetails->timeOffset)); + + v8::Local committer = v8::Object::New(); + committer->Set(String::NewSymbol("name"), cvv8::CastToJS(rawDetails->committer->name)); + committer->Set(String::NewSymbol("email"), cvv8::CastToJS(rawDetails->committer->email)); + + v8::Local committerWhen = v8::Object::New(); + committerWhen->Set(String::NewSymbol("time"), cvv8::CastToJS(rawDetails->committer->when.time)); + committerWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(rawDetails->committer->when.offset)); + committer->Set(String::NewSymbol("when"), cvv8::CastToJS(committerWhen)); + + details->Set(String::NewSymbol("committer"), committer); + + v8::Local author = v8::Object::New(); + author->Set(String::NewSymbol("name"), cvv8::CastToJS(rawDetails->author->name)); + author->Set(String::NewSymbol("email"), cvv8::CastToJS(rawDetails->author->email)); + + v8::Local authorWhen = v8::Object::New(); + authorWhen->Set(String::NewSymbol("time"), cvv8::CastToJS(rawDetails->author->when.time)); + authorWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(rawDetails->author->when.offset)); + author->Set(String::NewSymbol("when"), authorWhen); + + details->Set(String::NewSymbol("author"), author); + + details->Set(String::NewSymbol("parentCount"), cvv8::CastToJS(rawDetails->parentCount)); + details->Set(String::NewSymbol("parentShas"), cvv8::CastToJS(rawDetails->parentShas)); + + return details; +} From 1656bb96e8a77c4f9236e9dbc56c7409882aa4d9 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:04:08 +1300 Subject: [PATCH 004/186] Moved include to header --- src/commit.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/commit.cc b/src/commit.cc index 2c88d001b..278791b03 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -20,8 +20,6 @@ #include "../include/commit.h" #include "../include/error.h" -#include "../include/functions/string.h" - using namespace v8; using namespace cvv8; using namespace node; From 3518cf8d73c9aed51f075023f4e015e6169d3955 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:04:58 +1300 Subject: [PATCH 005/186] Initialise baton's error object --- src/commit.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commit.cc b/src/commit.cc index 278791b03..f5f8e4eec 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -143,8 +143,9 @@ Handle GitCommit::FetchDetails(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - FetchDetailsBaton* baton = new FetchDetailsBaton(); + FetchDetailsBaton* baton = new FetchDetailsBaton; baton->request.data = baton; + baton->error = NULL; baton->rawCommit = ObjectWrap::Unwrap(args.This())->commit; baton->callback = Persistent::New(Local::Cast(args[0])); From 72093226d6a032db23d1ec3f3d111758b0c9420f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:05:07 +1300 Subject: [PATCH 006/186] Use commit helper function --- include/commit.h | 13 ++--- src/commit.cc | 127 +++++++++++------------------------------------ 2 files changed, 34 insertions(+), 106 deletions(-) diff --git a/include/commit.h b/include/commit.h index 84e20a829..bc4e8f4e6 100755 --- a/include/commit.h +++ b/include/commit.h @@ -16,6 +16,9 @@ #include "oid.h" #include "tree.h" +#include "../include/functions/string.h" +#include "../include/functions/commit.h" + using namespace node; using namespace v8; @@ -92,15 +95,7 @@ class GitCommit : public ObjectWrap { const git_error* error; git_commit* rawCommit; - const git_oid *oid; - char sha[GIT_OID_HEXSZ + 1]; - const char* message; - time_t time; - int timeOffset; - const git_signature* committer; - const git_signature* author; - unsigned int parentCount; - std::vector parentShas; + GitCommitDetails* details; Persistent callback; }; diff --git a/src/commit.cc b/src/commit.cc index f5f8e4eec..043c90646 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -76,64 +76,33 @@ Handle GitCommit::FetchDetailsSync(const Arguments& args) { HandleScope scope; GitCommit *commit = ObjectWrap::Unwrap(args.This()); + git_commit* rawCommit = commit->GetValue(); - Local details = Object::New(); + GitCommitDetails* details = new GitCommitDetails; + details->oid = git_commit_id(rawCommit); - Handle oid = GitOid::constructor_template->NewInstance(); + details->sha[GIT_OID_HEXSZ] = '\0'; + git_oid_fmt(details->sha, details->oid); - char sha[GIT_OID_HEXSZ + 1]; - sha[GIT_OID_HEXSZ] = '\0'; - GitOid *oidInstance = ObjectWrap::Unwrap(oid); - const git_oid* rawOid = git_commit_id(commit->commit); - oidInstance->SetValue(*const_cast(rawOid)); - git_oid_fmt(sha, rawOid); + details->message = git_commit_message(rawCommit); + details->time = git_commit_time(rawCommit); + details->timeOffset = git_commit_time_offset(rawCommit); + details->committer = git_commit_committer(rawCommit); + details->author = git_commit_author(rawCommit); + details->parentCount = git_commit_parentcount(rawCommit); - details->Set(String::NewSymbol("id"), oid); - details->Set(String::NewSymbol("sha"), String::New(sha)); - details->Set(String::NewSymbol("message"), cvv8::CastToJS(git_commit_message(commit->commit))); - details->Set(String::NewSymbol("time"), cvv8::CastToJS(git_commit_time(commit->commit))); - details->Set(String::NewSymbol("timeOffset"), cvv8::CastToJS(git_commit_time_offset(commit->commit))); - - const git_signature *rawCommitter = git_commit_committer(commit->commit); - Local committer = Object::New(); - committer->Set(String::NewSymbol("name"), cvv8::CastToJS(rawCommitter->name)); - committer->Set(String::NewSymbol("email"), cvv8::CastToJS(rawCommitter->email)); - - Local committerWhen = Object::New(); - committerWhen->Set(String::NewSymbol("when"), cvv8::CastToJS(rawCommitter->when.time)); - committerWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(rawCommitter->when.offset)); - committer->Set(String::NewSymbol("when"), cvv8::CastToJS(committerWhen)); - - details->Set(String::NewSymbol("committer"), committer); - - const git_signature* rawAuthor = git_commit_author(commit->commit); - Local author = Object::New(); - author->Set(String::NewSymbol("name"), cvv8::CastToJS(rawAuthor->name)); - author->Set(String::NewSymbol("email"), cvv8::CastToJS(rawAuthor->email)); - - Local authorWhen = Object::New(); - authorWhen->Set(String::NewSymbol("when"), cvv8::CastToJS(rawAuthor->when.time)); - authorWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(rawAuthor->when.offset)); - author->Set(String::NewSymbol("when"), authorWhen); - - details->Set(String::NewSymbol("author"), author); - - int parentCount = git_commit_parentcount(commit->commit); - std::vector parentShas; + int parentCount = details->parentCount; while (parentCount > 0) { int parentIndex = parentCount -1; char sha[GIT_OID_HEXSZ + 1]; sha[GIT_OID_HEXSZ] = '\0'; - const git_oid *parentOid = git_commit_parent_id(commit->commit, parentIndex); + const git_oid *parentOid = git_commit_parent_id(rawCommit, parentIndex); git_oid_fmt(sha, parentOid); - parentShas.push_back(sha); + details->parentShas.push_back(sha); parentCount--; } - details->Set(String::NewSymbol("parentCount"), cvv8::CastToJS(parentCount)); - details->Set(String::NewSymbol("parentShas"), cvv8::CastToJS(parentShas)); - - return scope.Close(details); + return scope.Close(createCommitDetailsObject(details)); } Handle GitCommit::FetchDetails(const Arguments& args) { @@ -145,7 +114,8 @@ Handle GitCommit::FetchDetails(const Arguments& args) { FetchDetailsBaton* baton = new FetchDetailsBaton; baton->request.data = baton; - baton->error = NULL; + baton->error = NULL; + baton->details = new GitCommitDetails; baton->rawCommit = ObjectWrap::Unwrap(args.This())->commit; baton->callback = Persistent::New(Local::Cast(args[0])); @@ -157,27 +127,27 @@ Handle GitCommit::FetchDetails(const Arguments& args) { void GitCommit::FetchDetailsWork(uv_work_t *req) { FetchDetailsBaton* baton = static_cast(req->data); - baton->oid = git_commit_id(baton->rawCommit); - - baton->sha[GIT_OID_HEXSZ] = '\0'; + GitCommitDetails* details = baton->details; + details->oid = git_commit_id(baton->rawCommit); - git_oid_fmt(baton->sha, baton->oid); + details->sha[GIT_OID_HEXSZ] = '\0'; + git_oid_fmt(details->sha, details->oid); - baton->message = git_commit_message(baton->rawCommit); - baton->time = git_commit_time(baton->rawCommit); - baton->timeOffset = git_commit_time_offset(baton->rawCommit); - baton->committer = git_commit_committer(baton->rawCommit); - baton->author = git_commit_author(baton->rawCommit); - baton->parentCount = git_commit_parentcount(baton->rawCommit); + details->message = git_commit_message(baton->rawCommit); + details->time = git_commit_time(baton->rawCommit); + details->timeOffset = git_commit_time_offset(baton->rawCommit); + details->committer = git_commit_committer(baton->rawCommit); + details->author = git_commit_author(baton->rawCommit); + details->parentCount = git_commit_parentcount(baton->rawCommit); - int parentCount = baton->parentCount; + int parentCount = details->parentCount; while (parentCount > 0) { int parentIndex = parentCount -1; char sha[GIT_OID_HEXSZ + 1]; sha[GIT_OID_HEXSZ] = '\0'; const git_oid *parentOid = git_commit_parent_id(baton->rawCommit, parentIndex); git_oid_fmt(sha, parentOid); - baton->parentShas.push_back(sha); + details->parentShas.push_back(sha); parentCount--; } } @@ -201,46 +171,9 @@ void GitCommit::FetchDetailsAfterWork(uv_work_t *req) { } } else { - Local details = Object::New(); - - Handle oid = GitOid::constructor_template->NewInstance(); - GitOid *oidInstance = ObjectWrap::Unwrap(oid); - oidInstance->SetValue(*const_cast(baton->oid)); - - details->Set(String::NewSymbol("id"), oid); - details->Set(String::NewSymbol("sha"), String::New(baton->sha)); - details->Set(String::NewSymbol("message"), cvv8::CastToJS(baton->message)); - details->Set(String::NewSymbol("time"), cvv8::CastToJS(baton->time)); - details->Set(String::NewSymbol("timeOffset"), cvv8::CastToJS(baton->timeOffset)); - - Local committer = Object::New(); - committer->Set(String::NewSymbol("name"), cvv8::CastToJS(baton->committer->name)); - committer->Set(String::NewSymbol("email"), cvv8::CastToJS(baton->committer->email)); - - Local committerWhen = Object::New(); - committerWhen->Set(String::NewSymbol("time"), cvv8::CastToJS(baton->committer->when.time)); - committerWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(baton->committer->when.offset)); - committer->Set(String::NewSymbol("when"), cvv8::CastToJS(committerWhen)); - - details->Set(String::NewSymbol("committer"), committer); - - Local author = Object::New(); - author->Set(String::NewSymbol("name"), cvv8::CastToJS(baton->author->name)); - author->Set(String::NewSymbol("email"), cvv8::CastToJS(baton->author->email)); - - Local authorWhen = Object::New(); - authorWhen->Set(String::NewSymbol("time"), cvv8::CastToJS(baton->author->when.time)); - authorWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(baton->author->when.offset)); - author->Set(String::NewSymbol("when"), authorWhen); - - details->Set(String::NewSymbol("author"), author); - - details->Set(String::NewSymbol("parentCount"), cvv8::CastToJS(baton->parentCount)); - details->Set(String::NewSymbol("parentShas"), cvv8::CastToJS(baton->parentShas)); - Handle argv[2] = { Local::New(Null()), - details + createCommitDetailsObject(baton->details) }; TryCatch try_catch; From b437f8e402f15080a959561093016c043cc0c3f5 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:05:49 +1300 Subject: [PATCH 007/186] Added commit helper function to node gyp --- binding.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/binding.gyp b/binding.gyp index ad556410f..79ace47dc 100644 --- a/binding.gyp +++ b/binding.gyp @@ -17,6 +17,7 @@ 'src/tree_entry.cc', 'src/diff_list.cc', 'src/threads.cc', + 'src/functions/commit.cc', 'src/functions/string.cc' ], From c0e4d28c0cf0bcb8dc38735f85a7a48ee489ef7d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:06:00 +1300 Subject: [PATCH 008/186] Added JS utilities --- lib/utilities.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 lib/utilities.js diff --git a/lib/utilities.js b/lib/utilities.js new file mode 100755 index 000000000..08f132927 --- /dev/null +++ b/lib/utilities.js @@ -0,0 +1,21 @@ +var git = require('../'); + +/** + * Apply given details to the context. + * + * @param {Object} details + * @param {Object} context + * @return {Object} The modified context. + */ +exports.applyProperties = function(details, context) { + if (details) { + for (var detailKey in details) { + if (detailKey === 'id') { + context[detailKey] = git.oid(details[detailKey]); + continue; + } + context[detailKey] = details[detailKey]; + } + } + return context; +}; From 0ff14523c38ce96b63cd74b69af78697ad8c5a23 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:06:21 +1300 Subject: [PATCH 009/186] Use JS utilities --- lib/commit.js | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 3c726faae..f9a2121f4 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -1,26 +1,7 @@ var git = require( '../' ), + utilities = require('./utilities'), events = require( 'events' ); -/** - * Apply given details to the context. - * - * @param {Object} details - * @param {Object} context - * @return {Object} The modified context. - */ -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]; - } - } - return context; -} - /** * Convenience commit constructor. * @@ -47,7 +28,7 @@ var Commit = function(rawCommit) { if (error) { error = git.error(error); } - applyDetails(details, self); + utilities.applyProperties(details, self); callback(error); }); }; @@ -57,7 +38,7 @@ var Commit = function(rawCommit) { */ self.fetchDetailsSync = function(callback) { var details = self.commit.fetchDetailsSync(); - return applyDetails(details, self); + return utilities.applyProperties(details, self); }; /** From aba633ae310582e4235840ed5b7f1a5cea3725fc Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:06:34 +1300 Subject: [PATCH 010/186] Updated exception message --- src/tree.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tree.cc b/src/tree.cc index 46ed0f8b2..75dd434cc 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -219,7 +219,7 @@ Handle GitTree::EntryByPath(const Arguments& args) { HandleScope scope; if(args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("Name is required and must be a String."))); + return ThrowException(Exception::Error(String::New("Path is required and must be a String."))); } if(args.Length() == 1 || !args[1]->IsFunction()) { From b323350c0d5123595a3685de00727350bfa476c4 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:06:42 +1300 Subject: [PATCH 011/186] Added basic utilities test --- test/utilities.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/utilities.js diff --git a/test/utilities.js b/test/utilities.js new file mode 100644 index 000000000..36ed198cb --- /dev/null +++ b/test/utilities.js @@ -0,0 +1,22 @@ +var git = require('../'), + utilities = require('../lib/utilities'); + +var object = { + property: 'value' +}; + +var details = { + one: 'one', + two: 'two' +}; + +// Repo +exports.basic = function(test){ + test.expect(2); + + object = utilities.applyProperties(details, object); + test.equal(object.one, details.one, 'Properties should match'); + test.equal(object.two, details.two, 'Properties should match'); + + test.done(); +}; From 28ca6050a9c494d9119a5dac26289f0abbb2f787 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 22:07:07 +1300 Subject: [PATCH 012/186] Updated file comment --- include/tree_entry.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/tree_entry.h b/include/tree_entry.h index c028444bd..7cbbb72ea 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef GITTREEENTRY_H #define GITTREEENTRY_H From 59ad116f019994b09d6a244cb9c4803c57823287 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 23:47:24 +1300 Subject: [PATCH 013/186] Removed debug lines --- src/reference.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/reference.cc b/src/reference.cc index e9c72b403..c3357443a 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -79,14 +79,12 @@ void GitReference::OidWork(uv_work_t* req) { git_ref_t referenceType = git_reference_type(baton->rawRef); if (referenceType == GIT_REF_INVALID) { - printf("invalid\n"); giterr_set_str(GITERR_INVALID, "Invalid reference type"); baton->error = giterr_last(); return; } 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(); From 315cb9276a9e6381f8cb39b166a05a083d9e9d8a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 23:48:09 +1300 Subject: [PATCH 014/186] Wrap instances of object in git.raw.Object, check type of id type --- lib/utilities.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utilities.js b/lib/utilities.js index 08f132927..c731c6ad9 100755 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -10,10 +10,14 @@ var git = require('../'); exports.applyProperties = function(details, context) { if (details) { for (var detailKey in details) { - if (detailKey === 'id') { + if (detailKey === 'id' && details[detailKey] instanceof git.raw.Oid) { context[detailKey] = git.oid(details[detailKey]); continue; } + if (detailKey === 'object' && details[detailKey] instanceof git.raw.Object) { + context[detailKey] = git.object(details[detailKey]); + continue; + } context[detailKey] = details[detailKey]; } } From 8acf6ce54dcbe2b1f7f315f5cf7f4958c40470bf Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 23:49:14 +1300 Subject: [PATCH 015/186] Removed sync tree_entry methods --- include/tree_entry.h | 19 ----------------- src/tree_entry.cc | 50 -------------------------------------------- 2 files changed, 69 deletions(-) diff --git a/include/tree_entry.h b/include/tree_entry.h index 7cbbb72ea..647228113 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -37,30 +37,11 @@ class GitTreeEntry : ObjectWrap { * @param target v8::Object the Node.js module object */ static void Initialize(Handle target); - - /** - * Accessor for GitTreeEntry - * - * @return the internal git_tree_entry reference - */ git_tree_entry* GetValue(); - - /** - * Mutator for GitTreeEntry - * - * @param obj a git_tree_entry object - */ void SetValue(git_tree_entry* tree); - const char* Name(); - int Attributes(); - const git_oid* Id(); - int ToObject(git_repository* repo, git_object** obj); protected: static Handle New(const Arguments& args); - static Handle Name(const Arguments& args); - static Handle Attributes(const Arguments& args); - static Handle Id(const Arguments& args); static Handle ToObject(const Arguments& args); private: diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 134932f7e..63eccc4ba 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -23,9 +23,6 @@ void GitTreeEntry::Initialize(Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("TreeEntry")); - NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); - NODE_SET_PROTOTYPE_METHOD(tpl, "attributes", Attributes); - NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id); NODE_SET_PROTOTYPE_METHOD(tpl, "toObject", ToObject); constructor_template = Persistent::New(tpl->GetFunction()); @@ -40,22 +37,6 @@ void GitTreeEntry::SetValue(git_tree_entry* entry) { this->entry = entry; } -const char* GitTreeEntry::Name() { - return git_tree_entry_name(this->entry); -} - -int GitTreeEntry::Attributes() { - return git_tree_entry_filemode(this->entry); -} - -const git_oid* GitTreeEntry::Id() { - return git_tree_entry_id(this->entry); -} - -int GitTreeEntry::ToObject(git_repository* repo, git_object** obj) { - return git_tree_entry_to_object(obj, repo, this->entry); -} - Handle GitTreeEntry::New(const Arguments& args) { HandleScope scope; @@ -66,37 +47,6 @@ Handle GitTreeEntry::New(const Arguments& args) { return scope.Close(args.This()); } -Handle GitTreeEntry::Name(const Arguments& args) { - HandleScope scope; - - GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); - - return scope.Close( String::New(entry->Name()) ); -} - -Handle GitTreeEntry::Attributes(const Arguments& args) { - HandleScope scope; - - GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); - - return scope.Close( Number::New(entry->Attributes()) ); -} - -Handle GitTreeEntry::Id(const Arguments& args) { - HandleScope scope; - - GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid is required and must be an Object."))); - } - - GitOid* oid = ObjectWrap::Unwrap(args[0]->ToObject()); - - oid->SetValue(*const_cast(entry->Id())); - - return scope.Close( Undefined() ); -} Handle GitTreeEntry::ToObject(const Arguments& args) { HandleScope scope; From 798a1788b87cf3126e5cac2ca518bb69ef1bc115 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 26 Mar 2013 23:51:27 +1300 Subject: [PATCH 016/186] Removed more sync methods from tree_entry --- include/tree_entry.h | 1 - src/tree_entry.cc | 25 ------------------------- 2 files changed, 26 deletions(-) diff --git a/include/tree_entry.h b/include/tree_entry.h index 647228113..aa6f8a0db 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -42,7 +42,6 @@ class GitTreeEntry : ObjectWrap { protected: static Handle New(const Arguments& args); - static Handle ToObject(const Arguments& args); private: git_tree_entry* entry; diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 63eccc4ba..5dc4e60e4 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -23,8 +23,6 @@ void GitTreeEntry::Initialize(Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("TreeEntry")); - NODE_SET_PROTOTYPE_METHOD(tpl, "toObject", ToObject); - constructor_template = Persistent::New(tpl->GetFunction()); target->Set(String::NewSymbol("TreeEntry"), constructor_template); } @@ -48,28 +46,5 @@ Handle GitTreeEntry::New(const Arguments& args) { } -Handle GitTreeEntry::ToObject(const Arguments& args) { - HandleScope scope; - - GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); - } - - if(args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Object is required and must be an Object."))); - } - - GitRepo* repo = ObjectWrap::Unwrap(args[0]->ToObject()); - GitObject* object = ObjectWrap::Unwrap(args[1]->ToObject()); - - git_object* out; - entry->ToObject(repo->GetValue(), &out); - - object->SetValue(out); - - return scope.Close( Undefined() ); -} Persistent GitTreeEntry::constructor_template; From 9215a7330795d03e3253fd1e257718b81c81c18f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:46:44 +1300 Subject: [PATCH 017/186] Updated blob's Initialize --- include/blob.h | 2 +- src/blob.cc | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/blob.h b/include/blob.h index 0426e8c88..0f97a8c59 100755 --- a/include/blob.h +++ b/include/blob.h @@ -25,7 +25,7 @@ class GitBlob : public ObjectWrap { * Variable: constructor_template * Used to create Node.js constructor. */ - static v8::Persistent constructor_template; + static Persistent constructor_template; /** * Function: Initialize * Used to intialize the EventEmitter from Node.js diff --git a/src/blob.cc b/src/blob.cc index ef2b9b7ac..22d966ebf 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -20,20 +20,20 @@ using namespace node; void GitBlob::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("Blob")); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->SetClassName(String::NewSymbol("Blob")); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "lookup", Lookup); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "rawContent", RawContent); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "rawSize", RawSize); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Close); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "createFromFile", CreateFromFile); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "createFromBuffer", CreateFromBuffer); + NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); + NODE_SET_PROTOTYPE_METHOD(tpl, "rawContent", RawContent); + NODE_SET_PROTOTYPE_METHOD(tpl, "rawSize", RawSize); + NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); + NODE_SET_PROTOTYPE_METHOD(tpl, "createFromFile", CreateFromFile); + NODE_SET_PROTOTYPE_METHOD(tpl, "createFromBuffer", CreateFromBuffer); - target->Set(String::NewSymbol("Blob"), constructor_template->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Blob"), constructor_template); } git_blob* GitBlob::GetValue() { @@ -232,4 +232,4 @@ Handle GitBlob::CreateFromBuffer(const Arguments& args) { return scope.Close( Integer::New(err) ); } -Persistent GitBlob::constructor_template; +Persistent GitBlob::constructor_template; From d0e8fdc5a77862cf8df7e12ac1ddf32bac08fd4c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:47:16 +1300 Subject: [PATCH 018/186] Use v8 namespace in blob implementation --- include/blob.h | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/include/blob.h b/include/blob.h index 0f97a8c59..a9d44fb3b 100755 --- a/include/blob.h +++ b/include/blob.h @@ -14,6 +14,7 @@ #include "repo.h" using namespace node; +using namespace v8; /** * Class: GitBlob @@ -31,9 +32,9 @@ class GitBlob : public ObjectWrap { * Used to intialize the EventEmitter from Node.js * * Parameters: - * target - v8::Object the Node.js global module object + * target - Object the Node.js global module object */ - static void Initialize(v8::Handle target); + static void Initialize(Handle target); /** * Accessor for GitBlob * @@ -112,22 +113,22 @@ class GitBlob : public ObjectWrap { * Function: New * * Parameters: - * args v8::Arguments function call + * args Arguments function call * * Returns: - * v8::Object args.This() + * Object args.This() */ - static v8::Handle New(const v8::Arguments& args); + static Handle New(const Arguments& args); /** * Function: Lookup * * Parameters: - * args v8::Arguments function call + * args Arguments function call * * Returns: - * v8::Object args.This() + * Object args.This() */ - static v8::Handle Lookup(const v8::Arguments& args); + static Handle Lookup(const Arguments& args); /** * Function: EIO_Lookup * @@ -147,52 +148,52 @@ class GitBlob : public ObjectWrap { * Function: RawContent * * Parameters: - * args v8::Arguments function call + * args Arguments function call * * Returns: - * v8::Object args.This() + * Object args.This() */ - static v8::Handle RawContent(const v8::Arguments& args); + static Handle RawContent(const Arguments& args); /** * Function: RawSize * * Parameters: - * args v8::Arguments function call + * args Arguments function call * * Returns: - * v8::Object args.This() + * Object args.This() */ - static v8::Handle RawSize(const v8::Arguments& args); + static Handle RawSize(const Arguments& args); /** * Function: Close * * Parameters: - * args v8::Arguments function call + * args Arguments function call * * Returns: - * v8::Object args.This() + * Object args.This() */ - static v8::Handle Close(const v8::Arguments& args); + static Handle Close(const Arguments& args); /** * Function: CreateFromFile * * Parameters: - * args v8::Arguments function call + * args Arguments function call * * Returns: - * v8::Object args.This() + * Object args.This() */ - static v8::Handle CreateFromFile(const v8::Arguments& args); + static Handle CreateFromFile(const Arguments& args); /** * Function: CreateFromBuffer * * Parameters: - * args v8::Arguments function call + * args Arguments function call * * Returns: - * v8::Object args.This() + * Object args.This() */ - static v8::Handle CreateFromBuffer(const v8::Arguments& args); + static Handle CreateFromBuffer(const Arguments& args); private: /** @@ -212,7 +213,7 @@ class GitBlob : public ObjectWrap { GitRepo* repo; GitOid* oid; int err; - v8::Persistent callback; + Persistent callback; }; }; From 6e4f28d20881de4084ad25443e75ae1398ffe821 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:48:00 +1300 Subject: [PATCH 019/186] Removed applyProperties from utilities.js --- lib/utilities.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/utilities.js b/lib/utilities.js index c731c6ad9..779c039a9 100755 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -1,25 +1 @@ var git = require('../'); - -/** - * Apply given details to the context. - * - * @param {Object} details - * @param {Object} context - * @return {Object} The modified context. - */ -exports.applyProperties = function(details, context) { - if (details) { - for (var detailKey in details) { - if (detailKey === 'id' && details[detailKey] instanceof git.raw.Oid) { - context[detailKey] = git.oid(details[detailKey]); - continue; - } - if (detailKey === 'object' && details[detailKey] instanceof git.raw.Object) { - context[detailKey] = git.object(details[detailKey]); - continue; - } - context[detailKey] = details[detailKey]; - } - } - return context; -}; From b6ab81dc100755ddd63cad0a752c48188575cbd7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:48:23 +1300 Subject: [PATCH 020/186] Added success to utilities.js to handle if (error) then wrap it and call callback --- lib/utilities.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/utilities.js b/lib/utilities.js index 779c039a9..f2bbeeb6a 100755 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -1 +1,21 @@ var git = require('../'); + +/** + * Check if error is null, if it is not, convert it to a GitError and call + * the callback. + * + * @param {Object} error + * @param {Function} callback + * @return {Boolean} True if the error was null, false otherwise. + */ +exports.success = function(error, callback) { + if (error) { + if (error instanceof git.error) { + callback(error); + } else { + callback(git.error(error)); + } + return false; + } + return true; +}; From 2e97ebf691562034ae896df6ed516d6d16ed1fc1 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:49:04 +1300 Subject: [PATCH 021/186] Ignore testing js --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1f63036f9..e0cc348f1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ /doc !doc/Theme.css /node_modules - +/testing.js From 3947245612ae27077517038704b7a679e742658e Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:50:49 +1300 Subject: [PATCH 022/186] Added C++ utilities --- include/functions/utilities.h | 15 +++++++++++++++ src/functions/utilities.cc | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 include/functions/utilities.h create mode 100644 src/functions/utilities.cc diff --git a/include/functions/utilities.h b/include/functions/utilities.h new file mode 100644 index 000000000..4d71f4911 --- /dev/null +++ b/include/functions/utilities.h @@ -0,0 +1,15 @@ +#ifndef UTILITY_FUNCTIONS +#define UTILITY_FUNCTIONS + +#include +#include + +#include "../../vendor/libgit2/include/git2.h" + +#include "../../include/error.h" + +using namespace v8; + +bool success(const git_error* error, Persistent callback); + +#endif diff --git a/src/functions/utilities.cc b/src/functions/utilities.cc new file mode 100644 index 000000000..ec5904dcc --- /dev/null +++ b/src/functions/utilities.cc @@ -0,0 +1,21 @@ +#include "../../include/functions/utilities.h" + +using namespace v8; + +bool success(const git_error* error, Persistent callback) { + HandleScope scope; + + if (error) { + Local argv[1] = { + GitError::WrapError(error) + }; + + TryCatch try_catch; + callback->Call(Context::GetCurrent()->Global(), 1, argv); + if (try_catch.HasCaught()) { + FatalException(try_catch); + } + return false; + } + return true; +} From 846aa49cf65efe1c8000e50ae32be63908c92d43 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:51:15 +1300 Subject: [PATCH 023/186] Rewrite Repo js convenience wrapper. --- lib/repo.js | 150 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 87 insertions(+), 63 deletions(-) diff --git a/lib/repo.js b/lib/repo.js index b6541b427..ddd63653b 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -1,79 +1,103 @@ var git = require('../'), - fs = require('fs'); + success = require('./utilities').success; -/* Module: Repo - * Work with a repository. - */ -exports.repo = function(directory, callback) { - var self = { - // Assign a new repo object - repo: new git.raw.Repo() - }; +var Repo = function() { + this.rawRepo = new git.raw.Repo(); +}; - if (directory) { - if (!callback || typeof callback !== 'function') { - throw new Error('If directory is provided, callback function is required'); - } - self.repo.open(directory, function(error, rawRepo) { - if (error) { - callback(git.error(error), null); - return; - } - self.repo = rawRepo; +/** + * Open the git repository at directory. + * + * @param {String} directory + * @param {Function} callback + */ +Repo.prototype.open = function(directory, callback) { + var self = this; + self.rawRepo.open(directory, function(error, rawRepo) { + if (success(error, callback)) { + self.rawRepo = rawRepo; callback(null, self); - }); - } + } + }); +}; - /** - * Look up a branch and find its tree. - * - * @param {String} name Branch name, e.g. 'master' - * @param {Function} - */ - self.branch = function(name, callback) { - git.reference(self.repo).lookup('refs/heads/' + name, function referenceLookupCallback(error, reference) { - if (error) { - callback(git.error(error), null); +/** + * Look up a branch's most recent commit. + * + * @param {String} name Branch name, e.g. 'master' + * @param {Function} callback + */ +Repo.prototype.branch = function(name, callback) { + var self = this; + (new git.reference(self.rawRepo)).lookup('refs/heads/' + name, function referenceLookupCallback(error, reference) { + if (!success(error, callback)) { + return; + } + reference.oid(function oidCallback(error, oid) { + if (!success(error, callback)) { return; } - reference.oid(function oidCallback(error, oid) { - if (error) { - callback(git.error(error), null); + self.commit(oid, function commitLookupCallback(error, commit) { + if (!success(error, callback)) { return; } - self.commit(oid, function commitLookupCallback(error, commit) { - if (error) { - callback(git.error(error), null); - return; - } - callback(null, commit); - }); + callback(null, commit); }); }); - }; - - // Find a single commit - self.commit = function(oid, callback) { - git.commit().lookup(self.repo, oid, function(error, commit) { - callback(error, commit); - }); - }; + }); +}; - self.commitSync = function(sha) { - throw new Error('commitSync not yet implemented'); - // return git.commit().lookupSync(sha); - }; +/** + * Retrieve the commit identified buy oid. + * @param {String|git.oid|git.raw.Oid} oid + * @param {Function} callback + */ +Repo.prototype.commit = function(sha, callback) { + (new git.commit(this.rawRepo)).lookup(sha, function(error, commit) { + if (success(error, callback)) { + callback(null, commit); + } + }); +}; - self.init = function(directory, isBare, callback) { - self.repo.init(directory, isBare, function(error) { - callback.call(this, error, self); - }); - }; +/** + * Initialise a git repository at directory. + * + * @param {String} directory + * @param {Boolean} isBare True if the repository is to be bare, false otherwise. + * @param {Function} callback + */ +Repo.prototype.init = function(directory, isBare, callback) { + var self = this; + self.repo.init(directory, isBare, function(error, rawRepo) { + if (success(error, callback)) { + self.rawRepo = rawRepo; + callback(null, self); + } + }); +}; - self.free = function() { - self.repo.free(); - delete self.repo; - }; +/** + * @todo necessary? + */ +Repo.prototype.free = function() { + this.rawRepo.free(); + delete self.repo; +}; - return self; +/** + * Create a new Repo object. If directory is not provided, simply return it. + * Otherwise open the repo asynchronously. + * + * @param {String|null} directory The directory for the git repo to open. Null + * if one does not want to open a repo. + * @param {Function|null} callback + * @return {Repo|null} The Repo if no directory is provided, else undefined. + */ +exports.repo = function(directory, callback) { + var repo = new Repo(); + if (typeof directory === 'undefined') { + return repo; + } + repo.open(directory, callback); }; From af43a5185877e4f9c56bc8700e299dddc5bf423c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:51:28 +1300 Subject: [PATCH 024/186] Rewrite Oid js convenience wrapper. --- lib/oid.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/oid.js b/lib/oid.js index 972933392..b5da0fb42 100644 --- a/lib/oid.js +++ b/lib/oid.js @@ -1,19 +1,19 @@ var git = require( '../' ); +/** + * @param {git.raw.Oid|null} rawOid + */ var Oid = function(rawOid) { - var self = {}; - if(rawOid instanceof git.raw.Oid) { - self.oid = rawOid; - } else { - self.oid = new git.raw.Oid(); + this.rawOid = rawOid; } +}; - self.getRawOid = function() { - return self.oid; - }; - - return self; +/** + * @return {git.raw.Oid} + */ +Oid.prototype.getRawoid = function() { + return this.rawOid; }; exports.oid = Oid; From fec1d3e70bba7efd640e405aa65e2cd53f1e29f7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:51:44 +1300 Subject: [PATCH 025/186] Rewrite TreeEntry js convenience wrapper. --- lib/tree_entry.js | 200 ++++++++++++++++++++++++++++------------------ 1 file changed, 122 insertions(+), 78 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 22dfdeeb8..02c3b9558 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -1,100 +1,144 @@ -var git = require( '../' ); +var git = require('../'), + success = require('./utilities').success; -var _TreeEntry = function(rawObject) { - var self = {}; +var DIRECTORY = 33188; +var FILE = 16384; - if(rawObject instanceof git.raw.TreeEntry) { - self.entry = rawObject; - } else { - self.entry = new git.raw.TreeEntry(); - self.repo = rawObject; +var TreeEntry = function(rawRepo, rawTreeEntry) { + if(!(rawRepo instanceof git.raw.Repo)) { + throw git.error('First parameter for Tree Entry must be a raw repo', 0); } - self.dir = ''; + if(!(rawTreeEntry instanceof git.raw.TreeEntry)) { + throw git.error('Second parameter for Tree Entry must be a raw tree entry', 0); + } - Object.defineProperty( self, 'name', { - get: function() { - return self.dir + self.entry.name(); - }, - enumerable: true - }); + this.rawRepo = rawRepo; + this.rawEntry = rawTreeEntry; +}; - Object.defineProperty( self, 'attributes', { - get: function() { - return self.entry.attributes(); - }, - enumerable: true +/** + * Retrieve the Oid for this TreeEntry. + * + * @param {Function} callback + */ +TreeEntry.prototype.oid = function(callback) { + this.rawEntry.oid(function(error, rawOid) { + if (success(error, callback)) { + callback(null, git.oid(rawOid)); + } }); +}; - Object.defineProperty( self, 'object', { - get: function() { - return self.entry.toObject(); - }, - enumerable: true +/** + * Retrieve the SHA for this TreeEntry. + * + * @param {Function} callback + */ +TreeEntry.prototype.sha = function(callback) { + this.rawEntry.sha(function(error, sha) { + if (success(error, callback)) { + callback(null, sha); + } }); +}; - Object.defineProperty( self, 'id', { - get: function() { - var oid = git.oid(); - self.entry.id( oid.oid ); - - return oid; - }, - enumerable: true +/** + * Determine whether this TreeEntry is a file. + * + * @param {Function} callback + */ +TreeEntry.prototype.isFile = function(callback) { + var self = this; + if (typeof self._cache.fileMode !== 'undefined') { + callback(null, self._cache.fileMode === FILE); + return; + } + self.rawEntry.fileMode(function(error, fileMode) { + if (success(error, callback)) { + self._cache.fileMode = fileMode; + callback(null, self._cache.fileMode === FILE); + } }); +}; - Object.defineProperty( self, 'sha', { - get: function() { - var oid = self.id; - - return oid.oid.toString( 40 ); - }, - enumerable: true +/** + * Determine whether this Tree Entry is a directory. + * + * @param {Function} callback + */ +TreeEntry.prototype.isDirectory = function(callback) { + var self = this; + if (typeof self._cache.fileMode !== 'undefined') { + callback(null, self._cache.fileMode === DIRECTORY); + return; + } + self.rawEntry.fileMode(function(error, fileMode) { + if (success(error, callback)) { + self._cache.fileMode = fileMode; + callback(null, self._cache.fileMode === DIRECTORY); + } }); +}; - Object.defineProperty( self, 'content', { - get: function() { - if( self.isFile() ) { - var blob = git.blob( self.repo ); - - self.entry.toObject( self.repo, blob.blob ); - - return blob.raw; - } - - return null; - }, - enumerable: true +/** + * Retrieve the name for this TreeEntry. + * + * @param {Function} callback + */ +TreeEntry.prototype.name = function(callback) { + this.rawEntry.name(function(error, name) { + if (success(error, callback)) { + callback(null, name); + } }); +}; - self.isFile = function() { - return self.attributes !== 16384; - }; - - self.isDir = function() { - return self.attributes === 16384; - }; +/** + * Retrieve the TreeEntry's content. + * + * @param {Function} callback + */ +TreeEntry.prototype.content = function(callback) { + this.toBlob(function convertBlob(error, blob) { + if (success(error, callback)) { + callback(null, blob.raw); + } + }); +}; - self.fetchDetails = function(callback) { - console.log('tree fetch details'); - callback(null, self); - }; +/** + * Convert the TreeEntry to a blob. + * + * @param {Function} callback + */ +TreeEntry.prototype.toBlob = function(callback) { + this.rawEntry.toBlob(this.rawRepo, function blobCallback(error, rawBlob) { + if (success(error, callback)) { + callback(null, git.blob(rawBlob)); + return; + } + }); +}; - self.tree = function() { - var tree = new git.raw.Tree( self.repo ); - if( tree.error ) { - return git.error( tree.error ); +/** + * Retrieve the TreeEntry's Tree. + * + * @param {Function} callback + */ +TreeEntry.prototype.tree = function(callback) { + var self = this; + self.oid(function treeEntryOid(error, oid) { + if (!success(error, callback)) { + return; } - else { - if( tree.lookup(self.repo, self.id.oid) ) { - return git.error( tree.error ); + (new git.raw.Tree(self.rawRepo)).lookup(oid.getRawOid(), function(error, tree) { + if (!success(error, callback)) { + return; } - } - - return git.tree( tree ); - }; - - return self; + callback(null, tree); + }); + }); }; -exports.entry = _TreeEntry; +exports.entry = TreeEntry; From 1c71929a905da9faab64472d53815d46ff4391dd Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:51:57 +1300 Subject: [PATCH 026/186] Removed commit functions --- include/functions/commit.h | 29 ----------------------- src/functions/commit.cc | 47 -------------------------------------- 2 files changed, 76 deletions(-) delete mode 100644 include/functions/commit.h delete mode 100644 src/functions/commit.cc diff --git a/include/functions/commit.h b/include/functions/commit.h deleted file mode 100644 index 2813694e6..000000000 --- a/include/functions/commit.h +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include -#include - -#include "cvv8/v8-convert.hpp" - -#include "../../vendor/libgit2/include/git2.h" - -#include "../../include/functions/string.h" - -#ifndef COMMIT_FUNCTIONS -#define COMMIT_FUNCTIONS - -struct GitCommitDetails { - const git_oid *oid; - char sha[GIT_OID_HEXSZ + 1]; - const char* message; - time_t time; - int timeOffset; - const git_signature* committer; - const git_signature* author; - unsigned int parentCount; - std::vector parentShas; -}; - -v8::Local createCommitDetailsObject(GitCommitDetails* rawDetails); - -#endif diff --git a/src/functions/commit.cc b/src/functions/commit.cc deleted file mode 100644 index 30dff25ae..000000000 --- a/src/functions/commit.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include "../../include/oid.h" -#include "../../include/functions/commit.h" - -/** - * Non blocking, Converts GitCommitDetails struct into a v8::Local for JavaScript - */ -v8::Local createCommitDetailsObject(GitCommitDetails* rawDetails) { - - v8::Local details = v8::Object::New(); - - v8::Handle oid = GitOid::constructor_template->NewInstance(); - GitOid *oidInstance = node::ObjectWrap::Unwrap(oid); - oidInstance->SetValue(*const_cast(rawDetails->oid)); - - details->Set(String::NewSymbol("id"), oid); - details->Set(String::NewSymbol("sha"), String::New(rawDetails->sha)); - details->Set(String::NewSymbol("message"), cvv8::CastToJS(rawDetails->message)); - details->Set(String::NewSymbol("time"), cvv8::CastToJS(rawDetails->time)); - details->Set(String::NewSymbol("timeOffset"), cvv8::CastToJS(rawDetails->timeOffset)); - - v8::Local committer = v8::Object::New(); - committer->Set(String::NewSymbol("name"), cvv8::CastToJS(rawDetails->committer->name)); - committer->Set(String::NewSymbol("email"), cvv8::CastToJS(rawDetails->committer->email)); - - v8::Local committerWhen = v8::Object::New(); - committerWhen->Set(String::NewSymbol("time"), cvv8::CastToJS(rawDetails->committer->when.time)); - committerWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(rawDetails->committer->when.offset)); - committer->Set(String::NewSymbol("when"), cvv8::CastToJS(committerWhen)); - - details->Set(String::NewSymbol("committer"), committer); - - v8::Local author = v8::Object::New(); - author->Set(String::NewSymbol("name"), cvv8::CastToJS(rawDetails->author->name)); - author->Set(String::NewSymbol("email"), cvv8::CastToJS(rawDetails->author->email)); - - v8::Local authorWhen = v8::Object::New(); - authorWhen->Set(String::NewSymbol("time"), cvv8::CastToJS(rawDetails->author->when.time)); - authorWhen->Set(String::NewSymbol("offset"), cvv8::CastToJS(rawDetails->author->when.offset)); - author->Set(String::NewSymbol("when"), authorWhen); - - details->Set(String::NewSymbol("author"), author); - - details->Set(String::NewSymbol("parentCount"), cvv8::CastToJS(rawDetails->parentCount)); - details->Set(String::NewSymbol("parentShas"), cvv8::CastToJS(rawDetails->parentShas)); - - return details; -} From 7342eaad4a2ec0f74dde138311c053d1f18e4320 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:52:17 +1300 Subject: [PATCH 027/186] Added default error type for convenience when throwing from JS --- lib/error.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/error.js b/lib/error.js index 3edd99493..ede0aadaf 100644 --- a/lib/error.js +++ b/lib/error.js @@ -13,7 +13,7 @@ var GitError = function(message, code) { this.name = 'GitError'; this.message = message; - this.code = code; + this.code = code || git.raw.Error.codes.GITERR_INVALID; }; util.inherits(GitError, Error); From 64ae9de96a9cbc562a5d7a93d35bf888fbcfa8f0 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:52:49 +1300 Subject: [PATCH 028/186] Rewrite Commit js convenience wrapper. --- lib/commit.js | 268 +++++++++++++++++++++++--------------------------- 1 file changed, 122 insertions(+), 146 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index f9a2121f4..a5d8876f2 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -1,6 +1,6 @@ var git = require( '../' ), - utilities = require('./utilities'), - events = require( 'events' ); + success = require('./utilities').success, + events = require('events'); /** * Convenience commit constructor. @@ -8,169 +8,145 @@ var git = require( '../' ), * @param {RawCommit|Null} rawCommit * @return {Commit} */ -var Commit = function(rawCommit) { - var self = {}; +var Commit = function(rawRepo, rawCommit) { - if(rawCommit && rawCommit instanceof git.raw.Commit) { - self.commit = rawCommit; - } else { - self.commit = new git.raw.Commit(); + if (!(rawRepo instanceof git.raw.Repo)) { + throw git.error('First parameter for Commit must be a raw repo'); } - /** - * Fetch the commit's details asynchronously. - * - * @param {Function} callback - */ - self.fetchDetails = function(callback) { - var error = null; - self.commit.fetchDetails(function(error, details) { - if (error) { - error = git.error(error); - } - utilities.applyProperties(details, self); - callback(error); - }); - }; + this.rawRepo = rawRepo; - /** - * Fetch the commit's details synchronously. - */ - self.fetchDetailsSync = function(callback) { - var details = self.commit.fetchDetailsSync(); - return utilities.applyProperties(details, self); - }; + if (rawCommit instanceof git.raw.Commit) { + this.rawCommit = rawCommit; + } else { + this.rawCommit = new git.raw.Commit(); + } +}; - /** - * Look up the commit referenced by oid, replace self.commit - * with the result. - * - * @param {Repo} repo - * @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(); +/** + * Look up the commit referenced by oid, replace this.commit with the result. + * + * @param {git.oid|git.raw.Oid|String} oid + * @param {Function} callback + */ +Commit.prototype.lookup = function(oid, callback) { + if (typeof oid !== 'string' && !(oid instanceof git.raw.Oid)) { + oid = oid.getRawOid(); + } + var self = this; + self.rawCommit.lookup(self.rawRepo, oid, function commitLookup(error, rawCommit) { + if (success(error, callback)) { + self.rawCommit = rawCommit; + callback(null, self); } - self.commit.lookup(repo, oid, function(error, commit) { - if (error) { - callback(git.error(error), null); - return; - } - self.commit = commit; - self.fetchDetails(function(error) { - if (error) { - callback(git.error(error), null); - return; - } - callback(null, self); - }); - }); - }; + }); +}; - self.tree = function() { - var tree = new git.raw.Tree(self.repo); - if(tree.error) { - return git.error(tree.error); - } else { - self.commit.tree(tree); +/** + * Retrieve the tree for this commit. + * + * @param {Function} callback + */ +Commit.prototype.tree = function(callback) { + var self = this; + self.rawCommit.tree(function commitTree(error, rawTree) { + if (success(error, callback)) { + callback(null, new git.tree(self.rawRepo, rawTree)); } - return git.tree(self.repo, tree); - }; - - self.file = function(path, callback) { - self.tree().entry(path, callback); - }; - - /** - * Walk the history of this commit. - * - * @return {Event} Event emits 'commit', with error, commit and 'end', with - * error, commits[] - */ - self.history = function() { - var revwalk = git.revwalk(self.repo), - event = new events.EventEmitter(), - commits = []; - - revwalk.walk(self.id, function(error, index, commit, noMoreCommits) { - if(error) { - event.emit('end', error, commits); - return false; - } + }); +}; - if (noMoreCommits) { - event.emit('end', null, commits); - return; +/** + * Retrieve the file represented by path for this commit. + * + * @param {String} path + * @param {Function} callback + */ +Commit.prototype.file = function(path, callback) { + this.tree(function commitFile(error, tree) { + if (!success(error, callback)) { + return; + } + tree.entry(path, function(error, entry) { + if (success(error, callback)) { + callback(null, entry); } - event.emit('commit', null, commit); - commits.push(commit); }); + }); +}; - return event; - }; +/** + * Walk the history of this commit. + * + * @return {Event} Event emits 'commit', with error, commit and 'end', with + * error, commits[] + */ +Commit.prototype.history = function() { + var revwalk = git.revwalk(self.repo), + event = new events.EventEmitter(), + commits = []; + + revwalk.walk(self.id, function(error, index, commit, noMoreCommits) { + if(error) { + event.emit('end', error, commits); + return false; + } - /** - * Retrieve the commit's parent at the given position asynchronously. - * - * @param {Integer} position - */ - self.parent = function(position, callback) { - var parent = null; - self.commit.parent(position, function processParent(errorCode, parent) { - var error = null; - if (errorCode) { - error = git.error(errorCode); - return callback(error, null); - } - var parentCommit = new Commit(parent); - parentCommit.fetchDetails(function returnParent(error) { - callback(error, parentCommit); - }); - }); - }; + if (noMoreCommits) { + event.emit('end', null, commits); + return; + } + event.emit('commit', null, commit); + commits.push(commit); + }); - /** - * Retrieve the commit's parent at the given positino synchronously. - * - * @param {Integer} position - * @return {Commit} - */ - self.parentSync = function(position) { - var parent = new Commit(self.commit.parentSync(position)); - return parent.fetchDetailsSync(); - }; + return event; +}; + +/** + * Retrieve the commit's parent at the given position asynchronously. + * + * @param {Integer} position + */ +Commit.prototype.parent = function(position, callback) { + self.rawCommit.parent(position, function processParent(error, rawParent) { + if (success(error, callback)) { + callback(null, new Commit(this.rawRepo, rawParent)); + } + }); +}; - /** - * Get a diff tree showing changes between this commit and its parent(s). - * Assumes commit has been populated with fetchDetails|fetchDetailsSync - * - * @param {Function} callback Called with error (null if no error) and the - * diff tree - */ - self.parentsDiffTrees = function(callback) { - if (!self.parentCount) { - callback(null, []); +/** + * Get a diff tree showing changes between this commit and its parent(s). + * + * @param {Function} callback + */ +Commit.prototype.parentsDiffTrees = function(callback) { + var self = this; + self.sha(function(error, commitSha) { + if (!success(error, callback)) { return; } - var parentDiffLists = []; - self.parentShas.forEach(function eachParentSha(parentSha) { - git.diffList(self.repo).treeToTree(parentSha, self.sha, function walkDiffList(error, diffList) { - if (error) { - callback(error, null); - return; - } - parentDiffLists.push(diffList); - if (parentDiffLists.length === self.parentShas.length) { - callback(null, parentDiffLists); - } + self.parents(function commitParents(error, parents) { + if (!success(error, callback)) { + return; + } + var parentDiffLists = []; + parents.forEach(function commitEachParent(parent) { + parent.sha(function commitParentSha(error, parentSha) { + (new git.diffList(self.repo)).treeToTree(parentSha, commitSha, function walkDiffList(error, diffList) { + if (!success(error, callback)) { + return; + } + parentDiffLists.push(diffList); + if (parentDiffLists.length === parents.length) { + callback(null, parentDiffLists); + } + }); + }); }); }); - }; - - return self; + }); }; exports.commit = Commit; From 62794fd08b4a6f49db0a49e312a878b03247b1c6 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:53:35 +1300 Subject: [PATCH 029/186] Add utilities to gyp binding --- binding.gyp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index 79ace47dc..ab18cbab5 100644 --- a/binding.gyp +++ b/binding.gyp @@ -18,7 +18,8 @@ 'src/diff_list.cc', 'src/threads.cc', 'src/functions/commit.cc', - 'src/functions/string.cc' + 'src/functions/string.cc', + 'src/functions/utilities.cc' ], 'include_dirs': [ From ae9b0502c735a99da30f811e4ac4e7fa29599a50 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:56:06 +1300 Subject: [PATCH 030/186] Updated object Initialize --- include/object.h | 2 +- src/object.cc | 72 +++++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/include/object.h b/include/object.h index d84de5c05..981c2d4c2 100755 --- a/include/object.h +++ b/include/object.h @@ -23,7 +23,7 @@ class GitObject : public ObjectWrap { /** * v8::FunctionTemplate used to create Node.js constructor */ - static Persistent constructor_template; + static Persistent constructor_template; /** * Used to intialize the EventEmitter from Node.js diff --git a/src/object.cc b/src/object.cc index 9a15102ec..88224e3a7 100755 --- a/src/object.cc +++ b/src/object.cc @@ -5,6 +5,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include #include +#include "cvv8/v8-convert.hpp" #include "../vendor/libgit2/include/git2.h" #include "../include/object.h" @@ -14,39 +15,42 @@ Copyright (c) 2011, Tim Branyen @tbranyen using namespace v8; using namespace node; +namespace cvv8 { + template <> + struct NativeToJS : NativeToJS {}; +} + void GitObject::Initialize (Handle target) { - HandleScope scope; + Local tpl = FunctionTemplate::New(New); - Local t = FunctionTemplate::New(New); - - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("Object")); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->SetClassName(String::NewSymbol("Object")); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "id", Id); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "type", Type); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "owner", Owner); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "type2String", Type2String); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "string2Type", String2Type); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "typeIsLoose", TypeIsLoose); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "size", Size); + NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id); + NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type); + NODE_SET_PROTOTYPE_METHOD(tpl, "owner", Owner); + NODE_SET_PROTOTYPE_METHOD(tpl, "type2String", Type2String); + NODE_SET_PROTOTYPE_METHOD(tpl, "string2Type", String2Type); + NODE_SET_PROTOTYPE_METHOD(tpl, "typeIsLoose", TypeIsLoose); + NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); - Local type = Object::New(); + Local types = Object::New(); - type->Set(String::New("ANY"), Integer::New(-2)); - type->Set(String::New("BAD"), Integer::New(-1)); - type->Set(String::New("_EXT1"), Integer::New(0)); - type->Set(String::New("COMMIT"), Integer::New(1)); - type->Set(String::New("TREE"), Integer::New(2)); - type->Set(String::New("BLOB"), Integer::New(3)); - type->Set(String::New("TAG"), Integer::New(4)); - type->Set(String::New("_EXT2"), Integer::New(5)); - type->Set(String::New("OFS_DELTA"), Integer::New(6)); - type->Set(String::New("REF_DELTA"), Integer::New(7)); + types->Set(String::New("GIT_OBJ_ANY"), cvv8::CastToJS(GIT_OBJ_ANY)); + types->Set(String::New("GIT_OBJ_BAD"), cvv8::CastToJS(GIT_OBJ_BAD)); + types->Set(String::New("GIT_OBJ__EXT1"), cvv8::CastToJS(GIT_OBJ__EXT1)); + types->Set(String::New("GIT_OBJ_COMMIT"), cvv8::CastToJS(GIT_OBJ_COMMIT)); + types->Set(String::New("GIT_OBJ_TREE"), cvv8::CastToJS(GIT_OBJ_TREE)); + types->Set(String::New("GIT_OBJ_BLOB"), cvv8::CastToJS(GIT_OBJ_BLOB)); + types->Set(String::New("GIT_OBJ_TAG"), cvv8::CastToJS(GIT_OBJ_TAG)); + types->Set(String::New("GIT_OBJ__EXT2"), cvv8::CastToJS(GIT_OBJ__EXT2)); + types->Set(String::New("GIT_OBJ_OFS_DELTA"), cvv8::CastToJS(GIT_OBJ_OFS_DELTA)); + types->Set(String::New("GIT_OBJ_REF_DELTA"), cvv8::CastToJS(GIT_OBJ_REF_DELTA)); - constructor_template->Set(String::New("type"), type); + tpl->Set(String::New("types"), types); - target->Set(String::NewSymbol("Object"), constructor_template->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Object"), constructor_template); } git_object* GitObject::GetValue() { @@ -99,7 +103,7 @@ Handle GitObject::Id(const Arguments& args) { HandleScope scope; GitObject *obj = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Oid is required and must be an Object."))); } @@ -115,7 +119,7 @@ Handle GitObject::Type(const Arguments& args) { HandleScope scope; GitObject *obj = ObjectWrap::Unwrap(args.This()); - + return scope.Close( Integer::New(obj->Type()) ); } @@ -123,7 +127,7 @@ Handle GitObject::Owner(const Arguments& args) { HandleScope scope; GitObject *obj = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); } @@ -139,7 +143,7 @@ Handle GitObject::Type2String(const Arguments& args) { HandleScope scope; GitObject *obj = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsNumber()) { return ThrowException(Exception::Error(String::New("Type is required and must be a Number."))); } @@ -153,7 +157,7 @@ Handle GitObject::String2Type(const Arguments& args) { HandleScope scope; GitObject *obj = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsString()) { return ThrowException(Exception::Error(String::New("Type is required and must be a String."))); } @@ -167,7 +171,7 @@ Handle GitObject::TypeIsLoose(const Arguments& args) { HandleScope scope; GitObject *obj = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsNumber()) { return ThrowException(Exception::Error(String::New("Type is required and must be a Number."))); } @@ -181,7 +185,7 @@ Handle GitObject::Size(const Arguments& args) { HandleScope scope; GitObject *obj = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsNumber()) { return ThrowException(Exception::Error(String::New("Type is required and must be a Number."))); } @@ -191,4 +195,4 @@ Handle GitObject::Size(const Arguments& args) { return scope.Close( Integer::New(obj->Size(type)) ); } -Persistent GitObject::constructor_template; +Persistent GitObject::constructor_template; From 80bd9a893d2d560d8295a14674aa89554cf441df Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:57:59 +1300 Subject: [PATCH 031/186] Updated commit parent methods --- include/commit.h | 3 +-- src/commit.cc | 51 ++++++------------------------------------------ 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/include/commit.h b/include/commit.h index bc4e8f4e6..9b5cebb07 100755 --- a/include/commit.h +++ b/include/commit.h @@ -66,7 +66,6 @@ class GitCommit : public ObjectWrap { static void TreeWork(uv_work_t* req); static void TreeAfterWork(uv_work_t* req); - static Handle ParentSync(const Arguments& args); static Handle Parent(const Arguments& args); static void ParentWork(uv_work_t* req); static void ParentAfterWork(uv_work_t* req); @@ -110,7 +109,7 @@ class GitCommit : public ObjectWrap { const git_error* error; int index; - GitCommit* commit; + git_commit* rawCommit; git_commit* rawParentCommit; Persistent callback; diff --git a/src/commit.cc b/src/commit.cc index 043c90646..9effa23b4 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -20,6 +20,8 @@ #include "../include/commit.h" #include "../include/error.h" +#include "../include/functions/utilities.h" + using namespace v8; using namespace cvv8; using namespace node; @@ -37,7 +39,6 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); NODE_SET_PROTOTYPE_METHOD(tpl, "parent", Parent); - NODE_SET_PROTOTYPE_METHOD(tpl, "parentSync", ParentSync); NODE_SET_PROTOTYPE_METHOD(tpl, "fetchDetails", FetchDetails); NODE_SET_PROTOTYPE_METHOD(tpl, "fetchDetailsSync", FetchDetailsSync); @@ -303,29 +304,6 @@ Handle GitCommit::Tree(const Arguments& args) { return scope.Close( Integer::New(err) ); } -Handle GitCommit::ParentSync(const Arguments& args) { - HandleScope scope; - - if(args.Length() == 0 || !args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Position must be a Number."))); - } - - GitCommit *commit = ObjectWrap::Unwrap(args.This()); - - git_commit *parentCommitValue ; - int returnCode = git_commit_parent(&parentCommitValue, commit->commit, args[0]->ToInteger()->Value()); - - if (returnCode != GIT_OK) { - return ThrowException(Exception::Error(String::New(giterr_last()->message))); - } - - Local parent = GitCommit::constructor_template->NewInstance(); - GitCommit *parentCommit = ObjectWrap::Unwrap(parent); - parentCommit->SetValue(parentCommitValue); - - return scope.Close(parent); -} - Handle GitCommit::Parent(const Arguments& args) { HandleScope scope; @@ -343,9 +321,9 @@ Handle GitCommit::Parent(const Arguments& args) { ParentBaton* baton = new ParentBaton(); baton->request.data = baton; - baton->commit = ObjectWrap::Unwrap(args.This()); - baton->commit->Ref(); + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); baton->error = NULL; + baton->rawParentCommit = NULL; baton->index = args[0]->ToInteger()->Value(); baton->callback = Persistent::New(Local::Cast(args[1])); @@ -353,36 +331,20 @@ Handle GitCommit::Parent(const Arguments& args) { return Undefined(); } - void GitCommit::ParentWork(uv_work_t* req) { ParentBaton* baton = static_cast(req->data); - baton->rawParentCommit = NULL; - int returnCode = git_commit_parent(&baton->rawParentCommit, baton->commit->commit, baton->index); + int returnCode = git_commit_parent(&baton->rawParentCommit, baton->rawCommit, baton->index); if (returnCode != GIT_OK) { baton->error = giterr_last(); } } - void GitCommit::ParentAfterWork(uv_work_t* req) { HandleScope scope; ParentBaton* 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 { - + if (success(baton->error, baton->callback)) { Local parent = GitCommit::constructor_template->NewInstance(); GitCommit *parentInstance = ObjectWrap::Unwrap(parent); parentInstance->SetValue(baton->rawParentCommit); @@ -398,7 +360,6 @@ void GitCommit::ParentAfterWork(uv_work_t* req) { node::FatalException(try_catch); } } - baton->commit->Unref(); delete req; } From ea1901888e830616a53ac4940e357745c8238703 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 27 Mar 2013 23:59:29 +1300 Subject: [PATCH 032/186] Made commit's tree method async --- include/commit.h | 13 ++++++++++-- src/commit.cc | 55 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/include/commit.h b/include/commit.h index 9b5cebb07..e6e00c108 100755 --- a/include/commit.h +++ b/include/commit.h @@ -41,9 +41,8 @@ class GitCommit : public ObjectWrap { git_commit* GetValue(); void SetValue(git_commit* commit); - void Close(); - int Tree(git_tree** tree); + void Close(); protected: GitCommit() {} @@ -86,6 +85,16 @@ class GitCommit : public ObjectWrap { Persistent callback; }; + struct TreeBaton { + uv_work_t request; + const git_error* error; + + git_commit* rawCommit; + git_tree* rawTree; + + Persistent callback; + }; + /** * Struct containing details for a commit. */ diff --git a/src/commit.cc b/src/commit.cc index 9effa23b4..a086b2fc8 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -59,10 +59,6 @@ void GitCommit::Close() { this->commit = NULL; } -int GitCommit::Tree(git_tree** tree) { - return git_commit_tree(tree, this->commit); -} - Handle GitCommit::New(const Arguments& args) { HandleScope scope; @@ -218,7 +214,6 @@ Handle GitCommit::Lookup(const Arguments& args) { return Undefined(); } - void GitCommit::LookupWork(uv_work_t *req) { LookupBaton *baton = static_cast(req->data); @@ -237,7 +232,6 @@ void GitCommit::LookupWork(uv_work_t *req) { baton->error = giterr_last(); } } - void GitCommit::LookupAfterWork(uv_work_t *req) { HandleScope scope; LookupBaton *baton = static_cast(req->data); @@ -283,25 +277,52 @@ Handle GitCommit::Close(const Arguments& args) { return scope.Close(Undefined()); } -/** - * @todo asynchronize - */ Handle GitCommit::Tree(const Arguments& args) { HandleScope scope; - GitCommit *commit = ObjectWrap::Unwrap(args.This()); + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Tree is required and must be an Object."))); + TreeBaton* baton = new TreeBaton; + baton->request.data = baton; + baton->error = NULL; + baton->rawTree = NULL; + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, TreeWork, (uv_after_work_cb)TreeAfterWork); + + return Undefined(); +} +void GitCommit::TreeWork(uv_work_t* req) { + TreeBaton* baton = static_cast(req->data); + int returnCode = git_commit_tree(&baton->rawTree, baton->rawCommit); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); } +} +void GitCommit::TreeAfterWork(uv_work_t* req) { + HandleScope scope; + TreeBaton* baton = static_cast(req->data); - GitTree* g_tree = ObjectWrap::Unwrap(args[0]->ToObject()); + if (success(baton->error, baton->callback)) { + Local tree = GitTree::constructor_template->NewInstance(); + GitTree *treeInstance = ObjectWrap::Unwrap(tree); + treeInstance->SetValue(baton->rawTree); - git_tree* tree; - int err = commit->Tree(&tree); - g_tree->SetValue(tree); + Handle argv[2] = { + Local::New(Null()), + tree + }; - return scope.Close( Integer::New(err) ); + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } + delete req; } Handle GitCommit::Parent(const Arguments& args) { From 4051efcb0481881bc73b38f7e9e788cf645e1094 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 00:00:50 +1300 Subject: [PATCH 033/186] Added toBlob to tree_entry --- include/tree_entry.h | 15 ++++++++++ src/tree_entry.cc | 67 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/include/tree_entry.h b/include/tree_entry.h index aa6f8a0db..0449f9f7c 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -43,8 +43,23 @@ class GitTreeEntry : ObjectWrap { protected: static Handle New(const Arguments& args); + static Handle ToBlob(const Arguments& args); + static void ToBlobWork(uv_work_t *req); + static void ToBlobAfterWork(uv_work_t *req); + private: git_tree_entry* entry; + + struct ToBlobBaton { + uv_work_t request; + const git_error* error; + + git_repository* rawRepo; + git_tree_entry* rawEntry; + git_blob* rawBlob; + + Persistent callback; + }; }; #endif diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 5dc4e60e4..c757cb073 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -13,6 +13,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "../include/object.h" #include "../include/oid.h" #include "../include/tree_entry.h" +#include "../include/error.h" using namespace v8; using namespace node; @@ -23,6 +24,8 @@ void GitTreeEntry::Initialize(Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("TreeEntry")); + NODE_SET_PROTOTYPE_METHOD(tpl, "toBlob", ToBlob); + constructor_template = Persistent::New(tpl->GetFunction()); target->Set(String::NewSymbol("TreeEntry"), constructor_template); } @@ -45,6 +48,70 @@ Handle GitTreeEntry::New(const Arguments& args) { return scope.Close(args.This()); } +Handle GitTreeEntry::ToBlob(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsObject()) { + return ThrowException(Exception::Error(String::New("Repository is required and must be an Object."))); + } + + if(args.Length() == 1 || !args[1]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + ToBlobBaton* baton = new ToBlobBaton(); + baton->request.data = baton; + baton->error = NULL; + baton->rawRepo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->rawEntry = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->rawBlob = NULL; + baton->callback = Persistent::New(Local::Cast(args[1])); + + uv_queue_work(uv_default_loop(), &baton->request, ToBlobWork, (uv_after_work_cb)ToBlobAfterWork); + + return Undefined(); +} +void GitTreeEntry::ToBlobWork(uv_work_t *req) { + ToBlobBaton* baton = static_cast(req->data); + + int returnCode = git_tree_entry_to_object((git_object**)&baton->rawBlob, baton->rawRepo, baton->rawEntry); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + } +} +void GitTreeEntry::ToBlobAfterWork(uv_work_t *req) { + HandleScope scope; + ToBlobBaton* 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 blob = GitBlob::constructor_template->NewInstance(); + GitBlob *blobInstance = ObjectWrap::Unwrap(blob); + blobInstance->SetValue(baton->rawBlob); + + Handle argv[2] = { + Local::New(Null()), + blob + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } + delete req; +} Persistent GitTreeEntry::constructor_template; From f62a6f1e0adfe9f4c31d9321e0376feb8cc4780b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 00:01:52 +1300 Subject: [PATCH 034/186] Use success instead of manual error handling --- src/tree_entry.cc | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/tree_entry.cc b/src/tree_entry.cc index c757cb073..a6bd16ef4 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -83,18 +83,7 @@ void GitTreeEntry::ToBlobAfterWork(uv_work_t *req) { HandleScope scope; ToBlobBaton* 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 { - + if (success(baton->error, baton->callback)) { Handle blob = GitBlob::constructor_template->NewInstance(); GitBlob *blobInstance = ObjectWrap::Unwrap(blob); blobInstance->SetValue(baton->rawBlob); From c92e983a4bd1f891b289a2427a0a5694922f505d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 00:02:12 +1300 Subject: [PATCH 035/186] Use success instead of manual error handling --- src/tree.cc | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/tree.cc b/src/tree.cc index 75dd434cc..7cc6fc361 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -14,6 +14,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen #include "../include/error.h" #include "../include/functions/string.h" +#include "../include/functions/utilities.h" using namespace v8; using namespace node; @@ -193,7 +194,6 @@ void GitTree::EIO_EntryByIndex(uv_work_t *req) { entryindex_request *er = static_cast(req->data); er->entry->SetValue(er->tree->EntryByIndex(er->idx)); - } void GitTree::EIO_AfterEntryByIndex(uv_work_t *req) { @@ -242,7 +242,6 @@ Handle GitTree::EntryByPath(const Arguments& args) { return Undefined(); } - void GitTree::EntryByPathWork(uv_work_t *req) { EntryByPathBaton *baton = static_cast(req->data); @@ -251,25 +250,11 @@ void GitTree::EntryByPathWork(uv_work_t *req) { baton->error = giterr_last(); } } - void GitTree::EntryByPathAfterWork(uv_work_t *req) { HandleScope scope; EntryByPathBaton *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 { - + if (success(baton->error, baton->callback)) { Local entry = GitTreeEntry::constructor_template->NewInstance(); GitTreeEntry *entryInstance = ObjectWrap::Unwrap(entry); entryInstance->SetValue(baton->rawEntry); From c8129dbcdc83ca776a0d3801d002f16302198e99 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:31:22 +1300 Subject: [PATCH 036/186] Removed sync accessors from blob --- include/blob.h | 16 ---------------- src/blob.cc | 15 --------------- 2 files changed, 31 deletions(-) diff --git a/include/blob.h b/include/blob.h index a9d44fb3b..0dd731ff3 100755 --- a/include/blob.h +++ b/include/blob.h @@ -59,22 +59,6 @@ class GitBlob : public ObjectWrap { * 0 on success; error code otherwise */ int Lookup(git_repository* repo, const git_oid *id); - /** - * Function: RawContent - * Get a read-only buffer with the raw content of a blob. - * - * Returns: - * raw content buffer; NULL if the blob has no contents - */ - const void* RawContent(); - /** - * Function: RawSize - * Lookup a blob object from a repository. - * - * Returns: - * size in bytes - */ - int RawSize(); /** * * Function: Close diff --git a/src/blob.cc b/src/blob.cc index 22d966ebf..b37cad03e 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -27,7 +27,6 @@ void GitBlob::Initialize (Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); NODE_SET_PROTOTYPE_METHOD(tpl, "rawContent", RawContent); - NODE_SET_PROTOTYPE_METHOD(tpl, "rawSize", RawSize); NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); NODE_SET_PROTOTYPE_METHOD(tpl, "createFromFile", CreateFromFile); NODE_SET_PROTOTYPE_METHOD(tpl, "createFromBuffer", CreateFromBuffer); @@ -39,23 +38,10 @@ void GitBlob::Initialize (Handle target) { git_blob* GitBlob::GetValue() { return this->blob; } - void GitBlob::SetValue(git_blob* blob) { this->blob = blob; } -int GitBlob::Lookup(git_repository* repo, const git_oid* id) { - return git_blob_lookup(&this->blob, repo, id); -} - -const void* GitBlob::RawContent() { - return git_blob_rawcontent(this->blob); -} - -int GitBlob::RawSize() { - return git_blob_rawsize(this->blob); -} - void GitBlob::Close() { git_blob_free(this->blob); } @@ -63,7 +49,6 @@ void GitBlob::Close() { int CreateFromFile(git_oid* oid, git_repository* repo, const char* path) { return git_blob_create_fromdisk(oid, repo, path); } - int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len) { return git_blob_create_frombuffer(oid, repo, buffer, len); } From eaf5d889705aa8a3be5f0594b80bcd12eb072d87 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:33:52 +1300 Subject: [PATCH 037/186] Refactored blob lookup --- include/blob.h | 30 ++++++++++----------- src/blob.cc | 73 +++++++++++++++++++++++--------------------------- 2 files changed, 48 insertions(+), 55 deletions(-) diff --git a/include/blob.h b/include/blob.h index 0dd731ff3..3f85a6a9e 100755 --- a/include/blob.h +++ b/include/blob.h @@ -8,13 +8,14 @@ #include #include +#include #include "../vendor/libgit2/include/git2.h" #include "repo.h" -using namespace node; using namespace v8; +using namespace node; /** * Class: GitBlob @@ -114,20 +115,21 @@ class GitBlob : public ObjectWrap { */ static Handle Lookup(const Arguments& args); /** - * Function: EIO_Lookup + * Function: LookupWork * * Parameters: * req - an uv_work_t pointer * */ - static void EIO_Lookup(uv_work_t* req); + static void LookupWork(uv_work_t* req); /** - * Function: EIO_AfterLookup + * Function: LookupAfterWork * * Parameters: * req - an uv_work_t pointer */ - static void EIO_AfterLookup(uv_work_t* req); + static void LookupAfterWork(uv_work_t* req); + /** * Function: RawContent * @@ -186,17 +188,15 @@ class GitBlob : public ObjectWrap { */ git_blob* blob; - /** - * Struct: lookup_request - * Contains references to the current blob, repo, and oid for a - * commit lookup, also contains references to an error code post - * lookup, and a callback function to execute. - */ - struct lookup_request { + struct LookupBaton { + uv_work_t request; + const git_error* error; + GitBlob* blob; - GitRepo* repo; - GitOid* oid; - int err; + git_blob* rawBlob; + git_repository* rawRepo; + git_oid rawOid; + Persistent callback; }; }; diff --git a/src/blob.cc b/src/blob.cc index b37cad03e..fbfd8c1c1 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -3,10 +3,7 @@ * Dual licensed under the MIT and GPL licenses. */ -#include -#include #include -#include #include "../vendor/libgit2/include/git2.h" @@ -14,6 +11,8 @@ #include "../include/repo.h" #include "../include/blob.h" +#include "../include/functions/utilities.h" + using namespace v8; using namespace node; @@ -77,51 +76,45 @@ Handle GitBlob::Lookup(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - GitBlob* blob = ObjectWrap::Unwrap(args.This()); - Local callback = Local::Cast(args[2]); - - lookup_request* ar = new lookup_request(); - ar->blob = blob; - ar->repo = ObjectWrap::Unwrap(args[0]->ToObject()); - ar->oid = ObjectWrap::Unwrap(args[1]->ToObject()); - ar->callback = Persistent::New(callback); - - blob->Ref(); + LookupBaton* baton = new LookupBaton; + baton->request.data = baton; + baton->blob = ObjectWrap::Unwrap(args.This()); + baton->blob->Ref(); + baton->rawBlob = baton->blob->GetValue(); + baton->rawRepo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->rawOid = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[2])); - 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); + uv_queue_work(uv_default_loop(), &baton->request, LookupWork, (uv_after_work_cb)LookupAfterWork); - return scope.Close( Undefined() ); + return Undefined(); } - -void GitBlob::EIO_Lookup(uv_work_t* req) { - lookup_request* ar = static_cast(req->data); - - git_oid oid = ar->oid->GetValue(); - ar->err = ar->blob->Lookup(ar->repo->GetValue(), &oid); - +void GitBlob::LookupWork(uv_work_t* req) { + LookupBaton* baton = static_cast(req->data); + int returnCode = git_blob_lookup(&baton->rawBlob, baton->rawRepo, &baton->rawOid); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + } } +void GitBlob::LookupAfterWork(uv_work_t* req) { + HandleScope scope; + LookupBaton* baton = static_cast(req->data); -void GitBlob::EIO_AfterLookup(uv_work_t* req) { - lookup_request* ar = static_cast(req->data); - delete req; - ar->blob->Unref(); - - Local argv[1]; - argv[0] = Integer::New(ar->err); - - TryCatch try_catch; + if (success(baton->error, baton->callback)) { + baton->blob->SetValue(baton->rawBlob); - ar->callback->Call(Context::GetCurrent()->Global(), 1, argv); + Handle argv[2] = { + Local::New(Null()), + baton->blob->handle_ + }; - if(try_catch.HasCaught()) { - FatalException(try_catch); + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } } - - ar->callback.Dispose(); - - delete ar; + delete req; } Handle GitBlob::RawContent(const Arguments& args) { From 138b7558e63084116820dbb0365ebcf8f4f76099 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:34:01 +1300 Subject: [PATCH 038/186] Made rawContent async --- include/blob.h | 14 ++++++++++++++ src/blob.cc | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/include/blob.h b/include/blob.h index 3f85a6a9e..0a9d86b3b 100755 --- a/include/blob.h +++ b/include/blob.h @@ -140,6 +140,9 @@ class GitBlob : public ObjectWrap { * Object args.This() */ static Handle RawContent(const Arguments& args); + static void RawContentWork(uv_work_t* req); + static void RawContentAfterWork(uv_work_t* req); + /** * Function: RawSize * @@ -199,6 +202,17 @@ class GitBlob : public ObjectWrap { Persistent callback; }; + + struct RawContentBaton { + uv_work_t request; + + GitBlob* blob; + git_blob* rawBlob; + std::string rawContent; + int rawSize; + + Persistent callback; + }; }; #endif diff --git a/src/blob.cc b/src/blob.cc index fbfd8c1c1..d795359a7 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -120,26 +120,44 @@ void GitBlob::LookupAfterWork(uv_work_t* req) { Handle GitBlob::RawContent(const Arguments& args) { HandleScope scope; - GitBlob* blob = ObjectWrap::Unwrap(args.This()); - - int rawSize = blob->RawSize(); - std::string contents = (const char *)const_cast(blob->RawContent()); + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } - int bufferLength = rawSize; - Buffer* buffer = Buffer::New(const_cast(contents.c_str()), bufferLength); + RawContentBaton* baton = new RawContentBaton; + baton->request.data = baton; + baton->rawBlob = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); - Local fastBuffer; - MAKE_FAST_BUFFER(buffer, fastBuffer); + uv_queue_work(uv_default_loop(), &baton->request, RawContentWork, (uv_after_work_cb)RawContentAfterWork); - return scope.Close( fastBuffer ); + return Undefined(); } +void GitBlob::RawContentWork(uv_work_t* req) { + RawContentBaton* baton = static_cast(req->data); -Handle GitBlob::RawSize(const Arguments& args) { + baton->rawContent = (const char *)const_cast(git_blob_rawcontent(baton->rawBlob)); + baton->rawSize = git_blob_rawsize(baton->rawBlob); +} +void GitBlob::RawContentAfterWork(uv_work_t* req) { HandleScope scope; + RawContentBaton* baton = static_cast(req->data); - GitBlob* blob = ObjectWrap::Unwrap(args.This()); + Local fastBuffer; + Buffer* buffer = Buffer::New(const_cast(baton->rawContent.c_str()), baton->rawSize); + MAKE_FAST_BUFFER(buffer, fastBuffer); - return scope.Close( Integer::New(blob->RawSize()) ); + Handle argv[2] = { + Local::New(Null()), + fastBuffer + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; } Handle GitBlob::Close(const Arguments& args) { From 545ceeb8fa081b3340a669e20fd892a4543d7c44 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:35:05 +1300 Subject: [PATCH 039/186] Refactored blob.js --- lib/blob.js | 80 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/lib/blob.js b/lib/blob.js index 2808a5e89..a5e8f103e 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -1,33 +1,65 @@ -var git = require( '../' ); +var git = require('../'), + success = require('./utilities').success; -var _Blob = function( obj ) { - var self = {}; - - if( obj instanceof git.raw.Repo ) { - self.repo = obj; - self.blob = new git.raw.Blob( obj ); +/** + * Blob convenience class constructor. + * + * @param {git.raw.Repo} rawRepo + * @param {git.raw.Blob|null} rawBlob + */ +var Blob = function(rawRepo, rawBlob) { + if(!(rawRepo instanceof git.raw.Repo)) { + throw git.error('First parameter for Blob must be a raw repo'); } - else if( obj instanceof git.raw.Blob ) { - self.blob = obj; + this.rawRepo = rawRepo; + + if(rawBlob instanceof git.raw.Blob) { + this.rawBlob = rawBlob; + } else { + this.rawBlob = new git.raw.Blob(this.rawRepo); } +}; - Object.defineProperty( self, 'raw', { - get: function() { - return self.blob.rawContent().toString(); - }, - enumerable: true +/** + * Retrieve the blob represented by the oid. + * + * @param {git.raw.Oid} oid + * @param {Function} callback + */ +Blob.prototype.lookup = function(oid, callback) { + var self = this; + self.rawBlob.lookup(self.rawRepo, oid, function blobLookup(error, rawBlob) { + if (success(error, callback)) { + self.rawBlob = rawBlob; + callback(null, self); + } }); +}; - self.lookup = function( oid ) { - self.blob.lookup( self.repo, oid, function() { - var args = Array.prototype.slice.call( arguments ); - args[0] = git.util().error( args[0] ); - - callback.apply( self, args.concat( self ) ); - }); - }; +/** + * Retrieve the blob's raw content buffer. + * + * @param {Function} callback + */ +Blob.prototype.rawContent = function(callback) { + this.rawBlob.rawContent(function(error, content) { + if (success(error, callback)) { + callback(null, content); + } + }); +}; - return self; +/** + * Retrieve the blob's content. + * + * @param {Function} callback + */ +Blob.prototype.content = function(callback) { + this.rawContent(function(error, content) { + if (success(error, callback)) { + callback(null, content.toString()); + } + }); }; -exports.blob = _Blob; +exports.blob = Blob; From 68110114e00320e0c3d67f5030e409c4b681cf08 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:35:42 +1300 Subject: [PATCH 040/186] Updated tree entry's content method --- lib/tree_entry.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 02c3b9558..cc19a1e45 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -101,9 +101,14 @@ TreeEntry.prototype.name = function(callback) { */ TreeEntry.prototype.content = function(callback) { this.toBlob(function convertBlob(error, blob) { - if (success(error, callback)) { - callback(null, blob.raw); + if (!success(error, callback)) { + return; } + blob.content(function blobContent(error, content) { + if (success(error, callback)) { + callback(null, content); + } + }); }); }; From fc731336be4599bce042a3a2e68a1ad55a8f2632 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:35:50 +1300 Subject: [PATCH 041/186] Updated toBlob --- lib/tree_entry.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index cc19a1e45..62ab8c744 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -118,10 +118,10 @@ TreeEntry.prototype.content = function(callback) { * @param {Function} callback */ TreeEntry.prototype.toBlob = function(callback) { - this.rawEntry.toBlob(this.rawRepo, function blobCallback(error, rawBlob) { + var self = this; + self.rawEntry.toBlob(self.rawRepo, function blobCallback(error, rawBlob) { if (success(error, callback)) { - callback(null, git.blob(rawBlob)); - return; + callback(null, new git.blob(self.rawRepo, rawBlob)); } }); }; From 60f9b0c2ef5eb9862235c13ed15d43bb1ceb556e Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:43:27 +1300 Subject: [PATCH 042/186] Refactor tree entry --- include/tree_entry.h | 48 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/include/tree_entry.h b/include/tree_entry.h index 0449f9f7c..1bd543abc 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -26,16 +26,9 @@ using namespace node; */ class GitTreeEntry : ObjectWrap { public: - /** - * v8::FunctionTemplate used to create Node.js constructor - */ + static Persistent constructor_template; - /** - * Used to intialize the EventEmitter from Node.js - * - * @param target v8::Object the Node.js module object - */ static void Initialize(Handle target); git_tree_entry* GetValue(); void SetValue(git_tree_entry* tree); @@ -43,6 +36,18 @@ class GitTreeEntry : ObjectWrap { protected: static Handle New(const Arguments& args); + static Handle Name(const Arguments& args); + static void NameWork(uv_work_t* req); + static void NameAfterWork(uv_work_t* req); + + static Handle FileMode(const Arguments& args); + static void FileModeWork(uv_work_t* req); + static void FileModeAfterWork(uv_work_t* req); + + static Handle Id(const Arguments& args); + static void IdWork(uv_work_t* req); + static void IdAfterWork(uv_work_t* req); + static Handle ToBlob(const Arguments& args); static void ToBlobWork(uv_work_t *req); static void ToBlobAfterWork(uv_work_t *req); @@ -50,6 +55,33 @@ class GitTreeEntry : ObjectWrap { private: git_tree_entry* entry; + struct NameBaton { + uv_work_t request; + + git_tree_entry* rawEntry; + std::string name; + + Persistent callback; + }; + + struct FileModeBaton { + uv_work_t request; + + git_tree_entry* rawEntry; + int fileMode; + + Persistent callback; + }; + + struct IdBaton { + uv_work_t request; + + git_tree_entry* rawEntry; + git_oid* rawOid; + + Persistent callback; + }; + struct ToBlobBaton { uv_work_t request; const git_error* error; From c3b7c395ea1c21711a5d9d51937febc792ae9b96 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 01:46:48 +1300 Subject: [PATCH 043/186] Updated file comment --- include/commit.h | 2 +- include/object.h | 7 +- include/oid.h | 7 +- include/repo.h | 7 +- include/revwalk.h | 7 +- include/sig.h | 7 +- include/tree.h | 7 +- src/base.cc | 7 +- src/commit.cc | 225 +++++++++++++++++++++++----------------------- src/object.cc | 7 +- src/oid.cc | 7 +- src/sig.cc | 9 +- src/tree_entry.cc | 7 +- 13 files changed, 167 insertions(+), 139 deletions(-) diff --git a/include/commit.h b/include/commit.h index e6e00c108..5ff621856 100755 --- a/include/commit.h +++ b/include/commit.h @@ -1,5 +1,5 @@ /* - * Copyright 2011, Tim Branyen @tbranyen + * Copyright 2013, Tim Branyen @tbranyen * @author Michael Robinson @codeofinterest * * Dual licensed under the MIT and GPL licenses. diff --git a/include/object.h b/include/object.h index 981c2d4c2..cc5a5270c 100755 --- a/include/object.h +++ b/include/object.h @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef OBJ_H #define OBJ_H diff --git a/include/oid.h b/include/oid.h index cfab6db64..5a876491d 100755 --- a/include/oid.h +++ b/include/oid.h @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef OID_H #define OID_H diff --git a/include/repo.h b/include/repo.h index e5493b11d..8eb805e1e 100755 --- a/include/repo.h +++ b/include/repo.h @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef REPO_H #define REPO_H diff --git a/include/revwalk.h b/include/revwalk.h index 09a0c0588..1a76d529d 100755 --- a/include/revwalk.h +++ b/include/revwalk.h @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef REVWALK_H #define REVWALK_H diff --git a/include/sig.h b/include/sig.h index c01778e20..157fb2350 100755 --- a/include/sig.h +++ b/include/sig.h @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef GitSig_H #define GitSig_H diff --git a/include/tree.h b/include/tree.h index 3309c88d6..bdf62ac55 100755 --- a/include/tree.h +++ b/include/tree.h @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #ifndef GITTREE_H #define GITTREE_H diff --git a/src/base.cc b/src/base.cc index 5a73900a2..0fb22aab7 100755 --- a/src/base.cc +++ b/src/base.cc @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #include #include diff --git a/src/commit.cc b/src/commit.cc index a086b2fc8..39b6c0366 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -1,5 +1,5 @@ /* - * Copyright 2011, Tim Branyen @tbranyen + * Copyright 2013, Tim Branyen @tbranyen * @author Michael Robinson @codeofinterest * * Dual licensed under the MIT and GPL licenses. @@ -39,8 +39,6 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); NODE_SET_PROTOTYPE_METHOD(tpl, "parent", Parent); - NODE_SET_PROTOTYPE_METHOD(tpl, "fetchDetails", FetchDetails); - NODE_SET_PROTOTYPE_METHOD(tpl, "fetchDetailsSync", FetchDetailsSync); constructor_template = Persistent::New(tpl->GetFunction()); target->Set(String::NewSymbol("Commit"), constructor_template); @@ -69,118 +67,115 @@ Handle GitCommit::New(const Arguments& args) { return scope.Close(args.This()); } -Handle GitCommit::FetchDetailsSync(const Arguments& args) { - HandleScope scope; - - GitCommit *commit = ObjectWrap::Unwrap(args.This()); - git_commit* rawCommit = commit->GetValue(); - - GitCommitDetails* details = new GitCommitDetails; - details->oid = git_commit_id(rawCommit); - - details->sha[GIT_OID_HEXSZ] = '\0'; - git_oid_fmt(details->sha, details->oid); - - details->message = git_commit_message(rawCommit); - details->time = git_commit_time(rawCommit); - details->timeOffset = git_commit_time_offset(rawCommit); - details->committer = git_commit_committer(rawCommit); - details->author = git_commit_author(rawCommit); - details->parentCount = git_commit_parentcount(rawCommit); - - int parentCount = details->parentCount; - while (parentCount > 0) { - int parentIndex = parentCount -1; - char sha[GIT_OID_HEXSZ + 1]; - sha[GIT_OID_HEXSZ] = '\0'; - const git_oid *parentOid = git_commit_parent_id(rawCommit, parentIndex); - git_oid_fmt(sha, parentOid); - details->parentShas.push_back(sha); - parentCount--; - } - - return scope.Close(createCommitDetailsObject(details)); -} - -Handle GitCommit::FetchDetails(const Arguments& args) { - HandleScope scope; - - if(args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); - } - - FetchDetailsBaton* baton = new FetchDetailsBaton; - baton->request.data = baton; - baton->error = NULL; - baton->details = new GitCommitDetails; - baton->rawCommit = ObjectWrap::Unwrap(args.This())->commit; - baton->callback = Persistent::New(Local::Cast(args[0])); - - uv_queue_work(uv_default_loop(), &baton->request, FetchDetailsWork, (uv_after_work_cb)FetchDetailsAfterWork); - - return Undefined(); -} - -void GitCommit::FetchDetailsWork(uv_work_t *req) { - FetchDetailsBaton* baton = static_cast(req->data); - - GitCommitDetails* details = baton->details; - details->oid = git_commit_id(baton->rawCommit); - - details->sha[GIT_OID_HEXSZ] = '\0'; - git_oid_fmt(details->sha, details->oid); - - details->message = git_commit_message(baton->rawCommit); - details->time = git_commit_time(baton->rawCommit); - details->timeOffset = git_commit_time_offset(baton->rawCommit); - details->committer = git_commit_committer(baton->rawCommit); - details->author = git_commit_author(baton->rawCommit); - details->parentCount = git_commit_parentcount(baton->rawCommit); - - int parentCount = details->parentCount; - while (parentCount > 0) { - int parentIndex = parentCount -1; - char sha[GIT_OID_HEXSZ + 1]; - sha[GIT_OID_HEXSZ] = '\0'; - const git_oid *parentOid = git_commit_parent_id(baton->rawCommit, parentIndex); - git_oid_fmt(sha, parentOid); - details->parentShas.push_back(sha); - parentCount--; - } -} - -void GitCommit::FetchDetailsAfterWork(uv_work_t *req) { - HandleScope scope; - - FetchDetailsBaton* 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 argv[2] = { - Local::New(Null()), - createCommitDetailsObject(baton->details) - }; - - TryCatch try_catch; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); - if (try_catch.HasCaught()) { - node::FatalException(try_catch); - } - } - delete req; -} +// Handle GitCommit::FetchDetailsSync(const Arguments& args) { +// HandleScope scope; + +// GitCommit *commit = ObjectWrap::Unwrap(args.This()); +// git_commit* rawCommit = commit->GetValue(); + +// GitCommitDetails* details = new GitCommitDetails; +// details->oid = git_commit_id(rawCommit); + +// details->sha[GIT_OID_HEXSZ] = '\0'; +// git_oid_fmt(details->sha, details->oid); + +// details->message = git_commit_message(rawCommit); +// details->time = git_commit_time(rawCommit); +// details->timeOffset = git_commit_time_offset(rawCommit); +// details->committer = git_commit_committer(rawCommit); +// details->author = git_commit_author(rawCommit); +// details->parentCount = git_commit_parentcount(rawCommit); + +// int parentCount = details->parentCount; +// while (parentCount > 0) { +// int parentIndex = parentCount -1; +// char sha[GIT_OID_HEXSZ + 1]; +// sha[GIT_OID_HEXSZ] = '\0'; +// const git_oid *parentOid = git_commit_parent_id(rawCommit, parentIndex); +// git_oid_fmt(sha, parentOid); +// details->parentShas.push_back(sha); +// parentCount--; +// } + +// return scope.Close(createCommitDetailsObject(details)); +// } +// Handle GitCommit::FetchDetails(const Arguments& args) { +// HandleScope scope; + +// if(args.Length() == 0 || !args[0]->IsFunction()) { +// return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); +// } + +// FetchDetailsBaton* baton = new FetchDetailsBaton; +// baton->request.data = baton; +// baton->error = NULL; +// baton->details = new GitCommitDetails; +// baton->rawCommit = ObjectWrap::Unwrap(args.This())->commit; +// baton->callback = Persistent::New(Local::Cast(args[0])); + +// uv_queue_work(uv_default_loop(), &baton->request, FetchDetailsWork, (uv_after_work_cb)FetchDetailsAfterWork); + +// return Undefined(); +// } +// void GitCommit::FetchDetailsWork(uv_work_t *req) { +// FetchDetailsBaton* baton = static_cast(req->data); + +// GitCommitDetails* details = baton->details; +// details->oid = git_commit_id(baton->rawCommit); + +// details->sha[GIT_OID_HEXSZ] = '\0'; +// git_oid_fmt(details->sha, details->oid); + +// details->message = git_commit_message(baton->rawCommit); +// details->time = git_commit_time(baton->rawCommit); +// details->timeOffset = git_commit_time_offset(baton->rawCommit); +// details->committer = git_commit_committer(baton->rawCommit); +// details->author = git_commit_author(baton->rawCommit); +// details->parentCount = git_commit_parentcount(baton->rawCommit); + +// int parentCount = details->parentCount; +// while (parentCount > 0) { +// int parentIndex = parentCount -1; +// char sha[GIT_OID_HEXSZ + 1]; +// sha[GIT_OID_HEXSZ] = '\0'; +// const git_oid *parentOid = git_commit_parent_id(baton->rawCommit, parentIndex); +// git_oid_fmt(sha, parentOid); +// details->parentShas.push_back(sha); +// parentCount--; +// } +// } +// void GitCommit::FetchDetailsAfterWork(uv_work_t *req) { +// HandleScope scope; + +// FetchDetailsBaton* 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 argv[2] = { +// Local::New(Null()), +// createCommitDetailsObject(baton->details) +// }; + +// TryCatch try_catch; +// baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); +// if (try_catch.HasCaught()) { +// node::FatalException(try_catch); +// } +// } +// delete req; +// } Handle GitCommit::Lookup(const Arguments& args) { HandleScope scope; diff --git a/src/object.cc b/src/object.cc index 88224e3a7..d62c48812 100755 --- a/src/object.cc +++ b/src/object.cc @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #include #include diff --git a/src/oid.cc b/src/oid.cc index 016246d38..e0837ae08 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #include #include diff --git a/src/sig.cc b/src/sig.cc index 0b33e1089..0b52f32fb 100755 --- a/src/sig.cc +++ b/src/sig.cc @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #include #include @@ -17,7 +20,7 @@ void GitSig::Initialize (Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(3); constructor_template->SetClassName(String::NewSymbol("Sig")); diff --git a/src/tree_entry.cc b/src/tree_entry.cc index a6bd16ef4..37a1088fa 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #include #include From cb7d0941fe0db0bf6f4b4bb14124642431ec3480 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 21:23:37 +1300 Subject: [PATCH 044/186] Refactored reference.js --- lib/reference.js | 75 +++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/lib/reference.js b/lib/reference.js index 94e8231d9..ebe6bf1c6 100644 --- a/lib/reference.js +++ b/lib/reference.js @@ -1,37 +1,54 @@ -var git = require('../'); +var git = require('../'), + success = require('./utilities').success; -var Reference = function(rawReference) { - var self = {}; - - 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); +/** + * Convenience reference constructor. + * + * @constructor + * @param {git.raw.Repo} rawRepo + * @param {git.raw.Reference|null} rawReference + */ +var Reference = function(rawRepo, rawReference) { + if (!(rawRepo instanceof git.raw.Repo)) { + throw git.error('First parameter for Reference must be a raw repo'); } + this.rawRepo = rawRepo; - self.lookup = function(name, callback) { - self.reference.lookup(self.repo, name, function(error, reference) { - if (error) { - callback(git.error(error), self); - return; - } - self.reference = reference; - callback(null, self); - }); - }; + if (rawReference instanceof git.raw.Reference) { + this.rawReference = rawReference; + } else { + this.rawReference = new git.raw.Reference(this.rawRepo); + } +}; - self.oid = function(callback) { - self.reference.oid(function(error, rawOid) { - if (error) { - callback(git.error(error, self)); - return; - } - callback(null, git.oid(rawOid)); - }); - }; +/** + * Lookup the reference with the given name. + * + * @param {String} name + * @param {Function} callback + */ +Reference.prototype.lookup = function(name, callback) { + var self = this; + self.rawReference.lookup(self.rawRepo, name, function referenceLookup(error, rawReference) { + if (!success(error, callback)) { + return; + } + self.rawReference = rawReference; + callback(null, self); + }); +}; - return self; +/** + * Get the Oid representing this reference. + * + * @param {Function} callback + */ +Reference.prototype.oid = function(callback) { + this.rawReference.oid(function referenceOid(error, rawOid) { + if (success(error, callback)) { + callback(null, new git.oid(rawOid)); + } + }); }; exports.reference = Reference; From 2297ed0cddd2ff0b3f12e79e6facbf9761d70a3e Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 21:23:48 +1300 Subject: [PATCH 045/186] Fixed typo in oid.js --- lib/oid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oid.js b/lib/oid.js index b5da0fb42..8cbdfb55c 100644 --- a/lib/oid.js +++ b/lib/oid.js @@ -12,7 +12,7 @@ var Oid = function(rawOid) { /** * @return {git.raw.Oid} */ -Oid.prototype.getRawoid = function() { +Oid.prototype.getRawOid = function() { return this.rawOid; }; From 2b1d1c9b8a0e49feeff5232dbcf1fd4f6694083a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 21:24:00 +1300 Subject: [PATCH 046/186] Tidied reference.cc --- src/reference.cc | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/reference.cc b/src/reference.cc index c3357443a..bb1139b15 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -17,6 +17,7 @@ #include "../include/error.h" #include "../include/functions/string.h" +#include "../include/functions/utilities.h" using namespace v8; using namespace node; @@ -39,7 +40,6 @@ void GitReference::Initialize(Handle target) { git_reference* GitReference::GetValue() { return this->ref; } - void GitReference::SetValue(git_reference *ref) { this->ref = ref; } @@ -72,7 +72,6 @@ Handle GitReference::Oid(const Arguments& args) { return Undefined(); } - void GitReference::OidWork(uv_work_t* req) { OidBaton *baton = static_cast(req->data); @@ -91,24 +90,12 @@ void GitReference::OidWork(uv_work_t* req) { 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 { - + if (success(baton->error, baton->callback)) { Handle oid = GitOid::constructor_template->NewInstance(); GitOid *oidInstance = ObjectWrap::Unwrap(oid); oidInstance->SetValue(*const_cast(baton->rawOid)); From 6a9aaebe488de05dc14b12ac0845ef1ef1bca0c5 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 21:25:23 +1300 Subject: [PATCH 047/186] Refactored revwalk --- lib/revwalk.js | 101 +++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 53 deletions(-) diff --git a/lib/revwalk.js b/lib/revwalk.js index 8958f9e89..da8bf2839 100644 --- a/lib/revwalk.js +++ b/lib/revwalk.js @@ -1,72 +1,67 @@ -var git = require( '../' ); +var git = require('../'), + success = require('./utilities').success; -var _RevWalk = function( obj ) { - var self = {}; +var RevWalk = function(rawRepo, rawRevWalk) { + if (!(rawRepo instanceof git.raw.Repo)) { + throw git.error('First parameter for RevWalk must be a raw repo'); + } + this.rawRepo = rawRepo; - if (obj instanceof git.raw.Repo) { - self.repo = obj; - self.revwalk = new git.raw.RevWalk(obj); - } else if (obj instanceof git.raw.RevWalk) { - self.revwalk = obj; + if (rawRevWalk instanceof git.raw.RevWalk) { + this.rawRevWalk = rawRevWalk; + } else { + this.rawRevWalk = new git.raw.RevWalk(this.rawRepo); } +}; - /** - * Walk the history from the given oid. - * - * @param {Oid} oid - * @param {Function} callback Callback accepting the following arguments: - * error, index, commit, noMoreCommits - */ - self.walk = function(oid, callback) { - if(!callback) { return; } +/** + * Walk the history from the given oid. + * + * @param {Oid} oid + * @param {Function} callback Callback accepting the following arguments: + * error, index, commit, noMoreCommits + */ +RevWalk.prototype.walk = function(oid, callback) { + var self = this; + self.rawRevWalk.push(oid.getRawOid(), function revWalkPush(error) { + if (!success(error, callback)) { + return; + } - self.revwalk.push(oid.getRawOid(), function(error) { - if (error) { - callback.apply(this, [git.error(error)]); + var shouldContinue = true, index = 0; + + function walk() { + if(!shouldContinue) { return; } - var shouldContinue = true, index = 0; + self.rawRevWalk.next(function revWalkNext(error, oid, walkOver) { + if(error) { + callback(git.error(error), index, commit); + return; + } - function walk() { - if(!shouldContinue) { + // Finished walking history, apply callback with noMoreCommits = true + if (walkOver) { + callback(null, index, null, walkOver); return; } - self.revwalk.next(function(error, oid, walkOver) { + (new git.commit(self.rawRepo)).lookup(oid, function revWalkCommitLookup(error, commit) { if(error) { - callback.apply(this, [git.error(error), index, commit]); + callback(git.error(error), index, commit); return; } - - // Finished walking history, apply callback with noMoreCommits = true - if (walkOver) { - callback.apply(this, [null, index, null, walkOver]); - return; + if(callback(null, index, commit) === false) { + shouldContinue = false; } - - git.commit(self.repo).lookup(self.repo, oid, function(error, commit) { - - if(error) { - callback.apply(this, [git.error(error), index, commit]); - return; - } - - if(callback.apply(this, [null, index, commit]) === false) { - shouldContinue = false; - } - - index++; - walk(); - }); + index++; + walk(); }); - } - - walk(); - }); - }; - - return self; + }); + } + walk(); + }); }; -exports.revwalk = _RevWalk; +exports.revwalk = RevWalk; From a1b7fa9186c55d8131b39182bf50cf24e98fd33f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 21:25:39 +1300 Subject: [PATCH 048/186] Updated reference.cc --- src/reference.cc | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/reference.cc b/src/reference.cc index bb1139b15..fae3cef7b 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -143,7 +143,6 @@ Handle GitReference::Lookup(const Arguments& args) { return Undefined(); } - void GitReference::LookupWork(uv_work_t *req) { LookupBaton *baton = static_cast(req->data); @@ -153,23 +152,11 @@ void GitReference::LookupWork(uv_work_t *req) { baton->error = giterr_last(); } } - 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 { - + if (success(baton->error, baton->callback)) { baton->ref->SetValue(baton->rawRef); Handle argv[2] = { From 079205893a47e07e0613cce884920f52880ffd01 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 21:25:57 +1300 Subject: [PATCH 049/186] Tidied convenience-commit.js test --- test/convenience-commit.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index 9f0b2bbcb..43badc9ea 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -1,6 +1,6 @@ -var git = require('../'); -var rimraf = require('rimraf'); -var fs = require( 'fs' ); +var git = require('../'), + rimraf = require('rimraf'), + fs = require( 'fs' ); // Helper functions var helper = { @@ -49,8 +49,6 @@ var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; /** * Test that retreiving walking a given commit's history works as expected. - * - * @param {Object} test */ exports.history = function(test) { test.expect(368); @@ -66,7 +64,6 @@ exports.history = function(test) { test.equals(null, error, 'There should be no errors'); test.equals(historyCount, expectedHistoryCount, 'Manual count does not match expected'); test.equals(commits.length, expectedHistoryCount, '"end" count does not match expected'); - test.done(); }); }); From 6b38372cc123574ac2b9369d079137c192c4a891 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 21:26:31 +1300 Subject: [PATCH 050/186] Removed unused items from commit.h header --- include/commit.h | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/include/commit.h b/include/commit.h index 5ff621856..24988bf71 100755 --- a/include/commit.h +++ b/include/commit.h @@ -1,5 +1,5 @@ /* - * Copyright 2013, Tim Branyen @tbranyen + * Copyright 2011, Tim Branyen @tbranyen * @author Michael Robinson @codeofinterest * * Dual licensed under the MIT and GPL licenses. @@ -17,7 +17,6 @@ #include "tree.h" #include "../include/functions/string.h" -#include "../include/functions/commit.h" using namespace node; using namespace v8; @@ -49,17 +48,13 @@ class GitCommit : public ObjectWrap { ~GitCommit() {} static Handle New(const Arguments& args); - - static Handle FetchDetailsSync(const Arguments& args); - static Handle FetchDetails(const Arguments& args); - static void FetchDetailsWork(uv_work_t *req); - static void FetchDetailsAfterWork(uv_work_t *req); + static Handle Close(const Arguments& args); static Handle Lookup(const Arguments& args); static void LookupWork(uv_work_t *req); static void LookupAfterWork(uv_work_t *req); - static Handle Close(const Arguments& args); + static Handle Oid(const Arguments& args); static Handle Tree(const Arguments& args); static void TreeWork(uv_work_t* req); @@ -95,19 +90,6 @@ class GitCommit : public ObjectWrap { Persistent callback; }; - /** - * Struct containing details for a commit. - */ - struct FetchDetailsBaton { - uv_work_t request; - const git_error* error; - - git_commit* rawCommit; - GitCommitDetails* details; - - Persistent callback; - }; - /** * Contains references to the current commit, parent commit (output) * parent commit's index, also contains references to an error code post From 6b0ed5cf1314e68aa4d08e73a1c93e97de074023 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:20:32 +1300 Subject: [PATCH 051/186] Removed commit function from gyp binding --- binding.gyp | 1 - 1 file changed, 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index ab18cbab5..5f48fed38 100644 --- a/binding.gyp +++ b/binding.gyp @@ -17,7 +17,6 @@ 'src/tree_entry.cc', 'src/diff_list.cc', 'src/threads.cc', - 'src/functions/commit.cc', 'src/functions/string.cc', 'src/functions/utilities.cc' ], From 76327ceace8b088b0b56b27c844f232c9890826a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:22:03 +1300 Subject: [PATCH 052/186] Fixed accidental line removal --- src/reference.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/reference.cc b/src/reference.cc index fae3cef7b..40e454944 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -90,6 +90,8 @@ void GitReference::OidWork(uv_work_t* req) { return; } } + + baton->rawOid = git_reference_target(baton->rawRef); } void GitReference::OidAfterWork(uv_work_t* req) { HandleScope scope; From 0873d9696eb72e28843f9e933fd04f5da66ccdcf Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:22:35 +1300 Subject: [PATCH 053/186] Moved close to match position in header --- src/commit.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commit.cc b/src/commit.cc index 39b6c0366..32a974b8b 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -52,11 +52,6 @@ void GitCommit::SetValue(git_commit* commit) { this->commit = commit; } -void GitCommit::Close() { - git_commit_free(this->commit); - this->commit = NULL; -} - Handle GitCommit::New(const Arguments& args) { HandleScope scope; @@ -67,6 +62,11 @@ Handle GitCommit::New(const Arguments& args) { return scope.Close(args.This()); } +void GitCommit::Close() { + git_commit_free(this->commit); + this->commit = NULL; +} + // Handle GitCommit::FetchDetailsSync(const Arguments& args) { // HandleScope scope; From 0335d8c4a17542a79dd99ca6d983c75beeeba1e3 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:23:37 +1300 Subject: [PATCH 054/186] Updated lookup, added sha & oid getters --- lib/commit.js | 12 +++++++++ src/commit.cc | 74 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index a5d8876f2..eaecc760a 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -42,6 +42,18 @@ Commit.prototype.lookup = function(oid, callback) { }); }; +Commit.prototype.oid = function(callback) { + callback(null, new git.oid(this.rawCommit.oid())); +}; + +Commit.prototype.sha = function(callback) { + this.rawCommit.sha(function(error, sha) { + if (success(error, callback)) { + callback(null, sha); + } + }); +}; + /** * Retrieve the tree for this commit. * diff --git a/src/commit.cc b/src/commit.cc index 32a974b8b..a8be85c06 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -35,6 +35,9 @@ void GitCommit::Initialize(Handle target) { tpl->SetClassName(String::NewSymbol("Commit")); NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); + NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha); + NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); @@ -212,9 +215,8 @@ Handle GitCommit::Lookup(const Arguments& args) { void GitCommit::LookupWork(uv_work_t *req) { LookupBaton *baton = static_cast(req->data); - git_oid rawOid = baton->rawOid; if (!baton->sha.empty()) { - int returnCode = git_oid_fromstr(&rawOid, baton->sha.c_str()); + int returnCode = git_oid_fromstr(&baton->rawOid, baton->sha.c_str()); if (returnCode != GIT_OK) { baton->error = giterr_last(); return; @@ -222,7 +224,7 @@ void GitCommit::LookupWork(uv_work_t *req) { } baton->rawCommit = NULL; - int returnCode = git_commit_lookup(&baton->rawCommit, baton->repo, &rawOid); + int returnCode = git_commit_lookup(&baton->rawCommit, baton->repo, &baton->rawOid); if (returnCode != GIT_OK) { baton->error = giterr_last(); } @@ -231,23 +233,11 @@ void GitCommit::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 { - + if (success(baton->error, baton->callback)) { Local commit = GitCommit::constructor_template->NewInstance(); GitCommit *commitInstance = ObjectWrap::Unwrap(commit); commitInstance->SetValue(baton->rawCommit); + commitInstance->oid = &baton->rawOid; Handle argv[2] = { Local::New(Null()), @@ -263,6 +253,56 @@ void GitCommit::LookupAfterWork(uv_work_t *req) { delete req; } +Handle GitCommit::Oid(const Arguments& args) { + HandleScope scope; + + Local oid = GitOid::constructor_template->NewInstance(); + GitOid *oidInstance = ObjectWrap::Unwrap(oid); + oidInstance->SetValue(*const_cast(ObjectWrap::Unwrap(args.This())->oid)); + + return scope.Close(oid); +} + +Handle GitCommit::Sha(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + ShaBaton* baton = new ShaBaton; + baton->request.data = baton; + baton->rawOid = ObjectWrap::Unwrap(args.This())->oid; + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, ShaWork, (uv_after_work_cb)ShaAfterWork); + + return Undefined(); +} +void GitCommit::ShaWork(uv_work_t* req) { + ShaBaton *baton = static_cast(req->data); + + baton->sha[GIT_OID_HEXSZ] = '\0'; + + git_oid_fmt(baton->sha, baton->rawOid); +} +void GitCommit::ShaAfterWork(uv_work_t* req) { + HandleScope scope; + ShaBaton *baton = static_cast(req->data); + + Handle argv[2] = { + Local::New(Null()), + String::New(baton->sha) + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; +} + Handle GitCommit::Close(const Arguments& args) { HandleScope scope; From 20fb0961e276ae94726235ff81c663160ef1644d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:24:22 +1300 Subject: [PATCH 055/186] Fixed commit lookup oid checking --- lib/commit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index eaecc760a..8d930160c 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -30,7 +30,9 @@ var Commit = function(rawRepo, rawCommit) { * @param {Function} callback */ Commit.prototype.lookup = function(oid, callback) { - if (typeof oid !== 'string' && !(oid instanceof git.raw.Oid)) { + if (typeof oid !== 'undefined' && + typeof oid !== 'string' && + !(oid instanceof git.raw.Oid)) { oid = oid.getRawOid(); } var self = this; From b03df79dca9a46cda4ffadd5da92a11ee785644f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:24:31 +1300 Subject: [PATCH 056/186] Updated commit history --- lib/commit.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 8d930160c..421aa0193 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -5,6 +5,7 @@ var git = require( '../' ), /** * Convenience commit constructor. * + * @constructor * @param {RawCommit|Null} rawCommit * @return {Commit} */ @@ -96,22 +97,25 @@ Commit.prototype.file = function(path, callback) { * error, commits[] */ Commit.prototype.history = function() { - var revwalk = git.revwalk(self.repo), - event = new events.EventEmitter(), - commits = []; - - revwalk.walk(self.id, function(error, index, commit, noMoreCommits) { - if(error) { - event.emit('end', error, commits); - return false; - } + var event = new events.EventEmitter(), + self = this; + + self.oid(function commitOid(error, oid) { + var revwalk = new git.revwalk(self.rawRepo), + commits = []; + revwalk.walk(oid, function commitRevWalk(error, index, commit, noMoreCommits) { + if(error) { + event.emit('end', error, commits); + return false; + } - if (noMoreCommits) { - event.emit('end', null, commits); - return; - } - event.emit('commit', null, commit); - commits.push(commit); + if (noMoreCommits) { + event.emit('end', null, commits); + return; + } + event.emit('commit', null, commit); + commits.push(commit); + }); }); return event; From 583c72cde3895f97efc68f32d71b35f15ce01f53 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:24:41 +1300 Subject: [PATCH 057/186] Updated commit header --- include/commit.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/commit.h b/include/commit.h index 24988bf71..f7c816aea 100755 --- a/include/commit.h +++ b/include/commit.h @@ -56,6 +56,10 @@ class GitCommit : public ObjectWrap { static Handle Oid(const Arguments& args); + static Handle Sha(const Arguments& args); + static void ShaWork(uv_work_t* req); + static void ShaAfterWork(uv_work_t* req); + static Handle Tree(const Arguments& args); static void TreeWork(uv_work_t* req); static void TreeAfterWork(uv_work_t* req); @@ -80,6 +84,15 @@ class GitCommit : public ObjectWrap { Persistent callback; }; + struct ShaBaton { + uv_work_t request; + + git_oid* rawOid; + char sha[GIT_OID_HEXSZ + 1]; + + Persistent callback; + }; + struct TreeBaton { uv_work_t request; const git_error* error; From 381f4711e42983988e8ab1d04467c60b246d1541 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:24:53 +1300 Subject: [PATCH 058/186] Started refactoring tree.js --- lib/tree.js | 191 +++++++++++++++++++++++++--------------------------- 1 file changed, 93 insertions(+), 98 deletions(-) diff --git a/lib/tree.js b/lib/tree.js index 35198dab4..d5a3d5a07 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -1,110 +1,105 @@ var git = require('../'), + success = require('./utilities').success, events = require('events'); -var Tree = function(rawObject, tree) { - var self = {}; +/** + * Tree convenience class constructor. + * + * @param {git.raw.Repo} rawRepo + * @param {git.raw.Tree|null} rawTree + */ +var Tree = function(rawRepo, rawTree) { + if(!(rawRepo instanceof git.raw.Repo)) { + throw git.error('First parameter for Tree must be a raw repo'); + } + this.rawRepo = rawRepo; - if (rawObject instanceof git.raw.Repo && - tree instanceof git.raw.Tree) { - self.repo = rawObject; - self.tree = tree; - } else if(rawObject instanceof git.raw.Repo) { - self.repo = rawObject; - self.tree = new git.raw.Tree(tree); - } else if (rawObject instanceof git.raw.Tree) { - self.tree = rawObject; + if(rawTree instanceof git.raw.Tree) { + this.rawTree = rawTree; } else { - self.tree = new git.raw.Tree(); + this.rawTree = new git.raw.Tree(this.rawRepo); } +}; - Object.defineProperty(self, 'length', { - get: function() { - return self.tree.entryCount(); - }, - enumerable: true - }); - - self.walk = function(repo) { - repo = repo || self.repo; - - var entry, - index, - length = self.length, - event = new events.EventEmitter(), - entries = []; - - function next(index) { - var dir; - var tree; - var prerequisites = 0; - - function complete(error) { - if (index < length-1) { - next(index = index+1); - } else { - event.emit('end', error, entries); - } - } - - entry = git.entry(repo); - - self.tree.entryByIndex(entry.entry, index, function() { - if (entry.isFile()) { - entries.push(entry); - event.emit('entry', null, index, entry); - } else { - dir = entry.name; - tree = entry.tree(); - prerequisites++; - if (tree.error) { - event.emit('end', tree.error); - return; - } - - tree.walk(repo).on('entry', function(error, index, entry) { - if (error) { - event.emit('entry', error, index, entry); - } - entry.dir = dir + '/' + entry.dir; - event.emit('entry', null, index, entry); - }).on('end', function(error, endEntries) { - if (error) { - complete(error); - } - prerequisites--; - entries = entries.concat(endEntries); - if (prerequisites === 0) { - complete(error); - } - }); - } - - if (prerequisites === 0) { - complete(); - } - }); - } - - next(0); - - return event; - }; - - self.entry = function(path, callback) { - if(!callback) { - throw new Error('Tree entry function requires a callback'); +/** + * Retrieve the entry by path. + * + * @param {String} path + * @param {Function} callback + */ +Tree.prototype.entry = function(path, callback) { + var self = this; + self.rawTree.entryByPath(path, function(error, rawEntry) { + if (success(error, callback)) { + callback(null, new git.entry(self.rawRepo, rawEntry)); } + }); +}; - self.tree.entryByPath(path, function(error, entry) { - if (error) { - callback(git.error(error), null); - } else { - git.entry(entry).fetchDetails(callback); - } - }); - }; - - return self; +Tree.prototype.walk = function() { + // @todo refactor to use git_tree_walk + + // var entry, + // index, + // length = self.length, + // event = new events.EventEmitter(), + // entries = []; + + // function next(index) { + // var dir; + // var tree; + // var prerequisites = 0; + + // function complete(error) { + // if (index < length - 1) { + // next(index = index + 1); + // } else { + // event.emit('end', error, entries); + // } + // } + + // entry = git.entry(repo); + + // self.tree.entryByIndex(entry.entry, index, function() { + // if (entry.isFile()) { + // entries.push(entry); + // event.emit('entry', null, index, entry); + // } else { + // dir = entry.name; + // tree = entry.tree(); + // prerequisites++; + // if (tree.error) { + // event.emit('end', tree.error); + // return; + // } + + // tree.walk(repo).on('entry', function(error, index, entry) { + // if (error) { + // event.emit('entry', error, index, entry); + // } + // entry.dir = dir + '/' + entry.dir; + // event.emit('entry', null, index, entry); + // }).on('end', function(error, endEntries) { + // if (error) { + // complete(error); + // } + // prerequisites--; + // entries = entries.concat(endEntries); + // if (prerequisites === 0) { + // complete(error); + // } + // }); + // } + + // if (prerequisites === 0) { + // complete(); + // } + // }); + // } + + // next(0); + + // return event; }; exports.tree = Tree; From c3ec5a1198199fcc72c32d802920f8dd2acb6a5c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:25:05 +1300 Subject: [PATCH 059/186] Updated tree.cc file comment --- src/tree.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tree.cc b/src/tree.cc index 7cc6fc361..c108d1be0 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -1,6 +1,9 @@ /* -Copyright (c) 2011, Tim Branyen @tbranyen -*/ + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ #include #include From 18118baa2a09ead80765e0b416227da70d4b7963 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:25:25 +1300 Subject: [PATCH 060/186] Started refactoring tree entry --- src/tree_entry.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 37a1088fa..5dcb670f7 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -18,6 +18,8 @@ #include "../include/tree_entry.h" #include "../include/error.h" +#include "../include/functions/utilities.h" + using namespace v8; using namespace node; @@ -27,6 +29,9 @@ void GitTreeEntry::Initialize(Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("TreeEntry")); + NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); + NODE_SET_PROTOTYPE_METHOD(tpl, "fileMode", FileMode); + NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id); NODE_SET_PROTOTYPE_METHOD(tpl, "toBlob", ToBlob); constructor_template = Persistent::New(tpl->GetFunction()); @@ -36,7 +41,6 @@ void GitTreeEntry::Initialize(Handle target) { git_tree_entry* GitTreeEntry::GetValue() { return this->entry; } - void GitTreeEntry::SetValue(git_tree_entry* entry) { this->entry = entry; } @@ -51,6 +55,55 @@ Handle GitTreeEntry::New(const Arguments& args) { return scope.Close(args.This()); } +Handle GitTreeEntry::Name(const Arguments& args) { + HandleScope scope; + + // GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + + // return scope.Close(String::New(git_tree_entry_name(entry->entry))); + return Undefined(); +} +void GitTreeEntry::NameWork(uv_work_t* req) { + +} +void GitTreeEntry::NameAfterWork(uv_work_t* req) { + +} + +Handle GitTreeEntry::FileMode(const Arguments& args) { + // HandleScope scope; + + // GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + + // return scope.Close(Number::New(git_tree_entry_filemode(entry->entry))); + return Undefined(); +} +void GitTreeEntry::FileModeWork(uv_work_t* req) { + +} +void GitTreeEntry::FileModeAfterWork(uv_work_t* req) { + +} + +Handle GitTreeEntry::Id(const Arguments& args) { + // HandleScope scope; + + // GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + + // Handle oid = GitOid::constructor_template->NewInstance(); + // GitOid* oidInstance = ObjectWrap::Unwrap(oid); + // oidInstance->SetValue(*const_cast(git_tree_entry_id(entry->entry))); + + // return oid; + return Undefined(); +} +void GitTreeEntry::IdWork(uv_work_t* req) { + +} +void GitTreeEntry::IdAfterWork(uv_work_t* req) { + +} + Handle GitTreeEntry::ToBlob(const Arguments& args) { HandleScope scope; @@ -62,7 +115,7 @@ Handle GitTreeEntry::ToBlob(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - ToBlobBaton* baton = new ToBlobBaton(); + ToBlobBaton* baton = new ToBlobBaton; baton->request.data = baton; baton->error = NULL; baton->rawRepo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); From 772816dc1968b823a859a677bf3689053f70adbe Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:28:04 +1300 Subject: [PATCH 061/186] Removed public close --- include/commit.h | 2 -- src/commit.cc | 20 ++++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/include/commit.h b/include/commit.h index f7c816aea..57881aec9 100755 --- a/include/commit.h +++ b/include/commit.h @@ -41,8 +41,6 @@ class GitCommit : public ObjectWrap { git_commit* GetValue(); void SetValue(git_commit* commit); - void Close(); - protected: GitCommit() {} ~GitCommit() {} diff --git a/src/commit.cc b/src/commit.cc index a8be85c06..e316fd00d 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -64,10 +64,15 @@ Handle GitCommit::New(const Arguments& args) { return scope.Close(args.This()); } +Handle GitCommit::Close(const Arguments& args) { + HandleScope scope; + + GitCommit *commit = ObjectWrap::Unwrap(args.This()); + commit->Close(); + git_commit_free(commit->commit); + commit->commit = NULL; -void GitCommit::Close() { - git_commit_free(this->commit); - this->commit = NULL; + return scope.Close(Undefined()); } // Handle GitCommit::FetchDetailsSync(const Arguments& args) { @@ -303,15 +308,6 @@ void GitCommit::ShaAfterWork(uv_work_t* req) { delete req; } -Handle GitCommit::Close(const Arguments& args) { - HandleScope scope; - - GitCommit *commit = ObjectWrap::Unwrap(args.This()); - commit->Close(); - - return scope.Close(Undefined()); -} - Handle GitCommit::Tree(const Arguments& args) { HandleScope scope; From b7a948de3813a27b661a809ec98372b7b03129b1 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 28 Mar 2013 22:28:14 +1300 Subject: [PATCH 062/186] Updated revwalk documentation --- lib/revwalk.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/revwalk.js b/lib/revwalk.js index da8bf2839..fff4e46ca 100644 --- a/lib/revwalk.js +++ b/lib/revwalk.js @@ -1,6 +1,13 @@ var git = require('../'), success = require('./utilities').success; +/** + * Convenience revision walking class + * + * @constructor + * @param {git.raw.Repo} rawRepo + * @param {git.raw.RevWalk|null} rawRevWalk + */ var RevWalk = function(rawRepo, rawRevWalk) { if (!(rawRepo instanceof git.raw.Repo)) { throw git.error('First parameter for RevWalk must be a raw repo'); From c03723ed33bd62ef2daa3edf04c6c6b0032fbed7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Jan 2001 13:13:38 +1300 Subject: [PATCH 063/186] Renamed signature --- include/{sig.h => signature.h} | 22 ++----- lib/index.js | 2 +- lib/sig.js | 31 --------- lib/signature.js | 23 +++++++ src/base.cc | 4 +- src/sig.cc | 115 --------------------------------- src/signature.cc | 109 +++++++++++++++++++++++++++++++ 7 files changed, 142 insertions(+), 164 deletions(-) rename include/{sig.h => signature.h} (72%) delete mode 100644 lib/sig.js create mode 100644 lib/signature.js delete mode 100755 src/sig.cc create mode 100755 src/signature.cc diff --git a/include/sig.h b/include/signature.h similarity index 72% rename from include/sig.h rename to include/signature.h index 157fb2350..af932e778 100755 --- a/include/sig.h +++ b/include/signature.h @@ -5,8 +5,8 @@ * Dual licensed under the MIT and GPL licenses. */ -#ifndef GitSig_H -#define GitSig_H +#ifndef GitSignature_H +#define GitSignature_H #include #include @@ -18,23 +18,18 @@ using namespace v8; using namespace node; -class GitSig : public ObjectWrap { +class GitSignature : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize(Handle target); void New(const char *name, const char *email, time_t time, int offset); git_signature* GetValue(); - void SetValue(git_signature* GitSig); - git_signature* Dup(); - void Free(); - - char* Name(); - char* Email(); + void SetValue(git_signature* GitSignature); protected: - GitSig() {}; - ~GitSig() {}; + GitSignature() {}; + ~GitSignature() {}; static Handle New(const Arguments& args); static Handle Dup(const Arguments& args); @@ -45,9 +40,6 @@ class GitSig : public ObjectWrap { private: git_signature* sig; - - char* name; - char* email; }; #endif diff --git a/lib/index.js b/lib/index.js index 6d37ebac3..f89724f93 100755 --- a/lib/index.js +++ b/lib/index.js @@ -12,7 +12,7 @@ if (~os.type().indexOf('CYGWIN') && !~path.indexOf(root)) { // Import libraries exports.blob = require('./blob.js').blob; exports.repo = require('./repo.js').repo; -exports.sig = require('./sig.js').sig; +exports.signature = require('./signature.js').signature; exports.oid = require('./oid.js').oid; exports.object = require('./object.js').object; exports.reference = require('./reference.js').reference; diff --git a/lib/sig.js b/lib/sig.js deleted file mode 100644 index 494de94ca..000000000 --- a/lib/sig.js +++ /dev/null @@ -1,31 +0,0 @@ -var git = require( '../' ); - -var _Sig = function( obj ) { - var self = {}; - - Object.defineProperty( self, 'name', { - get: function() { - return self.sig.name(); - }, - enumerable: true - }); - - Object.defineProperty( self, 'email', { - get: function() { - return self.sig.email(); - }, - enumerable: true - }); - - // Internal references to Git references - if( obj instanceof git.raw.Repo ) { - // TODO: Add support for creation - } - else if ( obj instanceof git.raw.Sig ) { - self.sig = obj; - } - - return self; -}; - -exports.sig = _Sig; diff --git a/lib/signature.js b/lib/signature.js new file mode 100644 index 000000000..78bda123e --- /dev/null +++ b/lib/signature.js @@ -0,0 +1,23 @@ +var git = require('../'); + +var Signature = function(rawSignature) { + if (rawSignature instanceof git.raw.Signature) { + this.rawSignature = rawSignature; + } else { + this.rawSignature = new git.raw.Signature(); + } +}; + +Signature.prototype.name = function(callback) { + callback(null, this.rawSignature.name()); +}; + +Signature.prototype.email = function(callback) { + callback(null, this.rawSignature.email()); +}; + +Signature.prototype.duplicate = function(callback) { + callback(null, new Signature(git.rawSignature.duplicate())); +}; + +exports.sig = Signature; diff --git a/src/base.cc b/src/base.cc index 0fb22aab7..511c85e8e 100755 --- a/src/base.cc +++ b/src/base.cc @@ -11,7 +11,7 @@ #include "../vendor/libgit2/include/git2.h" #include "../include/reference.h" -#include "../include/sig.h" +#include "../include/signature.h" #include "../include/error.h" #include "../include/blob.h" #include "../include/repo.h" @@ -30,7 +30,7 @@ extern "C" void init(Handle target) { GitError::Initialize(target); GitReference::Initialize(target); - GitSig::Initialize(target); + GitSignature::Initialize(target); GitBlob::Initialize(target); GitOid::Initialize(target); GitObject::Initialize(target); diff --git a/src/sig.cc b/src/sig.cc deleted file mode 100755 index 0b52f32fb..000000000 --- a/src/sig.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2013, Tim Branyen @tbranyen - * @author Michael Robinson @codeofinterest - * - * Dual licensed under the MIT and GPL licenses. - */ - -#include -#include - -#include "../vendor/libgit2/include/git2.h" - -#include "../include/repo.h" -#include "../include/sig.h" - -using namespace v8; -using namespace node; - -void GitSig::Initialize (Handle target) { - HandleScope scope; - - Local t = FunctionTemplate::New(New); - - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(3); - constructor_template->SetClassName(String::NewSymbol("Sig")); - - NODE_SET_PROTOTYPE_METHOD(constructor_template, "dup", Dup); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "free", Free); - - // FIXME: This is an irresponsible way to accomplish fetching properties from the struct - NODE_SET_PROTOTYPE_METHOD(constructor_template, "name", Name); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "email", Email); - - target->Set(String::NewSymbol("Sig"), constructor_template->GetFunction()); -} - -git_signature* GitSig::GetValue() { - return this->sig; -} - -void GitSig::SetValue(git_signature* sig) { - this->sig = sig; - this->name = sig->name; - this->email = sig->email; -} - -void GitSig::New(const char *name, const char *email, time_t time, int offset) { - git_signature_new(&this->sig, name, email, time, offset); - //this->sig = git_signature_new(name, email, time, offset); -} - -git_signature* GitSig::Dup() { - return git_signature_dup(this->sig); -} - -void GitSig::Free() { - git_signature_free(this->sig); -} - -char* GitSig::Name() { - return this->name; -} - -char* GitSig::Email() { - return this->email; -} - -Handle GitSig::New(const Arguments& args) { - HandleScope scope; - - GitSig *sig = new GitSig(); - sig->Wrap(args.This()); - - return scope.Close( args.This() ); -} - -Handle GitSig::Dup(const Arguments& args) { - HandleScope scope; - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("GitSignature is required and must be an Object."))); - } - - GitSig* sig = ObjectWrap::Unwrap(args[0]->ToObject()); - sig->SetValue(sig->Dup()); - - return scope.Close( Undefined() ); -} - -Handle GitSig::Free(const Arguments& args) { - HandleScope scope; - - GitSig *sig = ObjectWrap::Unwrap(args.This()); - sig->Free(); - - return scope.Close( Undefined() ); -} - -Handle GitSig::Name(const Arguments& args) { - HandleScope scope; - - GitSig *sig = ObjectWrap::Unwrap(args.This()); - - return scope.Close( String::New(sig->Name()) ); -} - -Handle GitSig::Email(const Arguments& args) { - HandleScope scope; - - GitSig *sig = ObjectWrap::Unwrap(args.This()); - - return scope.Close( String::New(sig->Email()) ); -} -Persistent GitSig::constructor_template; diff --git a/src/signature.cc b/src/signature.cc new file mode 100755 index 000000000..0f20b5679 --- /dev/null +++ b/src/signature.cc @@ -0,0 +1,109 @@ +/* + * Copyright 2013, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * + * Dual licensed under the MIT and GPL licenses. + */ + +#include +#include + +#include "../vendor/libgit2/include/git2.h" + +#include "../include/repo.h" +#include "../include/sig.h" + +using namespace v8; +using namespace node; + +void GitSignature::Initialize (Handle target) { + Local tpl = FunctionTemplate::New(New); + + tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->SetClassName(String::NewSymbol("Signature")); + + NODE_SET_PROTOTYPE_METHOD(tpl, "duplicate", Duplicate); + NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); + NODE_SET_PROTOTYPE_METHOD(tpl, "email", Email); + + NODE_SET_PROTOTYPE_METHOD(tpl, "free", Free); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Signature"), constructor_template); +} + +git_signature* GitSignature::GetValue() { + return this->sig; +} + +void GitSignature::SetValue(git_signature* sig) { + this->sig = sig; + this->name = sig->name; + this->email = sig->email; +} + +void GitSignature::New(const char *name, const char *email, time_t time, int offset) { + git_signature_new(&this->sig, name, email, time, offset); + //this->sig = git_signature_new(name, email, time, offset); +} + +char* GitSignature::Name() { + return this->name; +} + +char* GitSignature::Email() { + return this->email; +} + +Handle GitSignature::New(const Arguments& args) { + HandleScope scope; + + GitSignature *signature = new GitSignature(); + signature->Wrap(args.This()); + + return scope.Close(args.This()); +} + +Handle GitSignature::Duplicate(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsObject()) { + return ThrowException(Exception::Error(String::New("GitSignature is required and must be an Object."))); + } + + Local duplicateSignature = GitSignature::constructor_template->NewInstance(); + GitSignature *duplicateSignatureInstance = ObjectWrap::Unwrap(signature); + + GitSignature* signature = ObjectWrap::Unwrap(args[0]->ToObject()); + + duplicateSignatureInstance->SetValue(git_signature_dup(signature->GetValue())); + + return duplicateSignature; +} + +Handle GitSignature::Free(const Arguments& args) { + HandleScope scope; + + GitSignature *signature = ObjectWrap::Unwrap(args.This()); + git_signature_free(this->signature); + + return Undefined(); +} + +Handle GitSignature::Name(const Arguments& args) { + HandleScope scope; + + GitSignature *signature = ObjectWrap::Unwrap(args.This()); + + return String::New(signature->Name()); +} + +Handle GitSignature::Email(const Arguments& args) { + HandleScope scope; + + GitSignature *signature = ObjectWrap::Unwrap(args.This()); + + return String::New(signature->Email()); +} + +Persistent GitSignature::constructor_template; From e1ff4f80aeda7b4f246a9546d0ccfea327d08ac7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Jan 2001 13:16:58 +1300 Subject: [PATCH 064/186] Tidied signature --- include/signature.h | 2 +- src/signature.cc | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/include/signature.h b/include/signature.h index af932e778..88229fe65 100755 --- a/include/signature.h +++ b/include/signature.h @@ -21,9 +21,9 @@ using namespace node; class GitSignature : public ObjectWrap { public: static Persistent constructor_template; + static void Initialize(Handle target); - void New(const char *name, const char *email, time_t time, int offset); git_signature* GetValue(); void SetValue(git_signature* GitSignature); diff --git a/src/signature.cc b/src/signature.cc index 0f20b5679..b93ab3137 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -36,23 +36,8 @@ git_signature* GitSignature::GetValue() { return this->sig; } -void GitSignature::SetValue(git_signature* sig) { - this->sig = sig; - this->name = sig->name; - this->email = sig->email; -} - -void GitSignature::New(const char *name, const char *email, time_t time, int offset) { - git_signature_new(&this->sig, name, email, time, offset); - //this->sig = git_signature_new(name, email, time, offset); -} - -char* GitSignature::Name() { - return this->name; -} - -char* GitSignature::Email() { - return this->email; +void GitSignature::SetValue(git_signature* signature) { + this->signature = signature; } Handle GitSignature::New(const Arguments& args) { From 0bb9e370d447bba7b56d382cfd6e37086c8842e1 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Jan 2001 13:30:48 +1300 Subject: [PATCH 065/186] Added commit tests --- test/convenience-commit.js | 135 +++++++++++++++++++++++++++++++++++-- 1 file changed, 128 insertions(+), 7 deletions(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index 43badc9ea..de78ed9c1 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -2,6 +2,8 @@ var git = require('../'), rimraf = require('rimraf'), fs = require( 'fs' ); +var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; + // Helper functions var helper = { // Test if obj is a true function @@ -32,6 +34,131 @@ exports.method = function(test){ test.done(); }; +exports.message = function(test) { + test.expect(3); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.message(function(error, message) { + test.equals(error, null, 'There should be no error'); + test.notEqual(message, null, 'Message should not be null'); + test.equals(message, 'Update README.md', 'Message should match expected value'); + test.done(); + }); + }); + }); +}; + +exports.sha = function(test) { + test.expect(3); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.sha(function(error, sha) { + test.equals(error, null, 'There should be no error'); + test.notEqual(sha, null, 'SHA should not be null'); + test.equals(sha, historyCountKnownSHA, 'SHA should match expected value'); + test.done(); + }); + }); + }); +}; + +exports.time = function(test) { + test.expect(3); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.time(function(error, time) { + test.equals(error, null, 'There should be no error'); + test.notEqual(time, null, 'Time should not be null'); + test.equals(time, 1362012884, 'Time should match expected value'); + test.done(); + }); + }); + }); +}; + +exports.offset = function(test) { + test.expect(3); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.offset(function(error, offset) { + test.equals(error, null, 'There should be no error'); + test.notEqual(offset, null, 'Offset should not be null'); + test.equals(offset, 780, 'Offset should match expected value'); + test.done(); + }); + }); + }); +}; + +exports.author = function(test) { + test.expect(3); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.author(function(error, author) { + test.equals(error, null, 'There should be no error'); + test.notEqual(author, null, 'Author should not be null'); + test.done(); + }); + }); + }); +}; + +exports.authorName = function(test) { + test.expect(1); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.author(function commitAuthor(error, author) { + author.name(function authorName(error, name) { + test.equals(name, 'Michael Robinson', 'The author name should match expected value'); + test.done(); + }); + }); + }); + }); +}; + +exports.authorEmail = function(test) { + test.expect(1); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.author(function commitAuthor(error, author) { + author.email(function authorName(error, email) { + test.equals(email, 'mike@pagesofinterest.net', 'The author email should match expected value'); + test.done(); + }); + }); + }); + }); +}; + +exports.committerName = function(test) { + test.expect(1); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.committer(function commitCommitter(error, committer) { + committer.name(function committerName(error, name) { + test.equals(name, 'Michael Robinson', 'The author name should match expected value'); + test.done(); + }); + }); + }); + }); +}; + +exports.committerEmail = function(test) { + test.expect(1); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.committer(function commitCommitter(error, committer) { + committer.email(function committerName(error, email) { + test.equals(email, 'mike@pagesofinterest.net', 'The committer email should match expected value'); + test.done(); + }); + }); + }); + }); +}; + /** * Test that improper commit ID's result in an error message */ @@ -45,8 +172,6 @@ exports.improperCommitId = function(test) { }); }; -var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; - /** * Test that retreiving walking a given commit's history works as expected. */ @@ -77,13 +202,9 @@ exports.masterHead = function(test) { test.expect(2); git.repo('../.git', function(error, repository) { repository.branch('master', function(error, branch) { - test.equals(error, null, 'Getting branch should not error'); - - repository.commit(branch.sha, function(error, commit) { - + repository.commit(branch.sha, function(error, commit) { test.equals(error, null, 'Getting latest branch commit should not error'); - test.done(); }); }); From 7e5ee6e18d36126c0e2a9427cbbb72f8d1233ef5 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Jan 2001 13:31:25 +1300 Subject: [PATCH 066/186] Updated commit documentation, added more getters --- lib/commit.js | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index 421aa0193..9dc3629d3 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -10,7 +10,6 @@ var git = require( '../' ), * @return {Commit} */ var Commit = function(rawRepo, rawCommit) { - if (!(rawRepo instanceof git.raw.Repo)) { throw git.error('First parameter for Commit must be a raw repo'); } @@ -45,10 +44,20 @@ Commit.prototype.lookup = function(oid, callback) { }); }; +/** + * Retrieve the commit's Oid + * + * @param {Function} callback + */ Commit.prototype.oid = function(callback) { callback(null, new git.oid(this.rawCommit.oid())); }; +/** + * Retrieve the SHA + * + * @param {Function} callback + */ Commit.prototype.sha = function(callback) { this.rawCommit.sha(function(error, sha) { if (success(error, callback)) { @@ -57,6 +66,70 @@ Commit.prototype.sha = function(callback) { }); }; +/** + * Retrieve the message + * + * @param {Function} callback + */ +Commit.prototype.message = function(callback) { + this.rawCommit.message(function(error, message) { + if (success(error, callback)) { + callback(null, message); + } + }); +}; + +/** + * Retrieve the commit unix timestamp. + * + * @param {Function} callback + */ +Commit.prototype.time = function(callback) { + this.rawCommit.time(function(error, time) { + if (success(error, callback)) { + callback(null, time); + } + }); +}; + +/** + * Retrieve the commit's positive or negative timezone offset, in minutes from UTC. + * + * @param {Function} callback + */ +Commit.prototype.offset = function(callback) { + this.rawCommit.offset(function(error, offset) { + if (success(error, callback)) { + callback(null, offset); + } + }); +}; + +/** + * Retrieve the commit's author. + * + * @param {Function} callback + */ +Commit.prototype.author = function(callback) { + this.rawCommit.author(function(error, rawSignature) { + if (success(error, callback)) { + callback(null, new git.raw.signature(rawSignature)); + } + }); +}; + +/** + * Retrieve the commit's committer. + * + * @param {Function} callback + */ +Commit.prototype.committer = function(callback) { + this.rawCommit.committer(function(error, rawSignature) { + if (success(error, callback)) { + callback(null, new git.raw.signature(rawSignature)); + } + }); +}; /** * Retrieve the tree for this commit. * @@ -71,6 +144,19 @@ Commit.prototype.tree = function(callback) { }); }; +/** + * Retrieve the author of this commit. + * + * @param {Function} callback + */ +Commit.prototype.tree = function(callback) { + this.rawCommit.author(function(error, author) { + if (success(error, callback)) { + callback(null, author); + } + }); +}; + /** * Retrieve the file represented by path for this commit. * From 3111d39c92bfb5de8270ec0d49d4974e559f8f13 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Jan 2001 13:31:35 +1300 Subject: [PATCH 067/186] Added getters --- include/commit.h | 62 +++++++++- src/commit.cc | 305 +++++++++++++++++++++++++++++++---------------- 2 files changed, 262 insertions(+), 105 deletions(-) diff --git a/include/commit.h b/include/commit.h index 57881aec9..63151d395 100755 --- a/include/commit.h +++ b/include/commit.h @@ -58,6 +58,26 @@ class GitCommit : public ObjectWrap { static void ShaWork(uv_work_t* req); static void ShaAfterWork(uv_work_t* req); + static Handle Message(const Arguments& args); + static void MessageWork(uv_work_t* req); + static void MessageAfterWork(uv_work_t* req); + + static Handle Time(const Arguments& args); + static void TimeWork(uv_work_t* req); + static void TimeAfterWork(uv_work_t* req); + + static Handle Offset(const Arguments& args); + static void OffsetWork(uv_work_t* req); + static void OffsetAfterWork(uv_work_t* req); + + static Handle Author(const Arguments& args); + static void AuthorWork(uv_work_t* req); + static void AuthorAfterWork(uv_work_t* req); + + static Handle Committer(const Arguments& args); + static void CommitterWork(uv_work_t* req); + static void CommitterAfterWork(uv_work_t* req); + static Handle Tree(const Arguments& args); static void TreeWork(uv_work_t* req); static void TreeAfterWork(uv_work_t* req); @@ -91,6 +111,43 @@ class GitCommit : public ObjectWrap { Persistent callback; }; + struct MessageBaton { + uv_work_t request; + + git_commit* rawCommit; + std::string message; + + Persistent callback; + }; + + struct TimeBaton { + uv_work_t request; + + git_commit* rawCommit; + git_time_t time; + + Persistent callback; + }; + + struct SignatureBaton { + uv_work_t request; + + git_commit* rawCommit; + git_signature* signature; + + Persistent callback; + }; + + struct OffsetBaton { + uv_work_t request; + + git_commit* rawCommit; + int offset; + + Persistent callback; + }; + + struct TreeBaton { uv_work_t request; const git_error* error; @@ -101,11 +158,6 @@ class GitCommit : public ObjectWrap { Persistent callback; }; - /** - * Contains references to the current commit, parent commit (output) - * parent commit's index, also contains references to an error code post - * lookup, and a callback function to execute. - */ struct ParentBaton { uv_work_t request; const git_error* error; diff --git a/src/commit.cc b/src/commit.cc index e316fd00d..d4f45f53a 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -37,12 +37,16 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha); - - NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); - + NODE_SET_PROTOTYPE_METHOD(tpl, "message", Message); + NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time); + NODE_SET_PROTOTYPE_METHOD(tpl, "offset", Offset); + NODE_SET_PROTOTYPE_METHOD(tpl, "author", Author); + NODE_SET_PROTOTYPE_METHOD(tpl, "committer", Committer); NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); NODE_SET_PROTOTYPE_METHOD(tpl, "parent", Parent); + NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); + constructor_template = Persistent::New(tpl->GetFunction()); target->Set(String::NewSymbol("Commit"), constructor_template); } @@ -59,7 +63,6 @@ Handle GitCommit::New(const Arguments& args) { HandleScope scope; GitCommit *commit = new GitCommit(); - commit->Wrap(args.This()); return scope.Close(args.This()); @@ -68,30 +71,11 @@ Handle GitCommit::Close(const Arguments& args) { HandleScope scope; GitCommit *commit = ObjectWrap::Unwrap(args.This()); - commit->Close(); git_commit_free(commit->commit); commit->commit = NULL; return scope.Close(Undefined()); } - -// Handle GitCommit::FetchDetailsSync(const Arguments& args) { -// HandleScope scope; - -// GitCommit *commit = ObjectWrap::Unwrap(args.This()); -// git_commit* rawCommit = commit->GetValue(); - -// GitCommitDetails* details = new GitCommitDetails; -// details->oid = git_commit_id(rawCommit); - -// details->sha[GIT_OID_HEXSZ] = '\0'; -// git_oid_fmt(details->sha, details->oid); - -// details->message = git_commit_message(rawCommit); -// details->time = git_commit_time(rawCommit); -// details->timeOffset = git_commit_time_offset(rawCommit); -// details->committer = git_commit_committer(rawCommit); -// details->author = git_commit_author(rawCommit); // details->parentCount = git_commit_parentcount(rawCommit); // int parentCount = details->parentCount; @@ -107,83 +91,6 @@ Handle GitCommit::Close(const Arguments& args) { // return scope.Close(createCommitDetailsObject(details)); // } -// Handle GitCommit::FetchDetails(const Arguments& args) { -// HandleScope scope; - -// if(args.Length() == 0 || !args[0]->IsFunction()) { -// return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); -// } - -// FetchDetailsBaton* baton = new FetchDetailsBaton; -// baton->request.data = baton; -// baton->error = NULL; -// baton->details = new GitCommitDetails; -// baton->rawCommit = ObjectWrap::Unwrap(args.This())->commit; -// baton->callback = Persistent::New(Local::Cast(args[0])); - -// uv_queue_work(uv_default_loop(), &baton->request, FetchDetailsWork, (uv_after_work_cb)FetchDetailsAfterWork); - -// return Undefined(); -// } -// void GitCommit::FetchDetailsWork(uv_work_t *req) { -// FetchDetailsBaton* baton = static_cast(req->data); - -// GitCommitDetails* details = baton->details; -// details->oid = git_commit_id(baton->rawCommit); - -// details->sha[GIT_OID_HEXSZ] = '\0'; -// git_oid_fmt(details->sha, details->oid); - -// details->message = git_commit_message(baton->rawCommit); -// details->time = git_commit_time(baton->rawCommit); -// details->timeOffset = git_commit_time_offset(baton->rawCommit); -// details->committer = git_commit_committer(baton->rawCommit); -// details->author = git_commit_author(baton->rawCommit); -// details->parentCount = git_commit_parentcount(baton->rawCommit); - -// int parentCount = details->parentCount; -// while (parentCount > 0) { -// int parentIndex = parentCount -1; -// char sha[GIT_OID_HEXSZ + 1]; -// sha[GIT_OID_HEXSZ] = '\0'; -// const git_oid *parentOid = git_commit_parent_id(baton->rawCommit, parentIndex); -// git_oid_fmt(sha, parentOid); -// details->parentShas.push_back(sha); -// parentCount--; -// } -// } -// void GitCommit::FetchDetailsAfterWork(uv_work_t *req) { -// HandleScope scope; - -// FetchDetailsBaton* 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 argv[2] = { -// Local::New(Null()), -// createCommitDetailsObject(baton->details) -// }; - -// TryCatch try_catch; -// baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); -// if (try_catch.HasCaught()) { -// node::FatalException(try_catch); -// } -// } -// delete req; -// } Handle GitCommit::Lookup(const Arguments& args) { HandleScope scope; @@ -308,6 +215,204 @@ void GitCommit::ShaAfterWork(uv_work_t* req) { delete req; } +Handle GitCommit::Message(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + MessageBaton* baton = new MessageBaton; + baton->request.data = baton; + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, MessageWork, (uv_after_work_cb)MessageAfterWork); + + return Undefined(); +} +void GitCommit::MessageWork(uv_work_t* req) { + MessageBaton *baton = static_cast(req->data); + + baton->message = git_commit_message(baton->rawCommit); +} +void GitCommit::MessageAfterWork(uv_work_t* req) { + HandleScope scope; + MessageBaton *baton = static_cast(req->data); + + Handle argv[2] = { + Local::New(Null()), + String::New(baton->message.c_str()) + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; +} + +Handle GitCommit::Time(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + TimeBaton* baton = new TimeBaton; + baton->request.data = baton; + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, TimeWork, (uv_after_work_cb)TimeAfterWork); + + return Undefined(); +} +void GitCommit::TimeWork(uv_work_t* req) { + TimeBaton *baton = static_cast(req->data); + + baton->time = git_commit_time(baton->rawCommit); +} +void GitCommit::TimeAfterWork(uv_work_t* req) { + HandleScope scope; + TimeBaton *baton = static_cast(req->data); + + Handle argv[2] = { + Local::New(Null()), + Integer::New(baton->time) + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; +} + +Handle GitCommit::Offset(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + OffsetBaton* baton = new OffsetBaton; + baton->request.data = baton; + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, OffsetWork, (uv_after_work_cb)OffsetAfterWork); + + return Undefined(); +} +void GitCommit::OffsetWork(uv_work_t* req) { + OffsetBaton *baton = static_cast(req->data); + + baton->offset = git_commit_time_offset(baton->rawCommit); +} +void GitCommit::OffsetAfterWork(uv_work_t* req) { + HandleScope scope; + OffsetBaton *baton = static_cast(req->data); + + Handle argv[2] = { + Local::New(Null()), + Integer::New(baton->offset) + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; +} + +Handle GitCommit::Author(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + SignatureBaton* baton = new SignatureBaton; + baton->request.data = baton; + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, AuthorWork, (uv_after_work_cb)AuthorAfterWork); + + return Undefined(); +} +void GitCommit::AuthorWork(uv_work_t* req) { + SignatureBaton *baton = static_cast(req->data); + + baton->rawSignature = git_commit_author(baton->rawCommit); +} +void GitCommit::AuthorAfterWork(uv_work_t* req) { + HandleScope scope; + SignatureBaton *baton = static_cast(req->data); + + Local signature = GitSignature::constructor_template->NewInstance(); + GitSignature *signatureInstance = ObjectWrap::Unwrap(signature); + signatureInstance->SetValue(baton->rawSignature); + + Handle argv[2] = { + Local::New(Null()), + signature + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; +} + +Handle GitCommit::Committer(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + SignatureBaton* baton = new SignatureBaton; + baton->request.data = baton; + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, CommitterWork, (uv_after_work_cb)CommitterAfterWork); + + return Undefined(); +} +void GitCommit::CommitterWork(uv_work_t* req) { + SignatureBaton *baton = static_cast(req->data); + + baton->rawSignature = git_commit_committer(baton->rawCommit); +} +void GitCommit::CommitterAfterWork(uv_work_t* req) { + HandleScope scope; + SignatureBaton *baton = static_cast(req->data); + + Local signature = GitSignature::constructor_template->NewInstance(); + GitSignature *signatureInstance = ObjectWrap::Unwrap(signature); + signatureInstance->SetValue(baton->rawSignature); + + Handle argv[2] = { + Local::New(Null()), + signature + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; +} + Handle GitCommit::Tree(const Arguments& args) { HandleScope scope; From c781ad7d0391cf104a3611a92fff6930a97b8411 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Jan 2001 13:31:57 +1300 Subject: [PATCH 068/186] Renamed signature --- binding.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binding.gyp b/binding.gyp index 5f48fed38..368d36b11 100644 --- a/binding.gyp +++ b/binding.gyp @@ -12,7 +12,7 @@ 'src/reference.cc', 'src/repo.cc', 'src/revwalk.cc', - 'src/sig.cc', + 'src/signature.cc', 'src/tree.cc', 'src/tree_entry.cc', 'src/diff_list.cc', From ba44a6e9885dc37c4ac0b663d22ece156a858053 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Jan 2001 13:32:07 +1300 Subject: [PATCH 069/186] Whitespace --- src/signature.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/signature.cc b/src/signature.cc index b93ab3137..6df492849 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -16,7 +16,7 @@ using namespace v8; using namespace node; -void GitSignature::Initialize (Handle target) { +void GitSignature::Initialize(Handle target) { Local tpl = FunctionTemplate::New(New); tpl->InstanceTemplate()->SetInternalFieldCount(1); From 0f96843551b68032b9d475d9a7c4632b2aeda8d6 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 10:55:33 +1300 Subject: [PATCH 070/186] Updated author & committer methods --- src/commit.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commit.cc b/src/commit.cc index d4f45f53a..50b0838d3 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -13,7 +13,7 @@ #include "cvv8/v8-convert.hpp" #include "../include/reference.h" -#include "../include/sig.h" +#include "../include/signature.h" #include "../include/repo.h" #include "../include/oid.h" #include "../include/tree.h" @@ -355,8 +355,8 @@ void GitCommit::AuthorAfterWork(uv_work_t* req) { SignatureBaton *baton = static_cast(req->data); Local signature = GitSignature::constructor_template->NewInstance(); - GitSignature *signatureInstance = ObjectWrap::Unwrap(signature); - signatureInstance->SetValue(baton->rawSignature); + GitSignature *signatureInstance = ObjectWrap::Unwrap(signature); + signatureInstance->SetValue(const_cast(baton->rawSignature)); Handle argv[2] = { Local::New(Null()), @@ -397,8 +397,8 @@ void GitCommit::CommitterAfterWork(uv_work_t* req) { SignatureBaton *baton = static_cast(req->data); Local signature = GitSignature::constructor_template->NewInstance(); - GitSignature *signatureInstance = ObjectWrap::Unwrap(signature); - signatureInstance->SetValue(baton->rawSignature); + GitSignature *signatureInstance = ObjectWrap::Unwrap(signature); + signatureInstance->SetValue(const_cast(baton->rawSignature)); Handle argv[2] = { Local::New(Null()), From 86f0f62448a9aafe714b506e8de1f7b35d968896 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 10:55:45 +1300 Subject: [PATCH 071/186] Rename sig.h to signature.h --- src/signature.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/signature.cc b/src/signature.cc index 6df492849..a74109db0 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -11,7 +11,7 @@ #include "../vendor/libgit2/include/git2.h" #include "../include/repo.h" -#include "../include/sig.h" +#include "../include/signature.h" using namespace v8; using namespace node; From ef1f54063e1064e2600dd3d3c916abfef37ed9ce Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:39:07 +1300 Subject: [PATCH 072/186] Updated convenience commit tests --- test/convenience-commit.js | 46 +++++++++++++------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index de78ed9c1..2e2839564 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -91,7 +91,7 @@ exports.offset = function(test) { }; exports.author = function(test) { - test.expect(3); + test.expect(2); git.repo('../.git', function(error, repository) { repository.commit(historyCountKnownSHA, function(error, commit) { commit.author(function(error, author) { @@ -123,7 +123,7 @@ exports.authorEmail = function(test) { repository.commit(historyCountKnownSHA, function(error, commit) { commit.author(function commitAuthor(error, author) { author.email(function authorName(error, email) { - test.equals(email, 'mike@pagesofinterest.net', 'The author email should match expected value'); + test.equals(email, 'mike@panmedia.co.nz', 'The author email should match expected value'); test.done(); }); }); @@ -151,7 +151,7 @@ exports.committerEmail = function(test) { repository.commit(historyCountKnownSHA, function(error, commit) { commit.committer(function commitCommitter(error, committer) { committer.email(function committerName(error, email) { - test.equals(email, 'mike@pagesofinterest.net', 'The committer email should match expected value'); + test.equals(email, 'mike@panmedia.co.nz', 'The committer email should match expected value'); test.done(); }); }); @@ -203,9 +203,11 @@ exports.masterHead = function(test) { git.repo('../.git', function(error, repository) { repository.branch('master', function(error, branch) { test.equals(error, null, 'Getting branch should not error'); - repository.commit(branch.sha, function(error, commit) { - test.equals(error, null, 'Getting latest branch commit should not error'); - test.done(); + branch.sha(function(error, sha) { + repository.commit(sha, function(error, commit) { + test.equals(error, null, 'Getting latest branch commit should not error'); + test.done(); + }); }); }); }); @@ -216,32 +218,16 @@ exports.masterHead = function(test) { * * @param {Object} test */ -exports.parentSync = function(test) { +exports.parents = function(test) { test.expect(2); git.repo('../.git', function(error, repository) { - repository.commit('2d71044741412280370cb0326c96d3a5a7b5dca1', function(error, commit) { - test.equals(commit.parentCount, 1, 'Commit has exactly one parent'); - var parent = commit.parentSync(0); - test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value'); - test.done(); - }); - }); -}; - -/** - * Test that retreiving parent works as expected. - * - * @param {Object} test - */ -exports.parent = function(test) { - test.expect(2); - git.repo('../.git', function(error, repository) { - repository.commit('2d71044741412280370cb0326c96d3a5a7b5dca1', function(error, commit) { - test.equals(commit.parentCount, 1, 'Commit has exactly one parent'); - commit.parent(0, function(error, parent) { - if (error) throw error; - test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value'); - test.done(); + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.parents(function(error, parents) { + test.equals(parents.length, 1, 'Commit should have exactly one parent'); + parents[0].sha(function parentSha(error, sha) { + test.equals(sha, '', 'Parent SHA should match expected value'); + test.done(); + }); }); }); From 2602ee8a900fad2fb63e25c17e3e982c60812789 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:41:52 +1300 Subject: [PATCH 073/186] Updated signature header --- include/signature.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/signature.h b/include/signature.h index 88229fe65..483db8415 100755 --- a/include/signature.h +++ b/include/signature.h @@ -25,21 +25,21 @@ class GitSignature : public ObjectWrap { static void Initialize(Handle target); git_signature* GetValue(); - void SetValue(git_signature* GitSignature); + void SetValue(git_signature* signature); protected: GitSignature() {}; ~GitSignature() {}; static Handle New(const Arguments& args); - static Handle Dup(const Arguments& args); + static Handle Duplicate(const Arguments& args); static Handle Free(const Arguments& args); static Handle Name(const Arguments& args); static Handle Email(const Arguments& args); private: - git_signature* sig; + git_signature* signature; }; #endif From 2d8258ea2a273f2b8963b0c81b16b411e7de1828 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:42:08 +1300 Subject: [PATCH 074/186] Updated signature methods --- src/signature.cc | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/signature.cc b/src/signature.cc index a74109db0..72e4338f8 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -33,7 +33,7 @@ void GitSignature::Initialize(Handle target) { } git_signature* GitSignature::GetValue() { - return this->sig; + return this->signature; } void GitSignature::SetValue(git_signature* signature) { @@ -49,30 +49,26 @@ Handle GitSignature::New(const Arguments& args) { return scope.Close(args.This()); } -Handle GitSignature::Duplicate(const Arguments& args) { +Handle GitSignature::Free(const Arguments& args) { HandleScope scope; - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("GitSignature is required and must be an Object."))); - } - - Local duplicateSignature = GitSignature::constructor_template->NewInstance(); - GitSignature *duplicateSignatureInstance = ObjectWrap::Unwrap(signature); - - GitSignature* signature = ObjectWrap::Unwrap(args[0]->ToObject()); - - duplicateSignatureInstance->SetValue(git_signature_dup(signature->GetValue())); + GitSignature *signature = ObjectWrap::Unwrap(args.This()); + git_signature_free(signature->signature); + signature->signature = NULL; - return duplicateSignature; + return Undefined(); } -Handle GitSignature::Free(const Arguments& args) { +Handle GitSignature::Duplicate(const Arguments& args) { HandleScope scope; - GitSignature *signature = ObjectWrap::Unwrap(args.This()); - git_signature_free(this->signature); + Local duplicateSignature = GitSignature::constructor_template->NewInstance(); + GitSignature *duplicateSignatureInstance = ObjectWrap::Unwrap(duplicateSignature); - return Undefined(); + GitSignature* signature = ObjectWrap::Unwrap(args.This()); + duplicateSignatureInstance->SetValue(git_signature_dup(signature->GetValue())); + + return duplicateSignature; } Handle GitSignature::Name(const Arguments& args) { @@ -80,7 +76,7 @@ Handle GitSignature::Name(const Arguments& args) { GitSignature *signature = ObjectWrap::Unwrap(args.This()); - return String::New(signature->Name()); + return scope.Close(String::New(signature->GetValue()->name)); } Handle GitSignature::Email(const Arguments& args) { @@ -88,7 +84,7 @@ Handle GitSignature::Email(const Arguments& args) { GitSignature *signature = ObjectWrap::Unwrap(args.This()); - return String::New(signature->Email()); + return scope.Close(String::New(signature->GetValue()->email)); } Persistent GitSignature::constructor_template; From 72923b1ff0433ff09bbd608832f75743b2de0623 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:42:45 +1300 Subject: [PATCH 075/186] Renamed sig to signature --- lib/signature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/signature.js b/lib/signature.js index 78bda123e..c33f91b13 100644 --- a/lib/signature.js +++ b/lib/signature.js @@ -20,4 +20,4 @@ Signature.prototype.duplicate = function(callback) { callback(null, new Signature(git.rawSignature.duplicate())); }; -exports.sig = Signature; +exports.signature = Signature; From c073674b24ee8dfb094c1832a701adff31c302a4 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:46:48 +1300 Subject: [PATCH 076/186] Fixed commit signature getter --- lib/commit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 9dc3629d3..0a3026eec 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -113,7 +113,7 @@ Commit.prototype.offset = function(callback) { Commit.prototype.author = function(callback) { this.rawCommit.author(function(error, rawSignature) { if (success(error, callback)) { - callback(null, new git.raw.signature(rawSignature)); + callback(null, new git.signature(rawSignature)); } }); }; @@ -126,7 +126,7 @@ Commit.prototype.author = function(callback) { Commit.prototype.committer = function(callback) { this.rawCommit.committer(function(error, rawSignature) { if (success(error, callback)) { - callback(null, new git.raw.signature(rawSignature)); + callback(null, new git.signature(rawSignature)); } }); }; From f68c285f68fd731610e1dd610879111fd154b305 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:47:35 +1300 Subject: [PATCH 077/186] Updated commit parents --- lib/commit.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 0a3026eec..73473623c 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -208,14 +208,19 @@ Commit.prototype.history = function() { }; /** - * Retrieve the commit's parent at the given position asynchronously. + * Retrieve the commit's parents. * - * @param {Integer} position + * @param {Function} callback */ -Commit.prototype.parent = function(position, callback) { - self.rawCommit.parent(position, function processParent(error, rawParent) { +Commit.prototype.parents = function(callback) { + var self = this; + self.rawCommit.parents(function processParent(error, rawParents) { if (success(error, callback)) { - callback(null, new Commit(this.rawRepo, rawParent)); + var parents = []; + rawParents.forEach(function eachParent(rawParent) { + parents.push(new Commit(self.rawRepo, rawParent)); + }); + callback(null, parents); } }); }; From 9ca1e6ac43869d98eaa7c3fe9a1d90e443a1998f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:47:56 +1300 Subject: [PATCH 078/186] Updated commit header for new parents method --- include/commit.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/include/commit.h b/include/commit.h index 63151d395..3ca1e914d 100755 --- a/include/commit.h +++ b/include/commit.h @@ -40,13 +40,14 @@ class GitCommit : public ObjectWrap { git_commit* GetValue(); void SetValue(git_commit* commit); + void SetOid(git_oid* oid); protected: GitCommit() {} ~GitCommit() {} static Handle New(const Arguments& args); - static Handle Close(const Arguments& args); + static Handle Free(const Arguments& args); static Handle Lookup(const Arguments& args); static void LookupWork(uv_work_t *req); @@ -82,9 +83,9 @@ class GitCommit : public ObjectWrap { static void TreeWork(uv_work_t* req); static void TreeAfterWork(uv_work_t* req); - static Handle Parent(const Arguments& args); - static void ParentWork(uv_work_t* req); - static void ParentAfterWork(uv_work_t* req); + static Handle Parents(const Arguments& args); + static void ParentsWork(uv_work_t* req); + static void ParentsAfterWork(uv_work_t* req); private: git_commit* commit; @@ -133,7 +134,7 @@ class GitCommit : public ObjectWrap { uv_work_t request; git_commit* rawCommit; - git_signature* signature; + const git_signature* rawSignature; Persistent callback; }; @@ -158,15 +159,19 @@ class GitCommit : public ObjectWrap { Persistent callback; }; - struct ParentBaton { + struct Parent { + const git_oid* rawOid; + git_commit* rawCommit; + }; + + struct ParentsBaton { uv_work_t request; const git_error* error; int index; git_commit* rawCommit; - git_commit* rawParentCommit; + std::vector parents; Persistent callback; }; - }; From 681a8c435542f65d88a8f2d9d503f17d59de3528 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:48:30 +1300 Subject: [PATCH 079/186] Renamed close to free --- src/commit.cc | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/commit.cc b/src/commit.cc index 50b0838d3..af802cdfe 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -45,7 +45,7 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); NODE_SET_PROTOTYPE_METHOD(tpl, "parent", Parent); - NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); + NODE_SET_PROTOTYPE_METHOD(tpl, "free", Free); constructor_template = Persistent::New(tpl->GetFunction()); target->Set(String::NewSymbol("Commit"), constructor_template); @@ -67,30 +67,15 @@ Handle GitCommit::New(const Arguments& args) { return scope.Close(args.This()); } -Handle GitCommit::Close(const Arguments& args) { +Handle GitCommit::Free(const Arguments& args) { HandleScope scope; GitCommit *commit = ObjectWrap::Unwrap(args.This()); git_commit_free(commit->commit); commit->commit = NULL; - return scope.Close(Undefined()); + return Undefined(); } -// details->parentCount = git_commit_parentcount(rawCommit); - -// int parentCount = details->parentCount; -// while (parentCount > 0) { -// int parentIndex = parentCount -1; -// char sha[GIT_OID_HEXSZ + 1]; -// sha[GIT_OID_HEXSZ] = '\0'; -// const git_oid *parentOid = git_commit_parent_id(rawCommit, parentIndex); -// git_oid_fmt(sha, parentOid); -// details->parentShas.push_back(sha); -// parentCount--; -// } - -// return scope.Close(createCommitDetailsObject(details)); -// } Handle GitCommit::Lookup(const Arguments& args) { HandleScope scope; From e90169a8d73e7bf56193d13867509a79e17a04b8 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:49:42 +1300 Subject: [PATCH 080/186] Updated parents method --- src/commit.cc | 79 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/src/commit.cc b/src/commit.cc index af802cdfe..f0f15ac83 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -43,7 +43,7 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "author", Author); NODE_SET_PROTOTYPE_METHOD(tpl, "committer", Committer); NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); - NODE_SET_PROTOTYPE_METHOD(tpl, "parent", Parent); + NODE_SET_PROTOTYPE_METHOD(tpl, "parents", Parents); NODE_SET_PROTOTYPE_METHOD(tpl, "free", Free); @@ -54,10 +54,12 @@ void GitCommit::Initialize(Handle target) { git_commit* GitCommit::GetValue() { return this->commit; } - void GitCommit::SetValue(git_commit* commit) { this->commit = commit; } +void GitCommit::SetOid(git_oid* oid) { + this->oid = oid; +} Handle GitCommit::New(const Arguments& args) { HandleScope scope; @@ -134,7 +136,7 @@ void GitCommit::LookupAfterWork(uv_work_t *req) { Local commit = GitCommit::constructor_template->NewInstance(); GitCommit *commitInstance = ObjectWrap::Unwrap(commit); commitInstance->SetValue(baton->rawCommit); - commitInstance->oid = &baton->rawOid; + commitInstance->SetOid(&baton->rawOid); Handle argv[2] = { Local::New(Null()), @@ -180,7 +182,6 @@ void GitCommit::ShaWork(uv_work_t* req) { ShaBaton *baton = static_cast(req->data); baton->sha[GIT_OID_HEXSZ] = '\0'; - git_oid_fmt(baton->sha, baton->rawOid); } void GitCommit::ShaAfterWork(uv_work_t* req) { @@ -446,54 +447,70 @@ void GitCommit::TreeAfterWork(uv_work_t* req) { delete req; } -Handle GitCommit::Parent(const Arguments& args) { +Handle GitCommit::Parents(const Arguments& args) { HandleScope scope; - if(args.Length() != 2) { - return ThrowException(Exception::Error(String::New("Position and callback are required"))); - } - - if(!args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Position is required and must be a Number."))); - } - - if(!args[1]->IsFunction()) { + if(args.Length() == 0 && !args[0]->IsFunction()) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - ParentBaton* baton = new ParentBaton(); + ParentsBaton* baton = new ParentsBaton; baton->request.data = baton; - baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); baton->error = NULL; - baton->rawParentCommit = NULL; - baton->index = args[0]->ToInteger()->Value(); - baton->callback = Persistent::New(Local::Cast(args[1])); + baton->rawCommit = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); - uv_queue_work(uv_default_loop(), &baton->request, ParentWork, (uv_after_work_cb)ParentAfterWork); + uv_queue_work(uv_default_loop(), &baton->request, ParentsWork, (uv_after_work_cb)ParentsAfterWork); return Undefined(); } -void GitCommit::ParentWork(uv_work_t* req) { - ParentBaton* baton = static_cast(req->data); +void GitCommit::ParentsWork(uv_work_t* req) { + ParentsBaton* baton = static_cast(req->data); - int returnCode = git_commit_parent(&baton->rawParentCommit, baton->rawCommit, baton->index); + int parentCount = git_commit_parentcount(baton->rawCommit); + while (parentCount > 0) { + git_commit* rawParentCommit = NULL; - if (returnCode != GIT_OK) { - baton->error = giterr_last(); + int parentIndex = parentCount -1; + int returnCode = git_commit_parent(&rawParentCommit, baton->rawCommit, parentIndex); + + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + return; + } + + const git_oid* rawParentOid = git_commit_id(rawParentCommit); + + Parent* parent = new Parent; + parent->rawCommit = rawParentCommit; + parent->rawOid = rawParentOid; + + baton->parents.push_back(parent); + + parentCount--; } } -void GitCommit::ParentAfterWork(uv_work_t* req) { +void GitCommit::ParentsAfterWork(uv_work_t* req) { HandleScope scope; - ParentBaton* baton = static_cast(req->data); + ParentsBaton* baton = static_cast(req->data); if (success(baton->error, baton->callback)) { - Local parent = GitCommit::constructor_template->NewInstance(); - GitCommit *parentInstance = ObjectWrap::Unwrap(parent); - parentInstance->SetValue(baton->rawParentCommit); + std::vector > parents; + + for(std::vector::iterator parentIterator = baton->parents.begin(); parentIterator != baton->parents.end(); ++parentIterator) { + Parent *parentData = (*parentIterator); + + Local parent = GitCommit::constructor_template->NewInstance(); + GitCommit *parentInstance = ObjectWrap::Unwrap(parent); + parentInstance->SetValue(parentData->rawCommit); + parentInstance->SetOid(const_cast(parentData->rawOid)); + + parents.push_back(parent); + } Handle argv[2] = { Local::New(Null()), - parent + cvv8::CastToJS(parents) }; TryCatch try_catch; From 1f6acbfa0c9a3cebd0b78958955185b748766830 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:57:10 +1300 Subject: [PATCH 081/186] Whitespace --- lib/commit.js | 14 +------------- src/commit.cc | 1 + 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 73473623c..732d8643d 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -130,6 +130,7 @@ Commit.prototype.committer = function(callback) { } }); }; + /** * Retrieve the tree for this commit. * @@ -144,19 +145,6 @@ Commit.prototype.tree = function(callback) { }); }; -/** - * Retrieve the author of this commit. - * - * @param {Function} callback - */ -Commit.prototype.tree = function(callback) { - this.rawCommit.author(function(error, author) { - if (success(error, callback)) { - callback(null, author); - } - }); -}; - /** * Retrieve the file represented by path for this commit. * diff --git a/src/commit.cc b/src/commit.cc index f0f15ac83..139842885 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -419,6 +419,7 @@ Handle GitCommit::Tree(const Arguments& args) { } void GitCommit::TreeWork(uv_work_t* req) { TreeBaton* baton = static_cast(req->data); + int returnCode = git_commit_tree(&baton->rawTree, baton->rawCommit); if (returnCode != GIT_OK) { baton->error = giterr_last(); From 2741df1974238cf76a9811044338a96f8ec69c62 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 21:57:41 +1300 Subject: [PATCH 082/186] Updated convenience-commit test --- test/convenience-commit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index 2e2839564..328f6aff1 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -219,13 +219,14 @@ exports.masterHead = function(test) { * @param {Object} test */ exports.parents = function(test) { - test.expect(2); + test.expect(3); git.repo('../.git', function(error, repository) { repository.commit(historyCountKnownSHA, function(error, commit) { commit.parents(function(error, parents) { test.equals(parents.length, 1, 'Commit should have exactly one parent'); parents[0].sha(function parentSha(error, sha) { - test.equals(sha, '', 'Parent SHA should match expected value'); + test.equals(error, null, 'Getting parent SHA should not error'); + test.equals(sha, 'ecfd36c80a3e9081f200dfda2391acadb56dac27', 'Parent SHA should match expected value'); test.done(); }); }); From cb1d6dd4bfa2d6cbd966d7351f5c73117708a2c1 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 22:02:55 +1300 Subject: [PATCH 083/186] Cleaned out tree --- include/tree.h | 68 +----------------- src/tree.cc | 184 ------------------------------------------------- 2 files changed, 1 insertion(+), 251 deletions(-) diff --git a/include/tree.h b/include/tree.h index bdf62ac55..b4ada4ae5 100755 --- a/include/tree.h +++ b/include/tree.h @@ -48,88 +48,22 @@ class GitTree : public ObjectWrap { * @param obj a git_tree object */ void SetValue(git_tree* tree); - /** - * Lookup a tree object from a repository. - * - * @param repo the repo to use when locating the tree. - * @param id identity of the tree to locate. - * - * @return 0 on success; error code otherwise - */ - int Lookup(git_repository* repo, const git_oid* id); - /** - * Get number of entries in the looked up tree. - * - * @return number of entries - */ - size_t EntryCount(); - /** - * Get entry by index in the looked up tree. - * - * @param idx index of the entry - * - * @return git tree entry - */ - git_tree_entry* EntryByIndex(int idx); - - int SortEntries(); - void ClearEntries(); protected: - /** - * Constructor - */ GitTree() {}; - /** - * Deconstructor - */ ~GitTree() {}; - /** - * Creates a new instance of GitTree to Node.js - * - * @param args v8::Arguments function call arguments from Node.js - * - * @return v8::Object args.This() - */ + 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 Handle EntryCount(const Arguments& args); - static Handle EntryByIndex(const Arguments& args); - static void EIO_EntryByIndex(uv_work_t *req); - static void EIO_AfterEntryByIndex(uv_work_t *req); static Handle EntryByPath(const Arguments& args); static void EntryByPathWork(uv_work_t *req); static void EntryByPathAfterWork(uv_work_t *req); - static Handle SortEntries(const Arguments& args); - static Handle ClearEntries(const Arguments& args); private: /** * Internal reference to git_tree object */ git_tree* tree; - /** - * Structure to handle async lookups - */ - struct lookup_request { - GitTree* tree; - GitRepo* repo; - GitOid* oid; - int err; - Persistent callback; - }; - /** - * Structure to handle async entryByIndex - */ - struct entryindex_request { - GitTree* tree; - GitTreeEntry* entry; - int idx; - Persistent callback; - }; struct EntryByPathBaton { uv_work_t request; diff --git a/src/tree.cc b/src/tree.cc index c108d1be0..b16832cb8 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -30,11 +30,7 @@ void GitTree::Initialize (Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("Tree")); - NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); - NODE_SET_PROTOTYPE_METHOD(tpl, "entryCount", EntryCount); - NODE_SET_PROTOTYPE_METHOD(tpl, "entryByIndex", EntryByIndex); NODE_SET_PROTOTYPE_METHOD(tpl, "entryByPath", EntryByPath); - NODE_SET_PROTOTYPE_METHOD(tpl, "sortEntries", EntryCount); constructor_template = Persistent::New(tpl->GetFunction()); target->Set(String::NewSymbol("Tree"), constructor_template); @@ -43,28 +39,10 @@ void GitTree::Initialize (Handle target) { git_tree* GitTree::GetValue() { return this->tree; } - void GitTree::SetValue(git_tree* tree) { this->tree = tree; } -int GitTree::Lookup(git_repository* repo, const git_oid* id) { - return git_tree_lookup(&this->tree, repo, id); -} - -size_t GitTree::EntryCount() { - return git_tree_entrycount(this->tree); -} - -git_tree_entry* GitTree::EntryByIndex(int idx) { - return const_cast(git_tree_entry_byindex(this->tree, idx)); -} - -int GitTree::SortEntries() { - //return git_tree_sort_entries(this->tree); - return 0; -} - Handle GitTree::New(const Arguments& args) { HandleScope scope; @@ -75,149 +53,6 @@ Handle GitTree::New(const Arguments& args) { return scope.Close(args.This()); } -Handle GitTree::Lookup(const Arguments& args) { - HandleScope scope; - - GitTree *tree = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); - } - - if(args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid is required and must be an Object."))); - } - - GitRepo* repo = ObjectWrap::Unwrap(args[0]->ToObject()); - GitOid* oid = ObjectWrap::Unwrap(args[1]->ToObject()); - - git_oid ref_oid = oid->GetValue(); - int err = tree->Lookup(repo->GetValue(), &ref_oid); - - return scope.Close( Integer::New(err) ); - -// if(args.Length() == 2 || !args[2]->IsFunction()) { -// return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); -// } -// -// callback = Local::Cast(args[2]); -// -// lookup_request *lr = new lookup_request(); -// lr->tree = tree; -// lr->repo = ObjectWrap::Unwrap(args[0]->ToObject()); -// lr->oid = ObjectWrap::Unwrap(args[1]->ToObject()); -// lr->callback = Persistent::New(callback); -// -// tree->Ref(); -// -// eio_custom(EIO_Lookup, EIO_PRI_DEFAULT, EIO_AfterLookup, lr); -// ev_ref(EV_DEFAULT_UC); -// -// return scope.Close( Undefined() ); -} - -//void GitTree::EIO_Lookup(uv_work_t *req) { -// lookup_request *lr = static_cast(req->data); -// -// git_oid oid = lr->oid->GetValue(); -// lr->err = lr->tree->Lookup(lr->repo->GetValue(), &oid); -// -// return 0; -//} - -//void GitTree::EIO_AfterLookup(uv_work_t *req) { -// lookup_request *lr = static_cast(req->data); -// -// ev_unref(EV_DEFAULT_UC); -// lr->tree->Unref(); -// -// Handle argv[1]; -// argv[0] = Integer::New(lr->err); -// -// TryCatch try_catch; -// -// lr->callback->Call(Context::GetCurrent()->Global(), 1, argv); -// -// if(try_catch.HasCaught()) -// FatalException(try_catch); -// -// lr->callback.Dispose(); -// -// delete lr; -// -// return 0; -//} - -Handle GitTree::EntryCount(const Arguments& args) { - HandleScope scope; - - GitTree *tree = ObjectWrap::Unwrap(args.This()); - - int count = tree->EntryCount(); - - return scope.Close( Integer::New(count) ); -} - -Handle GitTree::EntryByIndex(const Arguments& args) { - HandleScope scope; - - GitTree *tree = ObjectWrap::Unwrap(args.This()); - Local callback; - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("TreeEntry is required and must be a Object."))); - } - - if(args.Length() == 1 || !args[1]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Index is required and must be a Number."))); - } - - if(args.Length() == 2 || !args[2]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); - } - - callback = Local::Cast(args[2]); - - entryindex_request *er = new entryindex_request(); - er->tree = tree; - er->entry = ObjectWrap::Unwrap(args[0]->ToObject()); - er->idx = args[1]->ToInteger()->Value(); - er->callback = Persistent::New(callback); - - tree->Ref(); - - uv_work_t *req = new uv_work_t; - req->data = er; - uv_queue_work(uv_default_loop(), req, EIO_EntryByIndex, (uv_after_work_cb)EIO_AfterEntryByIndex); - - return scope.Close( Undefined() ); -} - -void GitTree::EIO_EntryByIndex(uv_work_t *req) { - entryindex_request *er = static_cast(req->data); - - er->entry->SetValue(er->tree->EntryByIndex(er->idx)); -} - -void GitTree::EIO_AfterEntryByIndex(uv_work_t *req) { - entryindex_request *er = static_cast(req->data); - - Handle argv[0]; - - TryCatch try_catch; - - er->callback->Call(Context::GetCurrent()->Global(), 0, argv); - - if(try_catch.HasCaught()) - FatalException(try_catch); - - er->callback.Dispose(); - - delete req; - er->tree->Unref(); - delete er; -} - Handle GitTree::EntryByPath(const Arguments& args) { HandleScope scope; @@ -276,23 +111,4 @@ void GitTree::EntryByPathAfterWork(uv_work_t *req) { delete req; } -Handle GitTree::SortEntries(const Arguments& args) { - HandleScope scope; - - GitTree *tree = ObjectWrap::Unwrap(args.This()); - - int err = tree->SortEntries(); - - return scope.Close( Integer::New(err) ); -} - -Handle GitTree::ClearEntries(const Arguments& args) { - HandleScope scope; - - //GitTree *tree = ObjectWrap::Unwrap(args.This()); - - //tree->ClearEntries(); - - return scope.Close( Undefined() ); -} Persistent GitTree::constructor_template; From 589af77a9b0861632e3ce1337cf47a2779470c32 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 22:13:19 +1300 Subject: [PATCH 084/186] Tidied up diff_list.cc --- src/diff_list.cc | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/diff_list.cc b/src/diff_list.cc index 46d14db47..00ff8eaa5 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -114,17 +114,12 @@ Handle GitDiffList::New(const Arguments& args) { return scope.Close(args.This()); } - -void GitDiffList::Close() { - git_diff_list_free(this->diffList); - this->diffList = NULL; -} - -Handle GitDiffList::Close(const Arguments& args) { +Handle GitDiffList::Free(const Arguments& args) { HandleScope scope; GitDiffList *diffList = ObjectWrap::Unwrap(args.This()); - diffList->Close(); + git_diff_list_free(diffList->diffList); + diffList->diffList = NULL; return scope.Close(Undefined()); } @@ -265,7 +260,7 @@ void GitDiffList::TreeToTreeAfterWork(uv_work_t *req) { Handle GitDiffList::Walk(const Arguments& args) { HandleScope scope; - GitDiffList* diffList = ObjectWrap::Unwrap(args.This()); + GitDiffList* diffList = ObjectWrap::Unwrap(args.This()); if (diffList->GetValue() == NULL) { return ThrowException(Exception::Error(String::New("No diff list to Walk."))); @@ -288,7 +283,7 @@ Handle GitDiffList::Walk(const Arguments& args) { } - WalkBaton* baton = new WalkBaton(); + WalkBaton* baton = new WalkBaton; uv_async_init(uv_default_loop(), &baton->asyncFile, WalkWorkSendFile); uv_async_init(uv_default_loop(), &baton->asyncHunk, WalkWorkSendHunk); uv_async_init(uv_default_loop(), &baton->asyncData, WalkWorkSendData); @@ -308,7 +303,6 @@ Handle GitDiffList::Walk(const Arguments& args) { return Undefined(); } - void GitDiffList::WalkWork(void *payload) { WalkBaton *baton = static_cast(payload); @@ -326,7 +320,6 @@ void GitDiffList::WalkWork(void *payload) { baton->asyncEnd.data = baton; uv_async_send(&baton->asyncEnd); } - int GitDiffList::WalkWorkFile(const git_diff_delta *delta, float progress, void *payload) { WalkBaton *baton = static_cast(payload); @@ -358,17 +351,15 @@ int GitDiffList::WalkWorkFile(const git_diff_delta *delta, float progress, baton->fileDeltas[key] = newDelta; uv_mutex_unlock(&baton->mutex); - if ((unsigned int)baton->fileDeltas.size() == (unsigned int)GitDiffList::WALK_DELTA_THRESHHOLD) { + if ((unsigned int)baton->fileDeltas.size() == (unsigned int)GitDiffList::WALK_DELTA_SEND_THRESHHOLD) { uv_async_send(&baton->asyncFile); } return GIT_OK; } - int GitDiffList::WalkWorkHunk(const git_diff_delta *delta, const git_diff_range *range, const char *header, size_t header_len, void *payload) { return GIT_OK; } - int GitDiffList::WalkWorkData(const git_diff_delta *delta, const git_diff_range *range, char line_origin, const char *content, size_t content_len, void *payload) { @@ -393,7 +384,6 @@ int GitDiffList::WalkWorkData(const git_diff_delta *delta, const git_diff_range return GIT_OK; } - void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) { HandleScope scope; @@ -483,7 +473,6 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) { } } } - void GitDiffList::WalkWorkSendHunk(uv_async_t *handle, int status /*UNUSED*/) { } void GitDiffList::WalkWorkSendData(uv_async_t *handle, int status /*UNUSED*/) { } void GitDiffList::WalkWorkSendEnd(uv_async_t *handle, int status /*UNUSED*/) { From 8ca2d9556dee3c90aae525a431481e44b9a30282 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 22:13:31 +1300 Subject: [PATCH 085/186] Removed some useless code --- include/diff_list.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/include/diff_list.h b/include/diff_list.h index 429c96145..4e048504f 100644 --- a/include/diff_list.h +++ b/include/diff_list.h @@ -24,30 +24,21 @@ using namespace v8; class GitDiffList : public ObjectWrap { public: - /** - * v8::FunctionTemplate used to create Node.js constructor - */ static Persistent constructor_template; - static const int WALK_DELTA_THRESHHOLD = 10; + static const int WALK_DELTA_SEND_THRESHHOLD = 10; - /** - * Used to intialize the EventEmitter from Node.js - * - * @param target v8::Object the Node.js module object - */ static void Initialize (Handle target); git_diff_list* GetValue(); void SetValue(git_diff_list* diffList); - void Close(); protected: GitDiffList() {} ~GitDiffList() {} static Handle New(const Arguments& args); - static Handle Close(const Arguments& args); + static Handle Free(const Arguments& args); static Handle TreeToTree(const Arguments& args); static void TreeToTreeWork(uv_work_t *req); @@ -81,8 +72,6 @@ class GitDiffList : public ObjectWrap { private: git_diff_list* diffList; - // git_oid* oldOid; - // git_oid* newOid; struct TreeToTreeBaton { uv_work_t request; From 0af5bbb78994f29e68e2e6086603957a7873c949 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Mon, 1 Apr 2013 22:13:41 +1300 Subject: [PATCH 086/186] Removed unecessary () --- src/repo.cc | 2 +- src/revwalk.cc | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/repo.cc b/src/repo.cc index b1d6d5db9..8478bb3d2 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -151,7 +151,7 @@ Handle GitRepo::Init(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - InitBaton *baton = new InitBaton(); + InitBaton *baton = new InitBaton; baton->request.data = baton; baton->error = NULL; baton->repo = ObjectWrap::Unwrap(args.This()); diff --git a/src/revwalk.cc b/src/revwalk.cc index 23a9d96c6..b79bcb340 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -109,7 +109,7 @@ Handle GitRevWalk::Push(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - PushBaton* baton = new PushBaton(); + PushBaton* baton = new PushBaton; baton->request.data = baton; baton->revwalk = ObjectWrap::Unwrap(args.This())->GetValue(); @@ -158,7 +158,7 @@ Handle GitRevWalk::Next(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - NextBaton* baton = new NextBaton(); + NextBaton* baton = new NextBaton; baton->request.data = baton; baton->revwalk = ObjectWrap::Unwrap(args.This())->GetValue(); From 913997728303a824c52643a104c2c3b81295a106 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:19:18 +1300 Subject: [PATCH 087/186] Changed close to free --- src/diff_list.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diff_list.cc b/src/diff_list.cc index 00ff8eaa5..8a70d8734 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -34,7 +34,7 @@ void GitDiffList::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "treeToTree", TreeToTree); NODE_SET_PROTOTYPE_METHOD(tpl, "walk", Walk); - NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); + NODE_SET_PROTOTYPE_METHOD(tpl, "free", Free); // Add libgit2 delta types to diff_list object Local libgit2DeltaTypes = Object::New(); From f4154cc93e905107d84cd9c13b1dcdb7ab41b3a0 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:20:15 +1300 Subject: [PATCH 088/186] Updated diff list --- src/diff_list.cc | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/diff_list.cc b/src/diff_list.cc index 8a70d8734..fcd90df9a 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -15,9 +15,11 @@ #include "../include/error.h" #include "../include/functions/string.h" +#include "../include/functions/utilities.h" using namespace v8; using namespace node; +using namespace cvv8; namespace cvv8 { template <> @@ -143,7 +145,7 @@ Handle GitDiffList::TreeToTree(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - TreeToTreeBaton *baton = new TreeToTreeBaton(); + TreeToTreeBaton *baton = new TreeToTreeBaton; baton->request.data = baton; baton->error = NULL; baton->diffList = ObjectWrap::Unwrap(args.This()); @@ -293,7 +295,7 @@ Handle GitDiffList::Walk(const Arguments& args) { baton->rawDiffList = diffList->GetValue(); diffList->Ref(); - + baton->error = NULL; baton->fileCallback = Persistent::New(Local::Cast(args[0])); baton->hunkCallback = Persistent::New(Local::Cast(args[1])); baton->lineCallback = Persistent::New(Local::Cast(args[2])); @@ -341,7 +343,7 @@ int GitDiffList::WalkWorkFile(const git_diff_delta *delta, float progress, uv_mutex_lock(&baton->mutex); - GitDiffList::Delta* newDelta = new GitDiffList::Delta(); + Delta* newDelta = new Delta; newDelta->raw = (git_diff_delta*)malloc(sizeof(git_diff_delta)); memcpy(newDelta->raw, delta, sizeof(git_diff_delta)); @@ -352,6 +354,7 @@ int GitDiffList::WalkWorkFile(const git_diff_delta *delta, float progress, uv_mutex_unlock(&baton->mutex); if ((unsigned int)baton->fileDeltas.size() == (unsigned int)GitDiffList::WALK_DELTA_SEND_THRESHHOLD) { + baton->asyncFile.data = baton; uv_async_send(&baton->asyncFile); } @@ -389,19 +392,8 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) { WalkBaton *baton = static_cast(handle->data); - if (baton->error) { - Local argv[1] = { - GitError::WrapError(baton->error) - }; - - TryCatch try_catch; - baton->fileCallback->Call(Context::GetCurrent()->Global(), 1, argv); - if (try_catch.HasCaught()) { - node::FatalException(try_catch); - } - } else { - - uv_mutex_lock(&baton->mutex); + uv_mutex_lock(&baton->mutex); + if (success(baton->error, baton->fileCallback)) { std::vector > fileDeltasArray; @@ -459,7 +451,6 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) { baton->fileDeltas.clear(); - uv_mutex_unlock(&baton->mutex); Handle argv[2] = { Local::New(Null()), @@ -472,6 +463,7 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) { node::FatalException(try_catch); } } + uv_mutex_unlock(&baton->mutex); } void GitDiffList::WalkWorkSendHunk(uv_async_t *handle, int status /*UNUSED*/) { } void GitDiffList::WalkWorkSendData(uv_async_t *handle, int status /*UNUSED*/) { } From 94d532004323641fd169f375869c36a82b32fac7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:20:35 +1300 Subject: [PATCH 089/186] Tidied git2 import --- include/blob.h | 2 +- include/commit.h | 2 +- include/diff_list.h | 2 +- include/error.h | 2 +- include/functions/utilities.h | 2 +- include/index.h | 4 ++-- include/object.h | 2 +- include/odb.h | 4 ++-- include/oid.h | 2 +- include/reference.h | 2 +- include/repo.h | 2 +- include/revwalk.h | 2 +- include/signature.h | 2 +- include/tag.h | 4 ++-- include/threads.h | 2 +- src/base.cc | 2 +- src/blob.cc | 2 +- src/commit.cc | 2 +- src/object.cc | 2 +- src/oid.cc | 2 +- src/reference.cc | 2 +- src/repo.cc | 2 +- src/revwalk.cc | 2 +- src/signature.cc | 2 +- src/threads.cc | 2 +- 25 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/blob.h b/include/blob.h index 0a9d86b3b..7c7d27d25 100755 --- a/include/blob.h +++ b/include/blob.h @@ -10,7 +10,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "repo.h" diff --git a/include/commit.h b/include/commit.h index 3ca1e914d..37b6dd8be 100755 --- a/include/commit.h +++ b/include/commit.h @@ -9,7 +9,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "reference.h" #include "repo.h" diff --git a/include/diff_list.h b/include/diff_list.h index 4e048504f..37b550d4c 100644 --- a/include/diff_list.h +++ b/include/diff_list.h @@ -11,7 +11,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/repo.h" diff --git a/include/error.h b/include/error.h index 87c3e593a..ecf74c937 100755 --- a/include/error.h +++ b/include/error.h @@ -8,7 +8,7 @@ #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" using namespace v8; using namespace node; diff --git a/include/functions/utilities.h b/include/functions/utilities.h index 4d71f4911..ad9ec84c2 100644 --- a/include/functions/utilities.h +++ b/include/functions/utilities.h @@ -4,7 +4,7 @@ #include #include -#include "../../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../../include/error.h" diff --git a/include/index.h b/include/index.h index 03d479da9..2d7254a50 100755 --- a/include/index.h +++ b/include/index.h @@ -8,7 +8,7 @@ #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" using namespace node; @@ -52,5 +52,5 @@ class GitIndex : public ObjectWrap { */ static v8::Handle New(const v8::Arguments& args); }; - + #endif diff --git a/include/object.h b/include/object.h index cc5a5270c..ff8f26bb9 100755 --- a/include/object.h +++ b/include/object.h @@ -11,7 +11,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "repo.h" #include "oid.h" diff --git a/include/odb.h b/include/odb.h index a0d9692cc..b0b32b4d1 100755 --- a/include/odb.h +++ b/include/odb.h @@ -8,7 +8,7 @@ #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" using namespace node; @@ -52,5 +52,5 @@ class GitOdb : public ObjectWrap { */ static v8::Handle New(const v8::Arguments& args); }; - + #endif diff --git a/include/oid.h b/include/oid.h index 5a876491d..ab14b306d 100755 --- a/include/oid.h +++ b/include/oid.h @@ -11,7 +11,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" using namespace node; using namespace v8; diff --git a/include/reference.h b/include/reference.h index 46226573a..4f28bcca4 100644 --- a/include/reference.h +++ b/include/reference.h @@ -12,7 +12,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "repo.h" #include "oid.h" diff --git a/include/repo.h b/include/repo.h index 8eb805e1e..b0cea0ba4 100755 --- a/include/repo.h +++ b/include/repo.h @@ -12,7 +12,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "object.h" diff --git a/include/revwalk.h b/include/revwalk.h index 1a76d529d..b259179d5 100755 --- a/include/revwalk.h +++ b/include/revwalk.h @@ -10,7 +10,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "repo.h" diff --git a/include/signature.h b/include/signature.h index 483db8415..bc83ad529 100755 --- a/include/signature.h +++ b/include/signature.h @@ -11,7 +11,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "repo.h" diff --git a/include/tag.h b/include/tag.h index db8560d44..723e1d7c2 100755 --- a/include/tag.h +++ b/include/tag.h @@ -8,7 +8,7 @@ #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" using namespace node; @@ -52,5 +52,5 @@ class GitTag : public ObjectWrap { */ static v8::Handle New(const v8::Arguments& args); }; - + #endif diff --git a/include/threads.h b/include/threads.h index 469911d8c..bf9f8c392 100755 --- a/include/threads.h +++ b/include/threads.h @@ -8,7 +8,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" using namespace node; using namespace v8; diff --git a/src/base.cc b/src/base.cc index 511c85e8e..a106d2228 100755 --- a/src/base.cc +++ b/src/base.cc @@ -8,7 +8,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/reference.h" #include "../include/signature.h" diff --git a/src/blob.cc b/src/blob.cc index d795359a7..dc68c5717 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -5,7 +5,7 @@ #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/utils.h" #include "../include/repo.h" diff --git a/src/commit.cc b/src/commit.cc index 139842885..c232d2f5c 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -9,7 +9,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "cvv8/v8-convert.hpp" #include "../include/reference.h" diff --git a/src/object.cc b/src/object.cc index d62c48812..6b1c43654 100755 --- a/src/object.cc +++ b/src/object.cc @@ -9,7 +9,7 @@ #include #include "cvv8/v8-convert.hpp" -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/object.h" #include "../include/repo.h" diff --git a/src/oid.cc b/src/oid.cc index e0837ae08..cf8d3a2a9 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -8,7 +8,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/oid.h" diff --git a/src/reference.cc b/src/reference.cc index 40e454944..a80628ca9 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -9,7 +9,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/repo.h" #include "../include/reference.h" diff --git a/src/repo.cc b/src/repo.cc index 8478bb3d2..0d7f61c35 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -8,7 +8,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/object.h" #include "../include/repo.h" diff --git a/src/revwalk.cc b/src/revwalk.cc index b79bcb340..d4034c829 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -8,7 +8,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/revwalk.h" #include "../include/repo.h" diff --git a/src/signature.cc b/src/signature.cc index 72e4338f8..49b775403 100755 --- a/src/signature.cc +++ b/src/signature.cc @@ -8,7 +8,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/repo.h" #include "../include/signature.h" diff --git a/src/threads.cc b/src/threads.cc index 14c4b7f1c..847e38e3a 100755 --- a/src/threads.cc +++ b/src/threads.cc @@ -9,7 +9,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/threads.h" #include "../include/error.h" From 79fccb338ff30159c820aa35a4fc30ef6178e1ee Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:21:44 +1300 Subject: [PATCH 090/186] Added tree entry root & path --- include/tree_entry.h | 10 ++++++++-- lib/tree_entry.js | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/include/tree_entry.h b/include/tree_entry.h index 1bd543abc..5672df2da 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -10,8 +10,9 @@ #include #include +#include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "repo.h" #include "tree.h" @@ -32,10 +33,14 @@ class GitTreeEntry : ObjectWrap { static void Initialize(Handle target); git_tree_entry* GetValue(); void SetValue(git_tree_entry* tree); + void SetRoot(std::string root); + std::string GetRoot(); protected: static Handle New(const Arguments& args); + static Handle Root(const Arguments& args); + static Handle Name(const Arguments& args); static void NameWork(uv_work_t* req); static void NameAfterWork(uv_work_t* req); @@ -54,12 +59,13 @@ class GitTreeEntry : ObjectWrap { private: git_tree_entry* entry; + std::string root; struct NameBaton { uv_work_t request; git_tree_entry* rawEntry; - std::string name; + const char* name; Persistent callback; }; diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 62ab8c744..3cafe7825 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -87,13 +87,45 @@ TreeEntry.prototype.isDirectory = function(callback) { * @param {Function} callback */ TreeEntry.prototype.name = function(callback) { - this.rawEntry.name(function(error, name) { + this.rawEntry.name(function treeEntryName(error, name) { if (success(error, callback)) { callback(null, name); } }); }; +/** + * Retrieve the entry's root path. + * + * @param {Function} callback + */ +TreeEntry.prototype.root = function(callback) { + this.rawEntry.root(function treeEntryRoot(error, root) { + if (success(error, callback)) { + callback(null, root); + } + }); +}; + +/** + * Retrieve the path relative to the repository root for this TreeEntry. + * + * @param {Function} callback + */ +TreeEntry.prototype.path = function(callback) { + var self = this; + self.root(function treeEntryRoot(error, root) { + if (!success(error, callback)) { + return; + } + self.rawEntry.name(function treeEntryName(error, name) { + if (success(error, callback)) { + callback(null, root + name); + } + }); + }); +}; + /** * Retrieve the TreeEntry's content. * From f665287bde7a902abc8cd3eba7efb996817377c8 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:22:12 +1300 Subject: [PATCH 091/186] Implemented tree entry root & path, implemented name --- src/tree_entry.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 5dcb670f7..c8f072237 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -8,7 +8,7 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "../include/repo.h" #include "../include/blob.h" @@ -30,6 +30,7 @@ void GitTreeEntry::Initialize(Handle target) { tpl->SetClassName(String::NewSymbol("TreeEntry")); NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); + NODE_SET_PROTOTYPE_METHOD(tpl, "root", Root); NODE_SET_PROTOTYPE_METHOD(tpl, "fileMode", FileMode); NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id); NODE_SET_PROTOTYPE_METHOD(tpl, "toBlob", ToBlob); @@ -44,6 +45,12 @@ git_tree_entry* GitTreeEntry::GetValue() { void GitTreeEntry::SetValue(git_tree_entry* entry) { this->entry = entry; } +void GitTreeEntry::SetRoot(std::string root) { + this->root = root; +} +std::string GitTreeEntry::GetRoot() { + return this->root; +} Handle GitTreeEntry::New(const Arguments& args) { HandleScope scope; @@ -55,19 +62,73 @@ Handle GitTreeEntry::New(const Arguments& args) { return scope.Close(args.This()); } -Handle GitTreeEntry::Name(const Arguments& args) { +Handle GitTreeEntry::Root(const Arguments& args) { HandleScope scope; + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + + Handle argv[2] = { + Local::New(Null()), + String::New(entry->GetRoot().c_str()) + }; + + TryCatch try_catch; + Local::Cast(args[0])->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + + return Undefined(); +} + +Handle GitTreeEntry::Name(const Arguments& args) { + // HandleScope scope; + // GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); // return scope.Close(String::New(git_tree_entry_name(entry->entry))); + // return Undefined(); + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + NameBaton *baton = new NameBaton; + baton->request.data = baton; + + GitTreeEntry *treeEntry = ObjectWrap::Unwrap(args.This()); + baton->rawEntry = treeEntry->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, NameWork, (uv_after_work_cb)NameAfterWork); + return Undefined(); } void GitTreeEntry::NameWork(uv_work_t* req) { + NameBaton *baton = static_cast(req->data); + baton->name = git_tree_entry_name(baton->rawEntry); } void GitTreeEntry::NameAfterWork(uv_work_t* req) { + HandleScope scope; + NameBaton *baton = static_cast(req->data); + + Handle argv[2] = { + Local::New(Null()), + String::New(baton->name) + }; + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; } Handle GitTreeEntry::FileMode(const Arguments& args) { @@ -80,6 +141,7 @@ Handle GitTreeEntry::FileMode(const Arguments& args) { } void GitTreeEntry::FileModeWork(uv_work_t* req) { + } void GitTreeEntry::FileModeAfterWork(uv_work_t* req) { From bb15be1d08a826398c2eb42d233d1412b0847ca6 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:22:29 +1300 Subject: [PATCH 092/186] Re implemented tree walk --- lib/tree.js | 81 +++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 62 deletions(-) diff --git a/lib/tree.js b/lib/tree.js index d5a3d5a07..7182f08d9 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -37,69 +37,26 @@ Tree.prototype.entry = function(path, callback) { }; Tree.prototype.walk = function() { - // @todo refactor to use git_tree_walk - - // var entry, - // index, - // length = self.length, - // event = new events.EventEmitter(), - // entries = []; - - // function next(index) { - // var dir; - // var tree; - // var prerequisites = 0; - - // function complete(error) { - // if (index < length - 1) { - // next(index = index + 1); - // } else { - // event.emit('end', error, entries); - // } - // } - - // entry = git.entry(repo); - - // self.tree.entryByIndex(entry.entry, index, function() { - // if (entry.isFile()) { - // entries.push(entry); - // event.emit('entry', null, index, entry); - // } else { - // dir = entry.name; - // tree = entry.tree(); - // prerequisites++; - // if (tree.error) { - // event.emit('end', tree.error); - // return; - // } - - // tree.walk(repo).on('entry', function(error, index, entry) { - // if (error) { - // event.emit('entry', error, index, entry); - // } - // entry.dir = dir + '/' + entry.dir; - // event.emit('entry', null, index, entry); - // }).on('end', function(error, endEntries) { - // if (error) { - // complete(error); - // } - // prerequisites--; - // entries = entries.concat(endEntries); - // if (prerequisites === 0) { - // complete(error); - // } - // }); - // } - - // if (prerequisites === 0) { - // complete(); - // } - // }); - // } - - // next(0); + var self = this, + event = new events.EventEmitter(), + entries = []; + + self.rawTree.walk(function treeWalkEntries(error, rawEntries) { + rawEntries.forEach(function treeWalkEntryEmitter(rawEntry) { + var entry = new git.entry(self.rawRepo, rawEntry); + entries.push(entry); + if (!error) { + event.emit('entry', null, entry); + } + }); + }, function treeWalkEnd(error) { + if (error) { + event.emit('end', git.error(error), entries); + } + event.emit('end', null, entries); + }); - // return event; + return event; }; exports.tree = Tree; From d3f5053a00775479bf6580aa72b7e67b2273947f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:22:41 +1300 Subject: [PATCH 093/186] Implemented tree walk --- include/tree.h | 55 ++++++++++++-------- src/tree.cc | 134 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 166 insertions(+), 23 deletions(-) diff --git a/include/tree.h b/include/tree.h index b4ada4ae5..f40518909 100755 --- a/include/tree.h +++ b/include/tree.h @@ -11,8 +11,9 @@ #include #include #include +#include -#include "../vendor/libgit2/include/git2.h" +#include "git2.h" #include "repo.h" #include "tree_entry.h" @@ -25,28 +26,14 @@ using namespace node; */ class GitTree : public ObjectWrap { public: - /** - * v8::FunctionTemplate used to create Node.js constructor - */ + static Persistent constructor_template; - /** - * Used to intialize the EventEmitter from Node.js - * - * @param target v8::Object the Node.js module object - */ + static const int WALK_ENTRY_SEND_THRESHOLD = 10; + static void Initialize(Handle target); - /** - * Accessor for GitTree - * - * @return the internal git_tree reference - */ + git_tree* GetValue(); - /** - * Mutator for GitTree - * - * @param obj a git_tree object - */ void SetValue(git_tree* tree); protected: @@ -55,16 +42,40 @@ class GitTree : public ObjectWrap { static Handle New(const Arguments& args); + static Handle Walk(const Arguments& args); + static void WalkWork(void* payload); + static int WalkWorkEntry(const char *root, const git_tree_entry *entry, void *payload); + static void WalkWorkSendEntry(uv_async_t *handle, int status /*UNUSED*/); + static void WalkWorkSendEnd(uv_async_t *handle, int status /*UNUSED*/); + static Handle EntryByPath(const Arguments& args); static void EntryByPathWork(uv_work_t *req); static void EntryByPathAfterWork(uv_work_t *req); private: - /** - * Internal reference to git_tree object - */ + git_tree* tree; + struct WalkEntry { + git_tree_entry* rawEntry; + std::string root; + }; + + struct WalkBaton { + uv_thread_t threadId; + uv_mutex_t mutex; + uv_async_t asyncEntry; + uv_async_t asyncEnd; + + const git_error* error; + + std::vector rawTreeEntries; + + git_tree* rawTree; + Persistent entryCallback; + Persistent endCallback; + }; + struct EntryByPathBaton { uv_work_t request; const git_error* error; diff --git a/src/tree.cc b/src/tree.cc index b16832cb8..3bd6a3312 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -7,8 +7,10 @@ #include #include +#include -#include "../vendor/libgit2/include/git2.h" +#include "cvv8/v8-convert.hpp" +#include "git2.h" #include "../include/repo.h" #include "../include/oid.h" @@ -21,6 +23,7 @@ using namespace v8; using namespace node; +using namespace cvv8; void GitTree::Initialize (Handle target) { HandleScope scope; @@ -30,6 +33,7 @@ void GitTree::Initialize (Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("Tree")); + NODE_SET_PROTOTYPE_METHOD(tpl, "walk", Walk); NODE_SET_PROTOTYPE_METHOD(tpl, "entryByPath", EntryByPath); constructor_template = Persistent::New(tpl->GetFunction()); @@ -53,6 +57,133 @@ Handle GitTree::New(const Arguments& args) { return scope.Close(args.This()); } +Handle GitTree::Walk(const Arguments& args) { + HandleScope scope; + + GitTree* tree = ObjectWrap::Unwrap(args.This()); + + if (tree->GetValue() == NULL) { + return ThrowException(Exception::Error(String::New("No tree list to Walk."))); + } + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Entry callback is required and must be a Function."))); + } + + if(args.Length() == 1 || !args[1]->IsFunction()) { + return ThrowException(Exception::Error(String::New("End callback is required and must be a Function."))); + } + + WalkBaton* baton = new WalkBaton; + uv_async_init(uv_default_loop(), &baton->asyncEntry, WalkWorkSendEntry); + uv_async_init(uv_default_loop(), &baton->asyncEnd, WalkWorkSendEnd); + + uv_mutex_init(&baton->mutex); + + baton->rawTree = tree->GetValue(); + baton->error = NULL; + baton->entryCallback = Persistent::New(Local::Cast(args[0])); + baton->endCallback = Persistent::New(Local::Cast(args[1])); + + uv_thread_create(&baton->threadId, WalkWork, baton); + + return Undefined(); +} +void GitTree::WalkWork(void* payload) { + WalkBaton *baton = static_cast(payload); + + int returnCode = git_tree_walk(baton->rawTree, GIT_TREEWALK_PRE, WalkWorkEntry, payload); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + baton->asyncEnd.data = baton; + uv_async_send(&baton->asyncEnd); + return; + } + + baton->asyncEntry.data = baton; + uv_async_send(&baton->asyncEntry); + + baton->asyncEnd.data = baton; + uv_async_send(&baton->asyncEnd); +} +int GitTree::WalkWorkEntry(const char* root, const git_tree_entry* entry, void* payload) { + WalkBaton *baton = static_cast(payload); + + uv_mutex_lock(&baton->mutex); + + GitTree::WalkEntry* walkEntry = new WalkEntry; + walkEntry->rawEntry = git_tree_entry_dup(entry); + walkEntry->root = root; + + baton->rawTreeEntries.push_back(walkEntry); + + uv_mutex_unlock(&baton->mutex); + + if ((unsigned int)baton->rawTreeEntries.size() == (unsigned int)GitTree::WALK_ENTRY_SEND_THRESHOLD) { + baton->asyncEntry.data = baton; + uv_async_send(&baton->asyncEntry); + } + + return GIT_OK; +} +void GitTree::WalkWorkSendEntry(uv_async_t *handle, int status /*UNUSED*/) { + HandleScope scope; + + WalkBaton *baton = static_cast(handle->data); + + uv_mutex_lock(&baton->mutex); + + if (success(baton->error, baton->entryCallback)) { + + std::vector > treeEntries; + + for(std::vector::iterator treeEntriesIterator = baton->rawTreeEntries.begin(); treeEntriesIterator != baton->rawTreeEntries.end(); ++treeEntriesIterator) { + WalkEntry* walkEntry = (*treeEntriesIterator); + + Local entry = GitTreeEntry::constructor_template->NewInstance(); + GitTreeEntry *entryInstance = ObjectWrap::Unwrap(entry); + entryInstance->SetValue(walkEntry->rawEntry); + entryInstance->SetRoot(walkEntry->root); + + treeEntries.push_back(entry); + } + + baton->rawTreeEntries.clear(); + + Handle argv[2] = { + Local::New(Null()), + CastToJS(treeEntries) + }; + + TryCatch try_catch; + baton->entryCallback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } + uv_mutex_unlock(&baton->mutex); +} +void GitTree::WalkWorkSendEnd(uv_async_t *handle, int status /*UNUSED*/) { + WalkBaton *baton = static_cast(handle->data); + + uv_mutex_destroy(&baton->mutex); + + Local argv[1]; + if (baton->error) { + argv[0] = GitError::WrapError(baton->error); + } else { + argv[0] = Local::New(Null()); + } + + TryCatch try_catch; + + baton->endCallback->Call(Context::GetCurrent()->Global(), 1, argv); + + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } +} + Handle GitTree::EntryByPath(const Arguments& args) { HandleScope scope; @@ -96,6 +227,7 @@ void GitTree::EntryByPathAfterWork(uv_work_t *req) { Local entry = GitTreeEntry::constructor_template->NewInstance(); GitTreeEntry *entryInstance = ObjectWrap::Unwrap(entry); entryInstance->SetValue(baton->rawEntry); + entryInstance->SetRoot(baton->path.substr(0, baton->path.find_last_of("\\/"))); Handle argv[2] = { Local::New(Null()), From c174241121264b0f86fae8c0a930e0c124be3c6a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 00:23:23 +1300 Subject: [PATCH 094/186] Updated convenience-commit's tree test --- test/convenience-commit.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index 328f6aff1..e07728fc7 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -241,21 +241,20 @@ exports.parents = function(test) { exports.tree = function(test) { test.expect(2); git.repo('../.git', function(error, repository) { - repository.commit(historyCountKnownSHA, function(error, commit) { - test.equals(error, null, 'Getting latest branch commit should not error'); var commitTreeEntryCount = 0; var expectedCommitTreeEntryCount = 200; - commit.tree().walk().on('entry', function(commit) { - commitTreeEntryCount++; - }).on('end', function(commits) { - - test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected'); + commit.tree(function commitTree(error, tree) { + tree.walk().on('entry', function(error, entry) { + commitTreeEntryCount++; + }).on('end', function(error, entries) { + test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected'); - test.done(); + test.done(); + }); }); }); }); From 403d6e6cc5cb5973cfda389fc823136728402b57 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:23:39 +1300 Subject: [PATCH 095/186] Tidied revwalk. Made git_revwalk_new async (Allocate) --- src/revwalk.cc | 181 +++++++++++++++++++++++++------------------------ 1 file changed, 94 insertions(+), 87 deletions(-) diff --git a/src/revwalk.cc b/src/revwalk.cc index d4034c829..c8817bfde 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -15,87 +15,135 @@ #include "../include/commit.h" #include "../include/error.h" +#include "../include/functions/utilities.h" + using namespace v8; using namespace node; void GitRevWalk::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("RevWalk")); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->SetClassName(String::NewSymbol("RevWalk")); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "reset", Reset); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "push", Push); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "next", Next); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "free", Free); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "repository", Repository); + NODE_SET_PROTOTYPE_METHOD(tpl, "allocate", Allocate); + NODE_SET_PROTOTYPE_METHOD(tpl, "reset", Reset); + NODE_SET_PROTOTYPE_METHOD(tpl, "push", Push); + NODE_SET_PROTOTYPE_METHOD(tpl, "next", Next); + NODE_SET_PROTOTYPE_METHOD(tpl, "free", Free); - Local sort = Object::New(); + // Local sort = Object::New(); - sort->Set(String::New("NONE"), Integer::New(0)); - sort->Set(String::New("TOPOLOGICAL"), Integer::New(1)); - sort->Set(String::New("TIME"), Integer::New(2)); - sort->Set(String::New("REVERSE"), Integer::New(4)); + // sort->Set(String::New("NONE"), Integer::New(0)); + // sort->Set(String::New("TOPOLOGICAL"), Integer::New(1)); + // sort->Set(String::New("TIME"), Integer::New(2)); + // sort->Set(String::New("REVERSE"), Integer::New(4)); - constructor_template->Set(String::New("sort"), sort); + // tpl->Set(String::New("sort"), sort); - target->Set(String::NewSymbol("RevWalk"), constructor_template->GetFunction()); + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("RevWalk"), constructor_template); } git_revwalk* GitRevWalk::GetValue() { return this->revwalk; } - void GitRevWalk::SetValue(git_revwalk* revwalk) { this->revwalk = revwalk; } - -int GitRevWalk::New(git_repository* repo) { +git_repository* GitRevWalk::GetRepo() { + return this->repo; +} +void GitRevWalk::SetRepo(git_repository* repo) { this->repo = repo; - - return git_revwalk_new(&this->revwalk, this->repo); } -void GitRevWalk::Reset() { - git_revwalk_reset(this->revwalk); -} +Handle GitRevWalk::Free(const Arguments& args) { + HandleScope scope; -void GitRevWalk::Free() { - git_revwalk_free(this->revwalk); -} + GitRevWalk *revwalk = ObjectWrap::Unwrap(args.This()); + + git_revwalk_free(revwalk->revwalk); -git_repository* GitRevWalk::Repository() { - return git_revwalk_repository(this->revwalk); + return Undefined(); } Handle GitRevWalk::New(const Arguments& args) { HandleScope scope; GitRevWalk *revwalk = new GitRevWalk(); - if(args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); } GitRepo *repo = ObjectWrap::Unwrap(args[0]->ToObject()); - revwalk->New(repo->GetValue()); + revwalk->SetRepo(repo->GetValue()); revwalk->Wrap(args.This()); - return scope.Close( args.This() ); + return scope.Close(args.This()); } Handle GitRevWalk::Reset(const Arguments& args) { HandleScope scope; GitRevWalk *revwalk = ObjectWrap::Unwrap(args.This()); + git_revwalk_reset(revwalk->revwalk); + + return Undefined(); +} - revwalk->Reset(); +Handle GitRevWalk::Allocate(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + AllocateBaton *baton = new AllocateBaton; + baton->request.data = baton; + baton->error = NULL; + baton->revwalk = ObjectWrap::Unwrap(args.This()); + baton->rawRevwalk = NULL; + baton->rawRepo = baton->revwalk->GetRepo(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, AllocateWork, (uv_after_work_cb)AllocateAfterWork); + + return Undefined(); +} +void GitRevWalk::AllocateWork(uv_work_t *req) { + AllocateBaton *baton = static_cast(req->data); + + int returnCode = git_revwalk_new(&baton->rawRevwalk, baton->rawRepo); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + } +} + +void GitRevWalk::AllocateAfterWork(uv_work_t *req) { + HandleScope scope; + AllocateBaton *baton = static_cast(req->data); + + + if (success(baton->error, baton->callback)) { + + baton->revwalk->SetValue(baton->rawRevwalk); + + Handle argv[2] = { + Local::New(Null()), + baton->revwalk->handle_ + }; - return scope.Close( Undefined() ); + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } + delete req; } Handle GitRevWalk::Push(const Arguments& args) { @@ -112,26 +160,25 @@ Handle GitRevWalk::Push(const Arguments& args) { PushBaton* baton = new PushBaton; baton->request.data = baton; - baton->revwalk = ObjectWrap::Unwrap(args.This())->GetValue(); - baton->oid = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->error = NULL; + baton->rawRevwalk = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->rawOid = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); baton->callback = Persistent::New(Local::Cast(args[1])); uv_queue_work(uv_default_loop(), &baton->request, PushWork, (uv_after_work_cb)PushAfterWork); return Undefined(); } - void GitRevWalk::PushWork(uv_work_t *req) { PushBaton *baton = static_cast(req->data); - git_revwalk_sorting(baton->revwalk, GIT_SORT_TIME | GIT_SORT_REVERSE); + git_revwalk_sorting(baton->rawRevwalk, GIT_SORT_TIME | GIT_SORT_REVERSE); - int returnCode = git_revwalk_push(baton->revwalk, &baton->oid); + int returnCode = git_revwalk_push(baton->rawRevwalk, &baton->rawOid); if (returnCode) { baton->error = giterr_last(); } } - void GitRevWalk::PushAfterWork(uv_work_t *req) { HandleScope scope; PushBaton *baton = static_cast(req->data); @@ -161,7 +208,8 @@ Handle GitRevWalk::Next(const Arguments& args) { NextBaton* baton = new NextBaton; baton->request.data = baton; - baton->revwalk = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->error = NULL; + baton->rawRevwalk = ObjectWrap::Unwrap(args.This())->GetValue(); baton->walkOver = false; baton->callback = Persistent::New(Local::Cast(args[0])); @@ -169,42 +217,27 @@ Handle GitRevWalk::Next(const Arguments& args) { return Undefined(); } - void GitRevWalk::NextWork(uv_work_t *req) { NextBaton *baton = static_cast(req->data); - // baton->oid = NULL; - int returnCode = git_revwalk_next(&baton->oid, baton->revwalk); + int returnCode = git_revwalk_next(&baton->rawOid, baton->rawRevwalk); if (returnCode != GIT_OK) { if (returnCode == GIT_ITEROVER) { baton->walkOver = true; } else { + git_revwalk_reset(baton->rawRevwalk); baton->error = giterr_last(); } } } - void GitRevWalk::NextAfterWork(uv_work_t *req) { HandleScope scope; NextBaton *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 { - + if (success(baton->error, baton->callback)) { Local oid = GitOid::constructor_template->NewInstance(); GitOid *oidInstance = ObjectWrap::Unwrap(oid); - oidInstance->SetValue(baton->oid); + oidInstance->SetValue(baton->rawOid); Local argv[3] = { Local::New(Null()), @@ -213,9 +246,7 @@ void GitRevWalk::NextAfterWork(uv_work_t *req) { }; TryCatch try_catch; - baton->callback->Call(Context::GetCurrent()->Global(), 3, argv); - if(try_catch.HasCaught()) { FatalException(try_catch); } @@ -223,28 +254,4 @@ void GitRevWalk::NextAfterWork(uv_work_t *req) { delete req; } -Handle GitRevWalk::Free(const Arguments& args) { - HandleScope scope; - - GitRevWalk *revwalk = ObjectWrap::Unwrap(args.This()); - - revwalk->Free(); - - return scope.Close( Undefined() ); -} - -Handle GitRevWalk::Repository(const Arguments& args) { - HandleScope scope; - - GitRevWalk *revwalk = new GitRevWalk(); - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); - } - - GitRepo *repo = ObjectWrap::Unwrap(args[0]->ToObject()); - repo->SetValue(revwalk->Repository()); - - return scope.Close( Undefined() ); -} -Persistent GitRevWalk::constructor_template; +Persistent GitRevWalk::constructor_template; From 5967d17d286ca00e5d8ef7cdd686a33e6d41f94f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:24:08 +1300 Subject: [PATCH 096/186] Updated revwalk.js --- lib/revwalk.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/revwalk.js b/lib/revwalk.js index fff4e46ca..b85aab22b 100644 --- a/lib/revwalk.js +++ b/lib/revwalk.js @@ -14,13 +14,29 @@ var RevWalk = function(rawRepo, rawRevWalk) { } this.rawRepo = rawRepo; - if (rawRevWalk instanceof git.raw.RevWalk) { + if (typeof rawRevWalk !== 'undefined' && + rawRevWalk instanceof git.raw.RevWalk) { this.rawRevWalk = rawRevWalk; } else { - this.rawRevWalk = new git.raw.RevWalk(this.rawRepo); + this.rawRevWalk = new git.raw.RevWalk(rawRepo); } }; +/** + * Allocate new revwalker. + * + * @param {Function} callback + */ +RevWalk.prototype.allocate = function(callback) { + var self = this; + self.rawRevWalk.allocate(function revwalkAllocate(error, rawRevwalk) { + if (success(error, callback)) { + self.rawRevwalk = rawRevwalk; + callback(null, self); + } + }); +}; + /** * Walk the history from the given oid. * From 17076925d5cfb85a30c6e264518bae9e1b097a4d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:24:20 +1300 Subject: [PATCH 097/186] Updated revwalk.h --- include/revwalk.h | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/include/revwalk.h b/include/revwalk.h index b259179d5..46ef8db07 100755 --- a/include/revwalk.h +++ b/include/revwalk.h @@ -19,65 +19,70 @@ using namespace v8; class GitRevWalk : public ObjectWrap { public: - static Persistent constructor_template; + static Persistent constructor_template; static void Initialize(Handle target); git_revwalk* GetValue(); void SetValue(git_revwalk* revwalk); - int New(git_repository* repo); - void Reset(); - int Push(git_oid* oid); - int Hide(); - int Sorting(int sort); - void Free(); - git_repository* Repository(); + git_repository* GetRepo(); + void SetRepo(git_repository* repository); protected: GitRevWalk() {} ~GitRevWalk() {} + static Handle New(const Arguments& args); + static Handle Free(const Arguments& args); + static Handle Reset(const Arguments& args); - /** - * Although git_revwalk_next is not blocking when iterating with a - * time-sorting mode, options may be added later to allow different sort - * modes, hence the async implementation. - */ + static Handle Allocate(const Arguments& args); + static void AllocateWork(uv_work_t *req); + static void AllocateAfterWork(uv_work_t *req); + static Handle Push(const Arguments& args); static void PushWork(uv_work_t *req); static void PushAfterWork(uv_work_t *req); - static Handle Hide(const Arguments& args); - static Handle Next(const Arguments& args); static void NextWork(uv_work_t* req); static void NextAfterWork(uv_work_t* req); static Handle Sorting(const Arguments& args); - static Handle Free(const Arguments& args); - static Handle Repository(const Arguments& args); private: git_revwalk* revwalk; git_repository* repo; + struct AllocateBaton { + uv_work_t request; + const git_error* error; + + GitRevWalk* revwalk; + git_revwalk *rawRevwalk; + git_repository* rawRepo; + + Persistent callback; + }; + struct PushBaton { uv_work_t request; const git_error* error; - git_revwalk *revwalk; - git_oid oid; + git_revwalk *rawRevwalk; + git_oid rawOid; Persistent callback; }; struct NextBaton { uv_work_t request; + const git_error* error; bool walkOver; - git_revwalk *revwalk; - git_oid oid; + git_revwalk *rawRevwalk; + git_oid rawOid; Persistent callback; }; From b093d211727859dbd7aec5794ae58388bc51e4bc Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:24:30 +1300 Subject: [PATCH 098/186] Updated history --- lib/commit.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 732d8643d..d73ec5576 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -175,20 +175,21 @@ Commit.prototype.history = function() { self = this; self.oid(function commitOid(error, oid) { - var revwalk = new git.revwalk(self.rawRepo), - commits = []; - revwalk.walk(oid, function commitRevWalk(error, index, commit, noMoreCommits) { - if(error) { - event.emit('end', error, commits); - return false; - } - - if (noMoreCommits) { - event.emit('end', null, commits); - return; - } - event.emit('commit', null, commit); - commits.push(commit); + (new git.revwalk(self.rawRepo)).allocate(function createRevwalk(error, revwalk) { + var commits = []; + revwalk.walk(oid, function commitRevWalk(error, index, commit, noMoreCommits) { + if(error) { + event.emit('end', error, commits); + return false; + } + + if (noMoreCommits) { + event.emit('end', null, commits); + return; + } + event.emit('commit', null, commit); + commits.push(commit); + }); }); }); From 3caecc9faa2b490a3c9a41b0a1a66eb98cf22571 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:27:36 +1300 Subject: [PATCH 099/186] Updated convenience-commit tree test, removed file test --- test/convenience-commit.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index e07728fc7..f1ebff50f 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -245,7 +245,7 @@ exports.tree = function(test) { test.equals(error, null, 'Getting latest branch commit should not error'); var commitTreeEntryCount = 0; - var expectedCommitTreeEntryCount = 200; + var expectedCommitTreeEntryCount = 238; commit.tree(function commitTree(error, tree) { tree.walk().on('entry', function(error, entry) { @@ -274,19 +274,3 @@ exports.parentsDiffTrees = function(test) { }); }); }; - -exports.file = function(test) { - test.expect(5); - git.repo('../.git', function(error, repository) { - repository.commit(historyCountKnownSHA, function(error, commit) { - commit.file('README.md', function(error, file) { - test.equal(error, null, 'Should not error'); - test.notEqual(file, null, 'File should not be null'); - test.equal(file.name, 'README.md', 'File name should match expected'); - test.equal(file.sha, 'b252f396b17661462372f78b7bcfc403b8731aaa', 'SHA shoud match expected'); - test.equal(file.attributes, 33188, 'Attributes should match expected'); - test.done(); - }); - }); - }); -}; From e868dcae64cf7dc7ad3fa0242051fe0d87fea344 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:27:51 +1300 Subject: [PATCH 100/186] Fixed typo in parentsDiffTrees --- lib/commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index d73ec5576..a683f662a 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -232,7 +232,7 @@ Commit.prototype.parentsDiffTrees = function(callback) { var parentDiffLists = []; parents.forEach(function commitEachParent(parent) { parent.sha(function commitParentSha(error, parentSha) { - (new git.diffList(self.repo)).treeToTree(parentSha, commitSha, function walkDiffList(error, diffList) { + (new git.diffList(self.rawRepo)).treeToTree(parentSha, commitSha, function walkDiffList(error, diffList) { if (!success(error, callback)) { return; } From 5107effcdaa88776a866a58e8d7c90164e858dee Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:43:00 +1300 Subject: [PATCH 101/186] Whitespace --- src/repo.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/repo.cc b/src/repo.cc index 0d7f61c35..122913b27 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -138,7 +138,6 @@ Handle GitRepo::Free(const Arguments& args) { Handle GitRepo::Init(const Arguments& args) { HandleScope scope; - if(args.Length() == 0 || !args[0]->IsString()) { return ThrowException(Exception::Error(String::New("path is required and must be a String."))); } From 25d53dcd160018ccc2a2ee8a0f3dfc7360e9410e Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 01:43:17 +1300 Subject: [PATCH 102/186] Throw error when open is called without callback --- lib/repo.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/repo.js b/lib/repo.js index ddd63653b..9c13c2c4b 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -12,8 +12,11 @@ var Repo = function() { * @param {Function} callback */ Repo.prototype.open = function(directory, callback) { - var self = this; - self.rawRepo.open(directory, function(error, rawRepo) { + if (typeof callback === 'undefined') { + throw git.error('Callback is required and must be a Function'); + } + var self = this; + self.rawRepo.open(directory, function openRepository(error, rawRepo) { if (success(error, callback)) { self.rawRepo = rawRepo; callback(null, self); From 7dedc8e4a3402679e53f506e60bac14c0b62b1a8 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 21:36:29 +1300 Subject: [PATCH 103/186] Updated convenience-repo tests --- test/convenience-repo.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/convenience-repo.js b/test/convenience-repo.js index 94e9eb4a6..42ee81f40 100644 --- a/test/convenience-repo.js +++ b/test/convenience-repo.js @@ -38,11 +38,11 @@ exports.method = function(test){ }, 'Throw an exception if no callback'); // Test invalid repository - git.repo('/etc/hosts', function(error, path) { + git.repo('/etc/hosts', function(error, repository) { test.equals(error.code, error.GITERR_REPOSITORY, error.message, 'Invalid repository error code'); // Test valid repository - git.repo('../.git', function(error, path) { + git.repo('../.git', function(error, repository) { test.equals(null, error, 'Valid repository error code'); test.done(); }); @@ -62,16 +62,11 @@ exports.nonexistentDirectory = function(test) { }; /** - * Repo::Init - * * Ensure the init method can create repositories at the destination path and - * can create either bare/non-bare. This should work async/sync and provide - * the proper return values. + * can create either bare/non-bare. */ exports.init = function(test) { - test.expect(4); - - helper.testFunction(test.equals, git.repo().init, 'Repo::Init'); + test.expect(2); // Cleanup, remove test repo directory - if it exists rimraf('./test.git', function() { From 4ccf115061f9e3b46f75424d974eeff64ed52c16 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 21:49:34 +1300 Subject: [PATCH 104/186] Fixed bug in repo init --- lib/repo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/repo.js b/lib/repo.js index 9c13c2c4b..45c3be2a6 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -72,7 +72,7 @@ Repo.prototype.commit = function(sha, callback) { */ Repo.prototype.init = function(directory, isBare, callback) { var self = this; - self.repo.init(directory, isBare, function(error, rawRepo) { + self.rawRepo.init(directory, isBare, function(error, rawRepo) { if (success(error, callback)) { self.rawRepo = rawRepo; callback(null, self); From 9d6805c7430c0070a1a9606c12f6c73ee2405168 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 21:50:00 +1300 Subject: [PATCH 105/186] Reorganised repo.cc --- src/repo.cc | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/repo.cc b/src/repo.cc index 122913b27..1a31b4a3c 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -39,15 +39,10 @@ void GitRepo::Initialize(Handle target) { git_repository* GitRepo::GetValue() { return this->repo; } - void GitRepo::SetValue(git_repository* repo) { this->repo = repo; } -void GitRepo::Free() { - git_repository_free(this->repo); -} - Handle GitRepo::New(const Arguments& args) { HandleScope scope; @@ -57,6 +52,16 @@ Handle GitRepo::New(const Arguments& args) { return scope.Close(args.This()); } +Handle GitRepo::Free(const Arguments& args) { + HandleScope scope; + + GitRepo *repo = ObjectWrap::Unwrap(args.This()); + git_repository_free(repo->repo); + + return scope.Close( Undefined() ); +} + + Handle GitRepo::Open(const Arguments& args) { HandleScope scope; @@ -125,16 +130,6 @@ void GitRepo::OpenAfterWork(uv_work_t *req) { baton->repo->Unref(); } -Handle GitRepo::Free(const Arguments& args) { - HandleScope scope; - - GitRepo *repo = ObjectWrap::Unwrap(args.This()); - - repo->Free(); - - return scope.Close( Undefined() ); -} - Handle GitRepo::Init(const Arguments& args) { HandleScope scope; From db07c638f2932889cacc70501b51938b3fa5cfaf Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 22:01:07 +1300 Subject: [PATCH 106/186] Updated file comment --- include/blob.h | 6 ++++-- include/error.h | 6 ++++-- include/index.h | 6 ++++-- include/odb.h | 6 ++++-- include/tag.h | 6 ++++-- install.js | 12 ++++++------ src/blob.cc | 6 ++++-- src/error.cc | 6 ++++-- 8 files changed, 34 insertions(+), 20 deletions(-) diff --git a/include/blob.h b/include/blob.h index 7c7d27d25..e0ef511de 100755 --- a/include/blob.h +++ b/include/blob.h @@ -1,5 +1,7 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * * Dual licensed under the MIT and GPL licenses. */ diff --git a/include/error.h b/include/error.h index ecf74c937..3da2a90b0 100755 --- a/include/error.h +++ b/include/error.h @@ -1,5 +1,7 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * * Dual licensed under the MIT and GPL licenses. */ diff --git a/include/index.h b/include/index.h index 2d7254a50..cf58288e2 100755 --- a/include/index.h +++ b/include/index.h @@ -1,5 +1,7 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * * Dual licensed under the MIT and GPL licenses. */ diff --git a/include/odb.h b/include/odb.h index b0b32b4d1..19c07e900 100755 --- a/include/odb.h +++ b/include/odb.h @@ -1,5 +1,7 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * * Dual licensed under the MIT and GPL licenses. */ diff --git a/include/tag.h b/include/tag.h index 723e1d7c2..f75b28f90 100755 --- a/include/tag.h +++ b/include/tag.h @@ -1,5 +1,7 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * * Dual licensed under the MIT and GPL licenses. */ diff --git a/install.js b/install.js index 893daaf90..5434079fb 100644 --- a/install.js +++ b/install.js @@ -97,13 +97,13 @@ async.series([ }); }, function deleteExistingLibgit2BuildFolder(callback) { - fs.exists(libgit2BuildDirectory, function(exists) { - if (exists) { - fs.remove(libgit2BuildDirectory, callback); - } else { + // fs.exists(libgit2BuildDirectory, function(exists) { + // if (exists) { + // fs.remove(libgit2BuildDirectory, callback); + // } else { callback(); - } - }); + // } + // }); }, function createLibgit2BuildDirectory(callback) { console.log('[nodegit] Building libgit2 dependency.'); diff --git a/src/blob.cc b/src/blob.cc index dc68c5717..a65061b1d 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -1,5 +1,7 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * * Dual licensed under the MIT and GPL licenses. */ diff --git a/src/error.cc b/src/error.cc index 9a7565607..23f177981 100755 --- a/src/error.cc +++ b/src/error.cc @@ -1,5 +1,7 @@ -/* - * Copyright 2011, Tim Branyen @tbranyen +/** + * Copyright (c) 2011, Tim Branyen @tbranyen + * @author Michael Robinson @codeofinterest + * * Dual licensed under the MIT and GPL licenses. */ From e30cc6fdb942ec6e8dec975451d98883ffca0cdb Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 22:02:34 +1300 Subject: [PATCH 107/186] Tidied blob --- include/blob.h | 153 ++++--------------------------------------------- src/blob.cc | 40 ++++++------- 2 files changed, 28 insertions(+), 165 deletions(-) diff --git a/include/blob.h b/include/blob.h index e0ef511de..148a50c3a 100755 --- a/include/blob.h +++ b/include/blob.h @@ -20,177 +20,44 @@ using namespace v8; using namespace node; /** - * Class: GitBlob * Wrapper for libgit2 git_blob. */ class GitBlob : public ObjectWrap { public: - /** - * Variable: constructor_template - * Used to create Node.js constructor. - */ + static Persistent constructor_template; - /** - * Function: Initialize - * Used to intialize the EventEmitter from Node.js - * - * Parameters: - * target - Object the Node.js global module object - */ + static void Initialize(Handle target); - /** - * Accessor for GitBlob - * - * @return the internal git_blob reference - */ + git_blob* GetValue(); - /** - * Mutator for Object - * - * @param obj a git_object object - */ void SetValue(git_blob* blob); - /** - * Function: Lookup - * Lookup a blob object from a repository. - * - * Parameters: - * repo the repo to use when locating the blob. - * id identity of the blob to locate. - * - * Returns: - * 0 on success; error code otherwise - */ + int Lookup(git_repository* repo, const git_oid *id); - /** - * - * Function: Close - * Free a blob object. - */ - void Close(); - /** - * - * Function: CreateFromFile - * Read a file into the ODB. - * - * Returns: - * 0 on success, error code otherwise - */ + int CreateFromFile(git_oid* oid, git_repository* repo, const char* path); - /** - * - * Function: CreateFromBuffer - * Read a buffer into the ODB. - * - * Returns: - * 0 on success, error code otherwise - */ int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len); protected: - /** - * Constructor: GitBlob - */ GitBlob() {}; - /** - * Deconstructor: GitBlob - */ ~GitBlob() {}; - /** - * Function: New - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ + static Handle New(const Arguments& args); - /** - * Function: Lookup - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ + + static Handle CreateFromFile(const Arguments& args); + static Handle Lookup(const Arguments& args); - /** - * Function: LookupWork - * - * Parameters: - * req - an uv_work_t pointer - * - */ static void LookupWork(uv_work_t* req); - /** - * Function: LookupAfterWork - * - * Parameters: - * req - an uv_work_t pointer - */ static void LookupAfterWork(uv_work_t* req); - /** - * Function: RawContent - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ static Handle RawContent(const Arguments& args); static void RawContentWork(uv_work_t* req); static void RawContentAfterWork(uv_work_t* req); - /** - * Function: RawSize - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ - static Handle RawSize(const Arguments& args); - /** - * Function: Close - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ - static Handle Close(const Arguments& args); - /** - * Function: CreateFromFile - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ static Handle CreateFromFile(const Arguments& args); - /** - * Function: CreateFromBuffer - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ static Handle CreateFromBuffer(const Arguments& args); private: - /** - * Variable: blob - * Internal reference to git_blob object - */ + git_blob* blob; struct LookupBaton { diff --git a/src/blob.cc b/src/blob.cc index a65061b1d..f00c54170 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -28,7 +28,7 @@ void GitBlob::Initialize (Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); NODE_SET_PROTOTYPE_METHOD(tpl, "rawContent", RawContent); - NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); + NODE_SET_PROTOTYPE_METHOD(tpl, "free", Free); NODE_SET_PROTOTYPE_METHOD(tpl, "createFromFile", CreateFromFile); NODE_SET_PROTOTYPE_METHOD(tpl, "createFromBuffer", CreateFromBuffer); @@ -43,17 +43,6 @@ void GitBlob::SetValue(git_blob* blob) { this->blob = blob; } -void GitBlob::Close() { - git_blob_free(this->blob); -} - -int CreateFromFile(git_oid* oid, git_repository* repo, const char* path) { - return git_blob_create_fromdisk(oid, repo, path); -} -int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len) { - return git_blob_create_frombuffer(oid, repo, buffer, len); -} - Handle GitBlob::New(const Arguments& args) { HandleScope scope; @@ -63,6 +52,23 @@ Handle GitBlob::New(const Arguments& args) { return scope.Close( args.This() ); } +Handle GitBlob::Free(const Arguments& args) { + HandleScope scope; + + GitBlob* blob = ObjectWrap::Unwrap(args.This()); + git_blob_free(blob->blob); + + return scope.Close( Undefined() ); +} + + +int CreateFromFile(git_oid* oid, git_repository* repo, const char* path) { + return git_blob_create_fromdisk(oid, repo, path); +} +int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len) { + return git_blob_create_frombuffer(oid, repo, buffer, len); +} + Handle GitBlob::Lookup(const Arguments& args) { HandleScope scope; @@ -162,16 +168,6 @@ void GitBlob::RawContentAfterWork(uv_work_t* req) { delete req; } -Handle GitBlob::Close(const Arguments& args) { - HandleScope scope; - - GitBlob* blob = ObjectWrap::Unwrap(args.This()); - - blob->Close(); - - return scope.Close( Undefined() ); -} - Handle GitBlob::CreateFromFile(const Arguments& args) { HandleScope scope; From 0f9f8646f0fa2af8cb5e2e262f90c7c25e6e2f6f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 22:02:46 +1300 Subject: [PATCH 108/186] Updated blob constructor --- lib/blob.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/blob.js b/lib/blob.js index a5e8f103e..fdedb8997 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -13,7 +13,8 @@ var Blob = function(rawRepo, rawBlob) { } this.rawRepo = rawRepo; - if(rawBlob instanceof git.raw.Blob) { + if(typeof rawBlob !== 'undefined' && + rawBlob instanceof git.raw.Blob) { this.rawBlob = rawBlob; } else { this.rawBlob = new git.raw.Blob(this.rawRepo); From 7c5aa91dea6553058d41b0514f088ef5933eff74 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 22:16:22 +1300 Subject: [PATCH 109/186] Updated utilities test --- test/utilities.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/utilities.js b/test/utilities.js index 36ed198cb..6ed99f9d9 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -1,22 +1,26 @@ var git = require('../'), utilities = require('../lib/utilities'); -var object = { - property: 'value' -}; +exports.successNoError = function(test){ + test.expect(0); -var details = { - one: 'one', - two: 'two' + if (utilities.success(null, function() { })) { + test.done(); + } }; -// Repo -exports.basic = function(test){ - test.expect(2); - - object = utilities.applyProperties(details, object); - test.equal(object.one, details.one, 'Properties should match'); - test.equal(object.two, details.two, 'Properties should match'); - - test.done(); +/** + * Test whether success function calls callback with error + */ +exports.successError = function(test){ + test.expect(3); + utilities.success(git.error({ + code: git.raw.Error.codes.GITERR_INVALID, + message: 'Message' + }), function(error) { + test.notEqual(error, null, 'Error should not be null'); + test.equal(error.code, git.raw.Error.codes.GITERR_INVALID, 'Error code should match input'); + test.equal(error.message, 'Message', 'Error message should match input'); + test.done(); + }); }; From 082ad35db127d860d8d0f207b16bc40d615c2790 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 22:16:37 +1300 Subject: [PATCH 110/186] Removed details test from raw-commit tests --- test/raw-commit.js | 51 ---------------------------------------------- 1 file changed, 51 deletions(-) diff --git a/test/raw-commit.js b/test/raw-commit.js index e66443ca5..2e6c6a115 100644 --- a/test/raw-commit.js +++ b/test/raw-commit.js @@ -93,54 +93,3 @@ exports.lookup = function(test) { }); }); }; - -exports.fetchDetails = function(test) { - - test.expect(14); - - var testOid = new git.Oid(); - testOid.mkstr('cb76e3c030ab29db332aff3b297dc39451a84762'); - testRepo.open(path.resolve('../.git'), function() { - var testCommit = new git.Commit(); - testCommit.lookup(testRepo, testOid, function(error, commit) { - commit.fetchDetails(function(error, details) { - - var expected = { - sha: 'cb76e3c030ab29db332aff3b297dc39451a84762', - message: 'bumped package.json up\n', - time: 1300145116, - timeOffset: -240, - committer: - { name: 'Tim Branyen', - email: 'tim.branyen@gmail.com', - when: { time: 1300145116, offset: -240 } }, - author: - { name: 'Tim Branyen', - email: 'tim.branyen@gmail.com', - when: { time: 1300145116, offset: -240 } }, - parentCount: 1, - parentShas: [ 'b1f941c62f508db5f392a6bb0ea1d591753a045b' ] }; - - test.equals(expected.sha, details.sha, 'Expected SHA does not match result'); - test.equals(expected.message, details.message, 'Expected message does not match result'); - test.equals(expected.time, details.time, 'Expected time does not match result'); - test.equals(expected.offset, details.offset, 'Expected offset does not match result'); - - test.equals(expected.committer.name, details.committer.name, 'Expected committer.name does not match result'); - test.equals(expected.committer.email, details.committer.email, 'Expected committer.email does not match result'); - test.equals(expected.committer.when.time, details.committer.when.time, 'Expected committer.when.time does not match result'); - test.equals(expected.committer.when.offset, details.committer.when.offset, 'Expected committer.when.offset does not match result'); - - test.equals(expected.author.name, details.author.name, 'Expected author.name does not match result'); - test.equals(expected.author.email, details.author.email, 'Expected author.email does not match result'); - test.equals(expected.author.when.time, details.author.when.time, 'Expected author.when.time does not match result'); - test.equals(expected.author.when.offset, details.author.when.offset, 'Expected author.when.offset does not match result'); - - test.equals(expected.parentCount, details.parentCount, 'Expected parentCount does not match result'); - test.equals(expected.parentShas[0], details.parentShas[0], 'Expected parentShas[0] does not match result'); - - test.done(); - }); - }); - }); -}; From 803ea049c9bbd453d8655afd388c30c10a658536 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Tue, 2 Apr 2013 22:16:48 +1300 Subject: [PATCH 111/186] Updated convenience-tree tests --- test/convenience-tree.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/test/convenience-tree.js b/test/convenience-tree.js index 5144a0137..f4bcf0e2e 100644 --- a/test/convenience-tree.js +++ b/test/convenience-tree.js @@ -9,19 +9,18 @@ exports.walk = function(test) { test.expect(516); git.repo('../.git', function(error, repo) { - if(error) { throw error; } - // @todo assert repo is correct repo.commit(sha, function(error, commit) { - if(error) { throw error; } var entryCount = 0; - commit.tree().walk().on('entry', function(error, index, entry) { + commit.tree(function(error, tree) { + tree.walk().on('entry', function(error, index, entry) { + test.equals(error, null, 'There should be no error'); + entryCount++; + }).on('end', function(error, entries) { test.equals(error, null, 'There should be no error'); - entryCount++; - }).on('end', function(error, entries) { - test.equals(error, null, 'There should be no error'); - test.equals(entryCount, fileCount, 'The manual tree entry count and the "end" tree entry count do not match'); - test.equals(entries.length, fileCount, 'The end entries count and the manual entry count do not match'); - test.done(); + test.equals(entryCount, fileCount, 'The manual tree entry count and the "end" tree entry count do not match'); + test.equals(entries.length, fileCount, 'The end entries count and the manual entry count do not match'); + test.done(); + }); }); }); }); From 989c0aab4994c7ecae4ee74c2db720dae16bade5 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:05:33 +1300 Subject: [PATCH 112/186] Ignore out, test.git --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e0cc348f1..42cebca29 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ !doc/Theme.css /node_modules /testing.js +/out +/test.git From fb0561bcd3ea37f3417a97df15c772ffd4446e17 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:06:07 +1300 Subject: [PATCH 113/186] Updated documentation --- lib/blob.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/blob.js b/lib/blob.js index fdedb8997..19873198a 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -4,8 +4,9 @@ var git = require('../'), /** * Blob convenience class constructor. * - * @param {git.raw.Repo} rawRepo - * @param {git.raw.Blob|null} rawBlob + * @constructor + * @param {git.raw.Repo} rawRepo Raw repository object. + * @param {git.raw.Blob} [rawBlob = new git.raw.Blob(rawRepo)] Raw blob object. */ var Blob = function(rawRepo, rawBlob) { if(!(rawRepo instanceof git.raw.Repo)) { @@ -24,10 +25,15 @@ var Blob = function(rawRepo, rawBlob) { /** * Retrieve the blob represented by the oid. * - * @param {git.raw.Oid} oid - * @param {Function} callback + * @param {git.raw.Oid} oid The OID representing the blob to lookup. + * @param {Blob~lookupCallback} callback */ Blob.prototype.lookup = function(oid, callback) { + /** + * @callback Blob~lookupCallback Callback executed on lookup completion. + * @param {GitError|null} error An Error or null if successful. + * @param {Blob|null} blob The populated blob object or null. + */ var self = this; self.rawBlob.lookup(self.rawRepo, oid, function blobLookup(error, rawBlob) { if (success(error, callback)) { @@ -40,9 +46,14 @@ Blob.prototype.lookup = function(oid, callback) { /** * Retrieve the blob's raw content buffer. * - * @param {Function} callback + * @param {Blob~rawContentCallback} callback */ Blob.prototype.rawContent = function(callback) { + /** + * @callback Blob~rawContentCallback Callback executed after raw content is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {Buffer|null} content The raw content of the blob or null. + */ this.rawBlob.rawContent(function(error, content) { if (success(error, callback)) { callback(null, content); @@ -53,9 +64,14 @@ Blob.prototype.rawContent = function(callback) { /** * Retrieve the blob's content. * - * @param {Function} callback + * @param {Blob~contentCallback} callback */ Blob.prototype.content = function(callback) { + /** + * @callback Blob~contentCallback Callback executed after content is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} content The content of the blob or null. + */ this.rawContent(function(error, content) { if (success(error, callback)) { callback(null, content.toString()); From 904e3a5667d375bd77beb8760d8a73f8ba97b33c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:06:31 +1300 Subject: [PATCH 114/186] Tidied blob.h --- include/blob.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/include/blob.h b/include/blob.h index 148a50c3a..49a2e5b8c 100755 --- a/include/blob.h +++ b/include/blob.h @@ -32,18 +32,12 @@ class GitBlob : public ObjectWrap { git_blob* GetValue(); void SetValue(git_blob* blob); - int Lookup(git_repository* repo, const git_oid *id); - - int CreateFromFile(git_oid* oid, git_repository* repo, const char* path); - int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len); - protected: GitBlob() {}; ~GitBlob() {}; static Handle New(const Arguments& args); - - static Handle CreateFromFile(const Arguments& args); + static Handle Free(const Arguments& args); static Handle Lookup(const Arguments& args); static void LookupWork(uv_work_t* req); From 1c3b10267f74083c3a417440852215838b724f32 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:10:55 +1300 Subject: [PATCH 115/186] Updated convenience-repo.js --- test/convenience-repo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/convenience-repo.js b/test/convenience-repo.js index 42ee81f40..d01f7ec72 100644 --- a/test/convenience-repo.js +++ b/test/convenience-repo.js @@ -39,7 +39,7 @@ exports.method = function(test){ // Test invalid repository git.repo('/etc/hosts', function(error, repository) { - test.equals(error.code, error.GITERR_REPOSITORY, error.message, 'Invalid repository error code'); + test.equals(error.code, error.codes.GITERR_REPOSITORY, error.message, 'Invalid repository error code'); // Test valid repository git.repo('../.git', function(error, repository) { From 895309b1178a78bdb4335df18266b998d5e090e7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:11:03 +1300 Subject: [PATCH 116/186] Removed commented line --- test/raw-commit.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/raw-commit.js b/test/raw-commit.js index 2e6c6a115..190458f3b 100644 --- a/test/raw-commit.js +++ b/test/raw-commit.js @@ -85,9 +85,6 @@ exports.lookup = function(test) { testOid.mkstr('cb76e3c030ab29db332aff3b297dc39451a84762'); testCommit.lookup(testRepo, testOid, function(err) { test.equals(null, err, 'Valid commit'); - - //test.equals('Updated gitignore and raw-commit test', testCommit.messageShort(), 'Commit message is valid'); - test.done(); }); }); From 5e1d45ce90ec43ea4eaf81c5e06edc4eab9e0594 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:11:38 +1300 Subject: [PATCH 117/186] Removed blob raw size test --- test/raw-blob.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/raw-blob.js b/test/raw-blob.js index 50629b4a3..f7e70e276 100644 --- a/test/raw-blob.js +++ b/test/raw-blob.js @@ -120,19 +120,6 @@ exports.rawContent = function(test) { test.done(); }; -// Blob::RawSize -exports.rawSize = function(test) { - var testOid = new git.Oid(), - testBlob = new git.Blob(); - - test.expect(2); - - // Test for function - helper.testFunction(test.equals, testBlob.rawSize, 'Blob::RawSize'); - - test.done(); -}; - // Blob::Close exports.close = function(test) { var testOid = new git.Oid(), From 75b02e53c95edf762f4501c5ed9f207515e38d1f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:47:54 +1300 Subject: [PATCH 118/186] Removed unecessary code --- src/blob.cc | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/blob.cc b/src/blob.cc index f00c54170..f0ecf0301 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -51,7 +51,6 @@ Handle GitBlob::New(const Arguments& args) { return scope.Close( args.This() ); } - Handle GitBlob::Free(const Arguments& args) { HandleScope scope; @@ -61,14 +60,6 @@ Handle GitBlob::Free(const Arguments& args) { return scope.Close( Undefined() ); } - -int CreateFromFile(git_oid* oid, git_repository* repo, const char* path) { - return git_blob_create_fromdisk(oid, repo, path); -} -int CreateFromBuffer(git_oid* oid, git_repository* repo, const void* buffer, size_t len) { - return git_blob_create_frombuffer(oid, repo, buffer, len); -} - Handle GitBlob::Lookup(const Arguments& args) { HandleScope scope; @@ -99,7 +90,7 @@ Handle GitBlob::Lookup(const Arguments& args) { } void GitBlob::LookupWork(uv_work_t* req) { LookupBaton* baton = static_cast(req->data); - int returnCode = git_blob_lookup(&baton->rawBlob, baton->rawRepo, &baton->rawOid); + int returnCode = git_blob_lookup(&baton->rawBlob, baton->rawRepo, &baton->rawOid); if (returnCode != GIT_OK) { baton->error = giterr_last(); } From 66a05308f0e1d6292410c14119b58fa1a6c92e55 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:48:10 +1300 Subject: [PATCH 119/186] Refactored createFromFile & createFromBuffer --- include/blob.h | 30 ++++++++++++ src/blob.cc | 126 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 128 insertions(+), 28 deletions(-) diff --git a/include/blob.h b/include/blob.h index 49a2e5b8c..0afdb6c9a 100755 --- a/include/blob.h +++ b/include/blob.h @@ -48,7 +48,12 @@ class GitBlob : public ObjectWrap { static void RawContentAfterWork(uv_work_t* req); static Handle CreateFromFile(const Arguments& args); + static void CreateFromFileWork(uv_work_t* req); + static void CreateFromFileAfterWork(uv_work_t* req); + static Handle CreateFromBuffer(const Arguments& args); + static void CreateFromBufferWork(uv_work_t* req); + static void CreateFromBufferAfterWork(uv_work_t* req); private: @@ -76,6 +81,31 @@ class GitBlob : public ObjectWrap { Persistent callback; }; + + struct CreateFromFileBaton { + uv_work_t request; + const git_error* error; + + GitBlob* blob; + git_blob* rawBlob; + git_repository* rawRepo; + std::string path; + + Persistent callback; + }; + + struct CreateFromBufferBaton { + uv_work_t request; + const git_error* error; + + GitBlob* blob; + git_blob* rawBlob; + git_repository* rawRepo; + const void* data; + size_t dataLength; + + Persistent callback; + }; }; #endif diff --git a/src/blob.cc b/src/blob.cc index f0ecf0301..391e7534d 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -13,6 +13,7 @@ #include "../include/repo.h" #include "../include/blob.h" +#include "../include/functions/string.h" #include "../include/functions/utilities.h" using namespace v8; @@ -162,59 +163,128 @@ void GitBlob::RawContentAfterWork(uv_work_t* req) { Handle GitBlob::CreateFromFile(const Arguments& args) { HandleScope scope; - GitBlob* blob = ObjectWrap::Unwrap(args.This()); - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid is required and must be an Object."))); - } - - if(args.Length() == 1 || !args[1]->IsObject()) { return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); } - if(args.Length() == 2 || !args[2]->IsString()) { + if(args.Length() == 1 || !args[1]->IsString()) { return ThrowException(Exception::Error(String::New("Path is required and must be an String."))); } - GitOid* oid = ObjectWrap::Unwrap(args[0]->ToObject()); - GitRepo* repo = ObjectWrap::Unwrap(args[1]->ToObject()); + if(args.Length() == 2 || !args[2]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be an Function."))); + } - String::Utf8Value path(args[2]); + CreateFromFileBaton* baton = new CreateFromFileBaton; + baton->request.data = baton; + baton->error = NULL; + baton->blob = ObjectWrap::Unwrap(args.This()); + baton->blob->Ref(); + baton->rawBlob = baton->blob->GetValue(); + baton->rawRepo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->path = stringArgToString(args[1]->ToString()); + baton->callback = Persistent::New(Local::Cast(args[2])); - git_oid tmp_oid = oid->GetValue(); - int err = blob->CreateFromFile(&tmp_oid, repo->GetValue(), *path); + uv_queue_work(uv_default_loop(), &baton->request, CreateFromFileWork, (uv_after_work_cb)CreateFromFileAfterWork); - return scope.Close( Integer::New(err) ); + return Undefined(); } +void GitBlob::CreateFromFileWork(uv_work_t* req) { + CreateFromFileBaton* baton = static_cast(req->data); -Handle GitBlob::CreateFromBuffer(const Arguments& args) { + git_oid* rawOid = NULL; + int returnCode = git_blob_create_fromdisk(rawOid, baton->rawRepo, baton->path.c_str()); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + return; + } + + returnCode = git_blob_lookup(&baton->rawBlob, baton->rawRepo, rawOid); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + } +} +void GitBlob::CreateFromFileAfterWork(uv_work_t* req) { HandleScope scope; + CreateFromFileBaton* baton = static_cast(req->data); - GitBlob* blob = ObjectWrap::Unwrap(args.This()); + baton->blob->SetValue(baton->rawBlob); - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid is required and must be an Object."))); + Handle argv[2] = { + Local::New(Null()), + baton->blob->handle_ + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); } + delete req; +} - if(args.Length() == 1 || !args[1]->IsObject()) { +Handle GitBlob::CreateFromBuffer(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); } - if(args.Length() == 2 || !Buffer::HasInstance(args[2])) { - return ThrowException(Exception::Error(String::New("Buffer is required and must be a Buffer."))); + if(args.Length() == 1 || !Buffer::HasInstance(args[1])) { + return ThrowException(Exception::Error(String::New("Buffer is required and must be an Buffer."))); } - GitOid* oid = ObjectWrap::Unwrap(args[0]->ToObject()); - GitRepo* repo = ObjectWrap::Unwrap(args[1]->ToObject()); - Local buffer = args[2]->ToObject(); + if(args.Length() == 2 || !args[2]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be an Function."))); + } - const void* data = Buffer::Data(buffer); - size_t length = Buffer::Length(buffer); + CreateFromBufferBaton* baton = new CreateFromBufferBaton; + baton->request.data = baton; + baton->error = NULL; + baton->blob = ObjectWrap::Unwrap(args.This()); + baton->blob->Ref(); + baton->rawBlob = baton->blob->GetValue(); + baton->rawRepo = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + Local buffer = args[1]->ToObject(); + baton->data = Buffer::Data(buffer); + baton->dataLength = Buffer::Length(buffer); + baton->callback = Persistent::New(Local::Cast(args[2])); - git_oid tmp_oid = oid->GetValue(); - int err = blob->CreateFromBuffer(&tmp_oid, repo->GetValue(), data, length); + uv_queue_work(uv_default_loop(), &baton->request, CreateFromFileWork, (uv_after_work_cb)CreateFromFileAfterWork); - return scope.Close( Integer::New(err) ); + return Undefined(); +} +void GitBlob::CreateFromBufferWork(uv_work_t* req) { + CreateFromBufferBaton* baton = static_cast(req->data); + + git_oid* rawOid = NULL; + int returnCode = git_blob_create_frombuffer(rawOid, baton->rawRepo, baton->data, baton->dataLength); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + } + + returnCode = git_blob_lookup(&baton->rawBlob, baton->rawRepo, rawOid); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + } +} +void GitBlob::CreateFromBufferAfterWork(uv_work_t* req) { + HandleScope scope; + CreateFromBufferBaton* baton = static_cast(req->data); + + baton->blob->SetValue(baton->rawBlob); + + Handle argv[2] = { + Local::New(Null()), + baton->blob->handle_ + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; } Persistent GitBlob::constructor_template; From 8740f0f7a82a15389a58fd74e5b0694ba5b73cd9 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:49:22 +1300 Subject: [PATCH 120/186] Updated tree documentation --- lib/tree.js | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/tree.js b/lib/tree.js index 7182f08d9..0a037ba7c 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -5,8 +5,9 @@ var git = require('../'), /** * Tree convenience class constructor. * - * @param {git.raw.Repo} rawRepo - * @param {git.raw.Tree|null} rawTree + * @constructor + * @param {git.raw.Repo} rawRepo Raw repository object. + * @param {git.raw.Tree} [rawTree = new git.raw.Tree(rawRepo)] Raw tree object. */ var Tree = function(rawRepo, rawTree) { if(!(rawRepo instanceof git.raw.Repo)) { @@ -17,17 +18,22 @@ var Tree = function(rawRepo, rawTree) { if(rawTree instanceof git.raw.Tree) { this.rawTree = rawTree; } else { - this.rawTree = new git.raw.Tree(this.rawRepo); + this.rawTree = new git.raw.Tree(rawRepo); } }; /** * Retrieve the entry by path. * - * @param {String} path - * @param {Function} callback + * @param {String} path Path to the tree entry, relative to repository root. + * @param {Tree~entryCallback} callback */ Tree.prototype.entry = function(path, callback) { + /** + * @callback Tree~entryCallback Callback executed when an entry is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {Entry|null} blob The tree entry object or null. + */ var self = this; self.rawTree.entryByPath(path, function(error, rawEntry) { if (success(error, callback)) { @@ -36,6 +42,14 @@ Tree.prototype.entry = function(path, callback) { }); }; +/** + * Walk the tree. + * + * @fires Tree#entry + * @fires Tree#end + * + * @return {EventEmitter} + */ Tree.prototype.walk = function() { var self = this, event = new events.EventEmitter(), @@ -46,6 +60,14 @@ Tree.prototype.walk = function() { var entry = new git.entry(self.rawRepo, rawEntry); entries.push(entry); if (!error) { + /** + * Entry event. + * + * @event Tree#entry + * + * @param {GitError|null} error An error object if there was an issue, null otherwise. + * @param {Entry} entry The tree entry. + */ event.emit('entry', null, entry); } }); @@ -53,6 +75,14 @@ Tree.prototype.walk = function() { if (error) { event.emit('end', git.error(error), entries); } + /** + * End event. + * + * @event Tree#end + * + * @param {GitError|null} error An error object if there was an issue, null otherwise. + * @param {Entry[]} entries The tree entries. + */ event.emit('end', null, entries); }); From dfab61a0df429edf12e8f005ae62c782a6d7445d Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:49:36 +1300 Subject: [PATCH 121/186] Refactored error --- lib/error.js | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/error.js b/lib/error.js index ede0aadaf..103d91dff 100644 --- a/lib/error.js +++ b/lib/error.js @@ -4,8 +4,9 @@ var git = require('../'), /** * GitError constructor. * - * @param {String} message giterr_last->message - * @param {Integer} code giterr_last->klass + * @constructor + * @param {String} message The error description. Set from giterr_last->message. + * @param {Integer} [code = git.raw.Error.codes.GITERR_INVALID] The error code. Set from giterr_last->klass */ var GitError = function(message, code) { Error.call(this); @@ -19,21 +20,43 @@ var GitError = function(message, code) { util.inherits(GitError, Error); /** - * Add libgit2 error codes to git.error object. - * * Refer to vendor/libgit2/include/git2/errors.h for error code definitions. + * + * @readonly + * @enum {Integer} */ -for (var errorName in git.raw.Error.codes) { - GitError.prototype[errorName] = git.raw.Error.codes[errorName]; -} +GitError.prototype.codes = { + /** 0 */ GITERR_NOMEMORY: git.raw.Error.codes['GITERR_NOMEMORY'], + /** 1 */ GITERR_OS: git.raw.Error.codes['GITERR_OS'], + /** 2 */ GITERR_INVALID: git.raw.Error.codes['GITERR_INVALID'], + /** 3 */ GITERR_REFERENCE: git.raw.Error.codes['GITERR_REFERENCE'], + /** 4 */ GITERR_ZLIB: git.raw.Error.codes['GITERR_ZLIB'], + /** 5 */ GITERR_REPOSITORY: git.raw.Error.codes['GITERR_REPOSITORY'], + /** 6 */ GITERR_CONFIG: git.raw.Error.codes['GITERR_CONFIG'], + /** 7 */ GITERR_REGEX: git.raw.Error.codes['GITERR_REGEX'], + /** 8 */ GITERR_ODB: git.raw.Error.codes['GITERR_ODB'], + /** 9 */ GITERR_INDEX: git.raw.Error.codes['GITERR_INDEX'], + /** 10 */ GITERR_OBJECT: git.raw.Error.codes['GITERR_OBJECT'], + /** 11 */ GITERR_NET: git.raw.Error.codes['GITERR_NET'], + /** 12 */ GITERR_TAG: git.raw.Error.codes['GITERR_TAG'], + /** 13 */ GITERR_TREE: git.raw.Error.codes['GITERR_TREE'] +}; /** - * Add libgit2 return codes to git.error object. - * * Refer to vendor/libgit2/include/git2/errors.h for return code definitions. + * + * @readonly + * @enum {Integer} */ -for (var errorName in git.raw.Error.returnCodes) { - GitError.prototype[errorName] = git.raw.Error.returnCodes[errorName]; +GitError.prototype.returnCodes = { + /** 0 */ GIT_OK: git.raw.Error.returnCodes['GIT_OK'], + /** -1 */ GIT_ERROR: git.raw.Error.returnCodes['GIT_ERROR'], + /** -3 */ GIT_ENOTFOUND: git.raw.Error.returnCodes['GIT_ENOTFOUND'], + /** -4 */ GIT_EEXISTS: git.raw.Error.returnCodes['GIT_EEXISTS'], + /** -5 */ GIT_EAMBIGUOUS: git.raw.Error.returnCodes['GIT_EAMBIGUOUS'], + /** -6 */ GIT_EBUFS: git.raw.Error.returnCodes['GIT_EBUFS'], + /** -30 */ GIT_PASSTHROUGH: git.raw.Error.returnCodes['GIT_PASSTHROUGH'], + /** -31 */ GIT_ITEROVER: git.raw.Error.returnCodes['GIT_ITEROVER'] } exports.error = function(error) { From bf568bdec91ebc4c11f6512b7ab1e6633051d80b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:50:43 +1300 Subject: [PATCH 122/186] Removed jquery stress submodules --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index c7bc5e0e7..ca6a48f0b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "example/stress/jquery"] - path = example/stress/jquery - url = https://github.com/jquery/jquery.git [submodule "vendor/libgit2"] path = vendor/libgit2 url = git://github.com/libgit2/libgit2.git From 4c48b115c9f3dc935e5345fc21cd3c3640f9051a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:50:59 +1300 Subject: [PATCH 123/186] Updated commit documentation --- lib/commit.js | 109 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 20 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index a683f662a..e80c46689 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -6,8 +6,8 @@ var git = require( '../' ), * Convenience commit constructor. * * @constructor - * @param {RawCommit|Null} rawCommit - * @return {Commit} + * @param {git.raw.Repo} rawRepo Raw repository object. + * @param {git.raw.Commit} [rawCommit = new git.raw.Commit(rawRepo)] Raw commit object. */ var Commit = function(rawRepo, rawCommit) { if (!(rawRepo instanceof git.raw.Repo)) { @@ -26,10 +26,15 @@ var Commit = function(rawRepo, rawCommit) { /** * Look up the commit referenced by oid, replace this.commit with the result. * - * @param {git.oid|git.raw.Oid|String} oid - * @param {Function} callback + * @param {Oid|git.raw.Oid|String} oid A representation of an OID used to lookup the commit. + * @param {Commit~lookupCallback} callback */ Commit.prototype.lookup = function(oid, callback) { + /** + * @callback Commit~lookupCallback Callback executed on lookup completion. + * @param {GitError|null} error An Error or null if successful. + * @param {Commit|null} commit Retrieved commit object or null. + */ if (typeof oid !== 'undefined' && typeof oid !== 'string' && !(oid instanceof git.raw.Oid)) { @@ -45,20 +50,30 @@ Commit.prototype.lookup = function(oid, callback) { }; /** - * Retrieve the commit's Oid + * Retrieve the commit's OID. * - * @param {Function} callback + * @param {Commit~oidCallback} callback */ Commit.prototype.oid = function(callback) { + /** + * @callback Commit~oidCallback Callback executed on OID retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Oid|null} commit Retrieved OID object or null. + */ callback(null, new git.oid(this.rawCommit.oid())); }; /** - * Retrieve the SHA + * Retrieve the SHA. * - * @param {Function} callback + * @param {Commit~shaCallback} callback */ Commit.prototype.sha = function(callback) { + /** + * @callback Commit~shaCallback Callback executed on SHA retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} sha Retrieved SHA. + */ this.rawCommit.sha(function(error, sha) { if (success(error, callback)) { callback(null, sha); @@ -69,9 +84,14 @@ Commit.prototype.sha = function(callback) { /** * Retrieve the message * - * @param {Function} callback + * @param {Commit~messageCallback} callback */ Commit.prototype.message = function(callback) { + /** + * @callback Commit~messageCallback Callback executed on message retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} message Retrieved message. + */ this.rawCommit.message(function(error, message) { if (success(error, callback)) { callback(null, message); @@ -80,11 +100,16 @@ Commit.prototype.message = function(callback) { }; /** - * Retrieve the commit unix timestamp. + * Retrieve the commit time as a unix timestamp in seconds. * - * @param {Function} callback + * @param {Commit~timeCallback} callback */ Commit.prototype.time = function(callback) { + /** + * @callback Commit~timeCallback Callback executed on time retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Integer|null} time Retrieved time in seconds. + */ this.rawCommit.time(function(error, time) { if (success(error, callback)) { callback(null, time); @@ -95,9 +120,14 @@ Commit.prototype.time = function(callback) { /** * Retrieve the commit's positive or negative timezone offset, in minutes from UTC. * - * @param {Function} callback + * @param {Commit~offsetCallback} callback */ Commit.prototype.offset = function(callback) { + /** + * @callback Commit~offsetCallback Callback executed on offset retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Integer|null} offset Retrieved offset in in minutes from UTC. + */ this.rawCommit.offset(function(error, offset) { if (success(error, callback)) { callback(null, offset); @@ -106,11 +136,16 @@ Commit.prototype.offset = function(callback) { }; /** - * Retrieve the commit's author. + * Retrieve the commit's author signature. * - * @param {Function} callback + * @param {Commit~authorCallback} callback */ Commit.prototype.author = function(callback) { + /** + * @callback Commit~authorCallback Callback executed on author retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Signature|null} author Retrieved author signature. + */ this.rawCommit.author(function(error, rawSignature) { if (success(error, callback)) { callback(null, new git.signature(rawSignature)); @@ -121,9 +156,14 @@ Commit.prototype.author = function(callback) { /** * Retrieve the commit's committer. * - * @param {Function} callback + * @param {Commit~committerCalback} callback */ Commit.prototype.committer = function(callback) { + /** + * @callback Commit~committerCallback Callback executed on committer retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Signature|null} committer Retrieved committer signature. + */ this.rawCommit.committer(function(error, rawSignature) { if (success(error, callback)) { callback(null, new git.signature(rawSignature)); @@ -134,9 +174,14 @@ Commit.prototype.committer = function(callback) { /** * Retrieve the tree for this commit. * - * @param {Function} callback + * @param {Commit~treeCallback} callback */ Commit.prototype.tree = function(callback) { + /** + * @callback Commit~treeCallback Callback executed on tree retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Tree|null} tree Retrieved tree. + */ var self = this; self.rawCommit.tree(function commitTree(error, rawTree) { if (success(error, callback)) { @@ -147,11 +192,17 @@ Commit.prototype.tree = function(callback) { /** * Retrieve the file represented by path for this commit. + * Path must be relative to repository root. * - * @param {String} path - * @param {Function} callback + * @param {String} path + * @param {Commit~fileCallback} callback */ Commit.prototype.file = function(path, callback) { + /** + * @callback Commit~fileCallback Callback executed on file retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Entry|null} file Retrieved file entry. + */ this.tree(function commitFile(error, tree) { if (!success(error, callback)) { return; @@ -167,8 +218,10 @@ Commit.prototype.file = function(path, callback) { /** * Walk the history of this commit. * - * @return {Event} Event emits 'commit', with error, commit and 'end', with - * error, commits[] + * @fires Commit#commit + * @fires Commit#end + * + * @return {EventEmitter} Event */ Commit.prototype.history = function() { var event = new events.EventEmitter(), @@ -184,9 +237,25 @@ Commit.prototype.history = function() { } if (noMoreCommits) { + /** + * End event. + * + * @event Commit#end + * + * @param {GitError|null} error An error object if there was an issue, null otherwise. + * @param {Commit[]} commits The commits. + */ event.emit('end', null, commits); return; } + /** + * Commit event. + * + * @event Commit#commit + * + * @param {GitError|null} error An error object if there was an issue, null otherwise. + * @param {Commit} commit The commit. + */ event.emit('commit', null, commit); commits.push(commit); }); From e3325f5d9b6e157aa458902905047ef7e0b4d6aa Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:51:14 +1300 Subject: [PATCH 124/186] Added createFromFile & createFromBuffer to blob js --- lib/blob.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/lib/blob.js b/lib/blob.js index 19873198a..b1e265532 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -32,7 +32,7 @@ Blob.prototype.lookup = function(oid, callback) { /** * @callback Blob~lookupCallback Callback executed on lookup completion. * @param {GitError|null} error An Error or null if successful. - * @param {Blob|null} blob The populated blob object or null. + * @param {Blob|null} blob Retrieved blob object or null. */ var self = this; self.rawBlob.lookup(self.rawRepo, oid, function blobLookup(error, rawBlob) { @@ -79,4 +79,46 @@ Blob.prototype.content = function(callback) { }); }; +/** + * Create a new blob from the file at the given path. + * + * @param {String} path Full path to the file. + * @param {Blob~createFromFileCallback} callback + */ +Blob.prototype.createFromFile = function(path, callback) { + /** + * @callback Blob~createFromFileCallback Callback executed after blob is created. + * @param {GitError|null} error An Error or null if successful. + * @param {Blob|null} content The new blob or null. + */ + var self = this; + self.rawBlob.createFromFile(path, self.rawRepo, function blobCreateFromFileCallback(error, rawBlob) { + if (success(error, callback)) { + self.rawBlob = rawBlob; + callback(null, self); + } + }); +}; + +/** + * Create a new blob from the given buffer. + * + * @param {Buffer} buffer Buffer used to create blob. + * @param {Blob~createFromBufferCallback} callback + */ +Blob.prototype.createFromFile = function(path, callback) { + /** + * @callback Blob~createFromBufferCallback Callback executed after blob is created. + * @param {GitError|null} error An Error or null if successful. + * @param {Blob|null} content The new blob or null. + */ + var self = this; + self.rawBlob.createFromBuffer(buffer, self.rawRepo, function blobCreateFromBufferCallback(error, rawBlob) { + if (success(error, callback)) { + self.rawBlob = rawBlob; + callback(null, self); + } + }); +}; + exports.blob = Blob; From 5abba2bcacf41021447cc2e26fd95286b73d75a8 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:52:04 +1300 Subject: [PATCH 125/186] Removed jquery --- example/stress/commit.js | 44 ----------------------------- example/stress/jquery | 1 - example/stress/repo.js | 50 --------------------------------- example/stress/revwalk.js | 58 --------------------------------------- 4 files changed, 153 deletions(-) delete mode 100644 example/stress/commit.js delete mode 160000 example/stress/jquery delete mode 100644 example/stress/repo.js delete mode 100644 example/stress/revwalk.js diff --git a/example/stress/commit.js b/example/stress/commit.js deleted file mode 100644 index d1dd0b2a6..000000000 --- a/example/stress/commit.js +++ /dev/null @@ -1,44 +0,0 @@ -var git = require( '../../' ).raw; - -//* Stress test basic commit - setInterval(function() { - for(var i=0; i<10000; i++) { - (function() { - - var start = new Date; - - var repo = new git.Repo(); - repo.open( 'jquery/.git', function() { - var commit = new git.Commit(); - - //console.log( 'Time taken: ' + (+new Date-start) + 'ms' ); - }); - - })(); - } - }, 0); -//*/ - -//* Stress test repo open - setInterval(function() { - for(var i=0; i<10000; i++) { - - (function() { - var start = new Date; - - var repo = new git.Repo(); - repo.open( 'jquery/.git', function() { - var oid = new git.Oid(); - oid.mkstr( 'cf702496ee28830f3488ed3f1c3940cfbb2dfa8f' ); - - var commit = new git.Commit(); - commit.lookup( repo, oid, function( err ) { - //console.log( 'Time taken: ' + (+new Date-start) + 'ms' ); - }); - }); - - })(); - - } - }, 0); -//*/ diff --git a/example/stress/jquery b/example/stress/jquery deleted file mode 160000 index cf702496e..000000000 --- a/example/stress/jquery +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cf702496ee28830f3488ed3f1c3940cfbb2dfa8f diff --git a/example/stress/repo.js b/example/stress/repo.js deleted file mode 100644 index d32ed765a..000000000 --- a/example/stress/repo.js +++ /dev/null @@ -1,50 +0,0 @@ -var git = require( 'nodegit' ).raw; - -//* Stress test basic repo - setInterval(function() { - for(var i=0; i<10000; i++) { - - (function() { - var start = new Date; - var repo = new git.Repo(); - - //console.log( 'Time taken: ' + (+new Date-start) + 'ms' ); - })(); - - } - }, 0); -//*/ - - -//* Stress test repo open - setInterval(function() { - for(var i=0; i<10000; i++) { - - (function() { - var start = new Date; - var repo = new git.Repo(); - repo.open( 'jquery/.git', function() { - - //console.log( 'Time taken: ' + (+new Date-start) + 'ms' ); - }); - })(); - - } - }, 0); -//*/ - -//* Init stress test - setInterval(function() { - for(var i=0; i<10000; i++) { - - (function() { - var start = new Date; - var repo = new git.Repo(); - repo.init( './test/'+ i +'.git', true, function() { - //console.log( 'Time taken: ' + (+new Date-start) + 'ms' ); - }); - })(); - - } - }, 0); -//*/ diff --git a/example/stress/revwalk.js b/example/stress/revwalk.js deleted file mode 100644 index c4e733fe0..000000000 --- a/example/stress/revwalk.js +++ /dev/null @@ -1,58 +0,0 @@ -//var git = require( '../../' ).raw; -var git = require( 'nodegit' ); - - -//* Stress test revision walking - //setInterval(function() { -// for(var i=0; i<10000; i++) { - - (function() { - - git.repo( 'jquery/.git', function() { - //console.log( 'Repo opened' ); - - this.branch( 'master', function() { - this.history().on( 'commit', function( i, commit ) { - console.log( commit.id.toString(40) ); - }); - }); - }); - - //var repo = new git.Repo(); - //repo.open( 'jquery/.git', function( err ) { - - // var commit = new git.Commit( repo ) - // , ref = new git.Ref( repo ); - - // ref.lookup( repo, '/refs/heads/master', function( err ) { - // if( err ) { throw new Error( err ); } - - // var oid = new git.Oid(); - // ref.oid( oid ); - - - //commit.lookup( repo, oid, function( err ) { - - // var revwalk = new git.RevWalk( repo ); - // revwalk.push( commit ); - - // function walk() { - // var _oid = new git.Oid(); - // revwalk.next( _oid, function( err ) { - // if( !err ) { - // walk(); - // } - // }); - // } - - // walk(); - - //}); - // }); - //}); - - })(); - -// } - //}, 0); -//*/ From 9cdafca5886739bad1337cdb88158cb676973f92 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 00:53:37 +1300 Subject: [PATCH 126/186] Updated raw-blob tests --- test/raw-blob.js | 62 +++++++++--------------------------------------- 1 file changed, 11 insertions(+), 51 deletions(-) diff --git a/test/raw-blob.js b/test/raw-blob.js index f7e70e276..583c5bb14 100644 --- a/test/raw-blob.js +++ b/test/raw-blob.js @@ -4,7 +4,6 @@ var git = require('../').raw, var testRepo = new git.Repo(); -// Helper functions var helper = { // Test if obj is a true function testFunction: function(test, obj, label) { @@ -25,16 +24,13 @@ var helper = { } }; -// Blob +/** + * Blob constructor + */ exports.constructor = function(test){ test.expect(3); - - // Test for function helper.testFunction(test.equals, git.Blob, 'Blob'); - - // Ensure we get an instance of Blob test.ok(new git.Blob() instanceof git.Blob, 'Invocation returns an instance of Blob'); - test.done(); }; @@ -65,70 +61,34 @@ exports.lookup = function(test) { }, 'Throw an exception if no callback Object'); testRepo.open(path.resolve('../.git'), function() { - - //testOid.mkstr('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5'); - - //testCommit.lookup(testRepo, testOid, function(err) { - // var tree = new git.Tree(testRepo) - // , entry = new git.TreeEntry() - // , blob = new git.Blob(testRepo); - - // if(!testCommit.tree(tree) && tree.entryCount() > 1) { - // tree.entryByIndex(entry, 1); - // entry.toObject(testRepo, blob); - - // //console.log(entry.name() + ':'); - // //console.log(blob.rawSize()); - // //console.dir(blob.rawContent()); - // } - //}); + // @todo actually lookup test.done(); - }); }; // Blob::RawContent exports.rawContent = function(test) { - var testOid = new git.Oid() - , testBlob = new git.Blob() - , testCommit = new git.Commit(); + var testOid = new git.Oid(), + testBlob = new git.Blob(), + testCommit = new git.Commit(); test.expect(2); // Test for function helper.testFunction(test.equals, testBlob.rawContent, 'Blob::RawContent'); - testRepo.open(path.resolve('../.git'), function() { - testOid.mkstr('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5'); - - testCommit.lookup(testRepo, testOid, function(err) { - var tree = new git.Tree(testRepo), - entry = new git.TreeEntry(), - blob = new git.Blob(testRepo); - - //if(!testCommit.tree(tree) && tree.entryCount() > 1) { - // tree.entryByIndex(entry, 1); - // entry.toObject(testRepo, blob); - - // //console.log(entry.name() + ':'); - // //console.log(blob.rawSize()); - // //console.dir(blob.rawContent()); - //} - }); - }); - test.done(); }; -// Blob::Close -exports.close = function(test) { +// Blob::Free +exports.free = function(test) { var testOid = new git.Oid(), testBlob = new git.Blob(); test.expect(2); // Test for function - helper.testFunction(test.equals, testBlob.close, 'Blob::Close'); + helper.testFunction(test.equals, testBlob.free, 'Blob::Free'); test.done(); }; @@ -141,7 +101,7 @@ exports.createFromFile = function(test) { test.expect(2); // Test for function - helper.testFunction(test.equals, testBlob.createFromFile, 'Blob::Close'); + helper.testFunction(test.equals, testBlob.createFromFile, 'Blob::CreateFromFile'); test.done(); }; From b54119a6e440b27351e8e8b9f44e42d8f1425706 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:06:43 +1300 Subject: [PATCH 127/186] Removed unused Oid functions --- src/oid.cc | 174 ++++++++++++++--------------------------------------- 1 file changed, 46 insertions(+), 128 deletions(-) diff --git a/src/oid.cc b/src/oid.cc index cf8d3a2a9..fc68b7dea 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -7,11 +7,15 @@ #include #include +#include #include "git2.h" #include "../include/oid.h" +#include "../include/functions/utilities.h" +#include "../include/functions/string.h" + using namespace v8; using namespace node; @@ -23,14 +27,8 @@ void GitOid::Initialize(Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("Oid")); - NODE_SET_PROTOTYPE_METHOD(tpl, "mkstr", Mkstr); - NODE_SET_PROTOTYPE_METHOD(tpl, "mkraw", Mkraw); - NODE_SET_PROTOTYPE_METHOD(tpl, "fmt", Fmt); - NODE_SET_PROTOTYPE_METHOD(tpl, "pathFmt", PathFmt); - NODE_SET_PROTOTYPE_METHOD(tpl, "allocFmt", AllocFmt); - NODE_SET_PROTOTYPE_METHOD(tpl, "toString", ToString); - NODE_SET_PROTOTYPE_METHOD(tpl, "cpy", Cpy); - NODE_SET_PROTOTYPE_METHOD(tpl, "cmp", Cmp); + NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha); + NODE_SET_PROTOTYPE_METHOD(tpl, "fromString", FromString); constructor_template = Persistent::New(tpl->GetFunction()); target->Set(String::NewSymbol("Oid"), constructor_template); @@ -39,43 +37,10 @@ void GitOid::Initialize(Handle target) { git_oid GitOid::GetValue() { return this->oid; } - void GitOid::SetValue(git_oid oid) { this->oid = oid; } -int GitOid::Mkstr(const char* id) { - return git_oid_fromstr(&this->oid, id); -} - -void GitOid::Mkraw(const unsigned char* raw) { - git_oid_fromraw(&this->oid, raw); -} - -void GitOid::Fmt(char* buffer) { - git_oid_fmt(buffer, &this->oid); -} - -void GitOid::PathFmt(char* str) { - git_oid_pathfmt(str, &this->oid); -} - -char* GitOid::AllocFmt() { - return git_oid_allocfmt(&this->oid); -} - -char* GitOid::ToString(char* buffer, size_t bufferSize) { - return git_oid_tostr(buffer, bufferSize, &this->oid); -} - -void GitOid::Cpy(git_oid* out) { - git_oid_cpy(out, &this->oid); -} - -int GitOid::Cmp(const git_oid* a, const git_oid* b) { - return git_oid_cmp(a, b); -} - Handle GitOid::New(const Arguments& args) { HandleScope scope; @@ -85,117 +50,70 @@ Handle GitOid::New(const Arguments& args) { return scope.Close(args.This()); } -Handle GitOid::Mkstr(const Arguments& args) { +Handle GitOid::Sha(const Arguments& args) { HandleScope scope; GitOid* oid = ObjectWrap::Unwrap(args.This()); - if(args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("Object id is required and must be a hex formatted String."))); - } - - String::Utf8Value id(args[0]); + char sha[GIT_OID_HEXSZ + 1]; + sha[GIT_OID_HEXSZ] = '\0'; + git_oid rawOid = oid->GetValue(); + git_oid_fmt(sha, const_cast(&rawOid)); - return scope.Close(Integer::New(oid->Mkstr(*id))); + return scope.Close(String::New(sha)); } -Handle GitOid::Mkraw(const Arguments& args) { +Handle GitOid::FromString(const Arguments& args) { HandleScope scope; - GitOid* oid = ObjectWrap::Unwrap(args.This()); - if(args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("Raw object id is required."))); + return ThrowException(Exception::Error(String::New("String is required and must be a String."))); } - String::Utf8Value raw(args[0]); - oid->Mkraw((const unsigned char*)*raw); - - return scope.Close( args.This() ); -} - -Handle GitOid::Fmt(const Arguments& args) { - HandleScope scope; - - GitOid *oid = ObjectWrap::Unwrap(args.This()); - - char buffer[40]; - oid->Fmt(buffer); - - return scope.Close(String::New(buffer)); -} - -Handle GitOid::PathFmt(const Arguments& args) { - HandleScope scope; - - GitOid *oid = ObjectWrap::Unwrap(args.This()); - - char buffer[41]; - oid->PathFmt(buffer); - - return scope.Close( String::New(buffer) ); -} + if(args.Length() == 1 || !args[1]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } -Handle GitOid::AllocFmt(const Arguments& args) { - HandleScope scope; + FromStringBaton* baton = new FromStringBaton; + baton->request.data = baton; + baton->error = NULL; + baton->oid = ObjectWrap::Unwrap(args.This()); + baton->rawOid = baton->oid->GetValue(); + baton->fromString = stringArgToString(args[0]->ToString()); + baton->callback = Persistent::New(Local::Cast(args[1])); - GitOid *oid = ObjectWrap::Unwrap(args.This()); + uv_queue_work(uv_default_loop(), &baton->request, FromStringWork, (uv_after_work_cb)FromStringAfterWork); - return scope.Close( String::New(oid->AllocFmt()) ); + return Undefined(); } +void GitOid::FromStringWork(uv_work_t* req) { + FromStringBaton *baton = static_cast(req->data); -Handle GitOid::ToString(const Arguments& args) { - HandleScope scope; - - GitOid *oid = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Length argument is required and must be a Number."))); + int returnCode = git_oid_fromstr(&baton->rawOid, baton->fromString.c_str()); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); } - - char buffer[Int32::Cast(*args[0])->Value()+1]; - oid->ToString(buffer, sizeof(buffer)); - - return scope.Close( String::New(buffer) ); } - -Handle GitOid::Cpy(const Arguments& args) { +void GitOid::FromStringAfterWork(uv_work_t* req) { HandleScope scope; + FromStringBaton *baton = static_cast(req->data); - GitOid *oid = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("GitOid argument is required and must be a Object."))); - } - - GitOid *clone = ObjectWrap::Unwrap(args[0]->ToObject()); - - git_oid *out = NULL; - oid->Cpy(out); - clone->SetValue(*out); - - return scope.Close( Undefined() ); -} - -Handle GitOid::Cmp(const Arguments& args) { - HandleScope scope; + if (success(baton->error, baton->callback)) { - // GitOid *oid = ObjectWrap::Unwrap(args.This()); + baton->oid->SetValue(baton->rawOid); - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("GitOid argument is required and must be a Object."))); - } + Handle argv[2] = { + Local::New(Null()), + baton->oid->handle_ + }; - if(args.Length() == 1 || !args[1]->IsObject()) { - return ThrowException(Exception::Error(String::New("GitOid argument is required and must be a Object."))); + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } } - - // GitOid* a = ObjectWrap::Unwrap(args[0]->ToObject()); - // GitOid* b = ObjectWrap::Unwrap(args[1]->ToObject()); - - //int cmp = oid->Cmp(&a->GetValue(), &b->GetValue()); - int cmp = 0; - - return scope.Close( Integer::New(cmp) ); + delete req; } + Persistent GitOid::constructor_template; From f4a90f5e895e686413829363d013a0ffe90917a3 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:07:08 +1300 Subject: [PATCH 128/186] Updated Oid js --- lib/oid.js | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/oid.js b/lib/oid.js index 8cbdfb55c..63400a94a 100644 --- a/lib/oid.js +++ b/lib/oid.js @@ -1,7 +1,10 @@ -var git = require( '../' ); +var git = require('../'); /** - * @param {git.raw.Oid|null} rawOid + * Convenience Oid constructor. + * + * @constructor + * @param {git.raw.Oid} [rawOid = new git.rawOid] Raw Oid object. */ var Oid = function(rawOid) { if(rawOid instanceof git.raw.Oid) { @@ -10,10 +13,45 @@ var Oid = function(rawOid) { }; /** - * @return {git.raw.Oid} + * @return {git.raw.Oid} The wrapped raw Oid object. */ Oid.prototype.getRawOid = function() { return this.rawOid; }; +/** + * Create Oid object from string. + * + * @param {String} sha + * @param {Oid~fromStringCallback} callback + */ +Oid.prototype.fromString = function(sha, callback) { + /** + * @callback Oid~fromStringCallback Callback executed after raw Oid is created. + * @param {GitError|null} error An Error or null if successful. + * @param {Oid|null} oid The new Oid object. + */ + var self = this; + self.rawOid.fromString(sha, function(error, rawOid) { + if (success(error, rawOid)) { + self.rawOid = rawOid; + callback(null, self); + } + }); +}; + +/** + * Convert the raw Oid to a SHA + * + * @param {Oid~shaCallback} callback + */ +Oid.prototype.sha = function(callback) { + /** + * @callback Oid~shaCallback Callback executed after SHA is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} sha The SHA. + */ + callback(null, this.rawOid.sha()); +}; + exports.oid = Oid; From e59b4b8e80222d394b34b32bb098652539a48179 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:07:18 +1300 Subject: [PATCH 129/186] Removed Oid unused functions --- include/oid.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/include/oid.h b/include/oid.h index ab14b306d..4f61e8665 100755 --- a/include/oid.h +++ b/include/oid.h @@ -10,6 +10,7 @@ #include #include +#include #include "git2.h" @@ -22,35 +23,34 @@ class GitOid : public ObjectWrap { static Persistent constructor_template; static void Initialize (Handle target); - Handle WrapObj(Local obj); git_oid GetValue(); void SetValue(git_oid oid); - int Mkstr(const char* str); - void Mkraw(const unsigned char* raw); - void Fmt(char* buffer); - void PathFmt(char *str); - char* AllocFmt(); - char* ToString(char* buffer, size_t bufferSize); - void Cpy(git_oid* out); - int Cmp(const git_oid* a, const git_oid* b); - + protected: GitOid() {} ~GitOid() {} - protected: static Handle New(const Arguments& args); - static Handle Mkstr(const Arguments& args); - static Handle Mkraw(const Arguments& args); - static Handle Fmt(const Arguments& args); - static Handle PathFmt(const Arguments& args); - static Handle AllocFmt(const Arguments& args); - static Handle ToString(const Arguments& args); - static Handle Cpy(const Arguments& args); - static Handle Cmp(const Arguments& args); + + static Handle Sha(const Arguments& args); + + static Handle FromString(const Arguments& args); + static void FromStringWork(uv_work_t* req); + static void FromStringAfterWork(uv_work_t* req); private: git_oid oid; + + struct FromStringBaton { + uv_work_t request; + const git_error* error; + + std::string fromString; + GitOid* oid; + git_oid rawOid; + + Persistent callback; + }; }; #endif From 25f49d34ad0832ad8f7af13f15a637776acacf10 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:07:25 +1300 Subject: [PATCH 130/186] Updated raw oid tests --- test/raw-oid.js | 62 ++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/test/raw-oid.js b/test/raw-oid.js index 20219a6f8..126a6fd31 100644 --- a/test/raw-oid.js +++ b/test/raw-oid.js @@ -35,64 +35,48 @@ exports.constructor = function(test){ test.done(); }; -// Oid::Mkstr -exports.mkstr = function(test) { - var testOid = new git.Oid(); - +// Oid::FromString +exports.fromString = function(test) { test.expect(6); + var testOid = new git.Oid(); + // Test for function - helper.testFunction(test.equals, testOid.mkstr, 'Oid::Mkstr'); + helper.testFunction(test.equals, testOid.fromString, 'Oid::FromString'); // Test path argument existence helper.testException(test.ok, function() { - testOid.mkstr(); + testOid.fromString(); }, 'Throw an exception if no hex String'); // Test that both arguments result correctly helper.testException(test.ifError, function() { - testOid.mkstr("somestr"); + testOid.fromString("somestr", function() {}); }, 'No exception is thrown with proper arguments'); // Test invalid hex id string - test.equals(git.Error.returnCodes.GIT_ERROR, testOid.mkstr('1392DLFJIOS'), 'Invalid hex id String'); - - // Test valid hex id string - test.equals(git.Error.returnCodes.GIT_OK, testOid.mkstr('1810DFF58D8A660512D4832E740F692884338CCD'), 'Valid hex id String'); - - test.done(); + testOid.fromString('1392DLFJIOS', function(error, oid) { + test.notEqual(null, error, 'Invalid hex id String'); + testOid.fromString('1810DFF58D8A660512D4832E740F692884338CCD', function(error, oid) { + // Test valid hex id string + test.equal(null, error, 'Valid hex id String'); + test.done(); + }); + }); }; -// Oid::Fmt -exports.fmt = function(test) { - var testOid = new git.Oid(); - +// Oid::Sha +exports.sha = function(test) { test.expect(3); - - // Test for function - helper.testFunction(test.equals, testOid.fmt, 'Oid::Fmt'); - - // Test valid hex id string - testOid.mkstr('1810DFF58D8A660512D4832E740F692884338CCD'); - - // Slight hackery to get this to work... should investigate oid fmt - test.equals('1810DFF58D8A660512D4832E740F692884338CCD', testOid.fmt().substring(0, 40).toUpperCase(), 'Valid hex id String'); - - test.done(); -}; - -// Oid::Fmt -exports.toString = function(test) { var testOid = new git.Oid(); - test.expect(3); - // Test for function - helper.testFunction(test.equals, testOid.toString, 'Oid::ToString'); + helper.testFunction(test.equals, testOid.sha, 'Oid::Sha'); // Test valid hex id string - testOid.mkstr('1810DFF58D8A660512D4832E740F692884338CCD'); - test.equals('1810DFF58D8A660512D4832E740F692884338CCD', testOid.toString(40).toUpperCase(), 'Valid hex id String'); - - test.done(); + var sha = '1810DFF58D8A660512D4832E740F692884338CCD'; + testOid.fromString(sha, function(error, rawOid) { + test.equals(sha, testOid.sha().toUpperCase(), 'Valid hex id String'); + test.done(); + }); }; From b815a06e2a0fc9819cb6c84a55973ceac524540b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:07:33 +1300 Subject: [PATCH 131/186] Added convenience-oid tests --- test/convenience-oid.js | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 test/convenience-oid.js diff --git a/test/convenience-oid.js b/test/convenience-oid.js new file mode 100644 index 000000000..465c81f2a --- /dev/null +++ b/test/convenience-oid.js @@ -0,0 +1,54 @@ +var git = require('../'); + +// Helper functions +var helper = { + // Test if obj is a true function + testFunction: function(test, obj, label) { + // The object reports itself as a function + test(typeof obj, 'function', label + ' reports as a function.'); + // This ensures the repo is actually a derivative of the Function [[Class]] + test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.'); + }, + // Test code and handle exception thrown + testException: function(test, fun, label) { + try { + fun(); + test(false, label); + } + catch (ex) { + test(true, label); + } + } +}; + +/** + * Test that the commit object is present. + */ +exports.method = function(test){ + test.expect(2); + helper.testFunction(test.equals, git.commit, 'Oid'); + test.done(); +}; + +var knownSha = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; + +exports.fromString = function(test) { + test.expect(1); + git.repo('../.git', function(error, repository) { + (new git.oid()).fromString(knownSha, function(error, oid) { + test.equal(error, null, 'Should not error'); + test.done(); + }); + }); +}; + +exports.fromString = function(test) { + test.expect(2); + (new git.oid()).fromString(knownSha, function(error, oid) { + oid.sha(function(error, sha) { + test.equal(error, null, 'Should not error'); + test.equal(sha, knownSha, 'SHA should match known value'); + test.done(); + }); + }); +}; From 3467803b6d470a6a65127fd7868177abe5f00dfb Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:11:48 +1300 Subject: [PATCH 132/186] Removed sha method from C++ commit, commit js uses commit's Oid sha method --- include/commit.h | 15 --------------- lib/commit.js | 12 +++++++++--- src/commit.cc | 43 ++----------------------------------------- 3 files changed, 11 insertions(+), 59 deletions(-) diff --git a/include/commit.h b/include/commit.h index 37b6dd8be..961d2ed82 100755 --- a/include/commit.h +++ b/include/commit.h @@ -16,8 +16,6 @@ #include "oid.h" #include "tree.h" -#include "../include/functions/string.h" - using namespace node; using namespace v8; @@ -55,10 +53,6 @@ class GitCommit : public ObjectWrap { static Handle Oid(const Arguments& args); - static Handle Sha(const Arguments& args); - static void ShaWork(uv_work_t* req); - static void ShaAfterWork(uv_work_t* req); - static Handle Message(const Arguments& args); static void MessageWork(uv_work_t* req); static void MessageAfterWork(uv_work_t* req); @@ -103,15 +97,6 @@ class GitCommit : public ObjectWrap { Persistent callback; }; - struct ShaBaton { - uv_work_t request; - - git_oid* rawOid; - char sha[GIT_OID_HEXSZ + 1]; - - Persistent callback; - }; - struct MessageBaton { uv_work_t request; diff --git a/lib/commit.js b/lib/commit.js index e80c46689..bb2c6b08a 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -74,10 +74,16 @@ Commit.prototype.sha = function(callback) { * @param {GitError|null} error An Error or null if successful. * @param {String|null} sha Retrieved SHA. */ - this.rawCommit.sha(function(error, sha) { - if (success(error, callback)) { - callback(null, sha); + this.oid(function(error, oid) { + if (!success(error, callback)) { + return; } + oid.sha(function(error, sha) { + if (!success(error, callback)) { + return; + } + callback(null, sha); + }); }); }; diff --git a/src/commit.cc b/src/commit.cc index c232d2f5c..d4eecd555 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -5,9 +5,9 @@ * Dual licensed under the MIT and GPL licenses. */ -#include #include #include +#include #include "git2.h" #include "cvv8/v8-convert.hpp" @@ -21,6 +21,7 @@ #include "../include/error.h" #include "../include/functions/utilities.h" +#include "../include/functions/string.h" using namespace v8; using namespace cvv8; @@ -36,7 +37,6 @@ void GitCommit::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); - NODE_SET_PROTOTYPE_METHOD(tpl, "sha", Sha); NODE_SET_PROTOTYPE_METHOD(tpl, "message", Message); NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time); NODE_SET_PROTOTYPE_METHOD(tpl, "offset", Offset); @@ -162,45 +162,6 @@ Handle GitCommit::Oid(const Arguments& args) { return scope.Close(oid); } -Handle GitCommit::Sha(const Arguments& args) { - HandleScope scope; - - if(args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); - } - - ShaBaton* baton = new ShaBaton; - baton->request.data = baton; - baton->rawOid = ObjectWrap::Unwrap(args.This())->oid; - baton->callback = Persistent::New(Local::Cast(args[0])); - - uv_queue_work(uv_default_loop(), &baton->request, ShaWork, (uv_after_work_cb)ShaAfterWork); - - return Undefined(); -} -void GitCommit::ShaWork(uv_work_t* req) { - ShaBaton *baton = static_cast(req->data); - - baton->sha[GIT_OID_HEXSZ] = '\0'; - git_oid_fmt(baton->sha, baton->rawOid); -} -void GitCommit::ShaAfterWork(uv_work_t* req) { - HandleScope scope; - ShaBaton *baton = static_cast(req->data); - - Handle argv[2] = { - Local::New(Null()), - String::New(baton->sha) - }; - - TryCatch try_catch; - baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); - if (try_catch.HasCaught()) { - node::FatalException(try_catch); - } - delete req; -} - Handle GitCommit::Message(const Arguments& args) { HandleScope scope; From 578c7ad5772d0831ad47bdd8462aefcc937f7bdd Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:12:08 +1300 Subject: [PATCH 133/186] Added tree entry Oid methods --- src/tree_entry.cc | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/tree_entry.cc b/src/tree_entry.cc index c8f072237..bf2b47585 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -32,7 +32,7 @@ void GitTreeEntry::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "name", Name); NODE_SET_PROTOTYPE_METHOD(tpl, "root", Root); NODE_SET_PROTOTYPE_METHOD(tpl, "fileMode", FileMode); - NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id); + NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "toBlob", ToBlob); constructor_template = Persistent::New(tpl->GetFunction()); @@ -147,23 +147,46 @@ void GitTreeEntry::FileModeAfterWork(uv_work_t* req) { } -Handle GitTreeEntry::Id(const Arguments& args) { - // HandleScope scope; +Handle GitTreeEntry::Oid(const Arguments& args) { + HandleScope scope; - // GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } - // Handle oid = GitOid::constructor_template->NewInstance(); - // GitOid* oidInstance = ObjectWrap::Unwrap(oid); - // oidInstance->SetValue(*const_cast(git_tree_entry_id(entry->entry))); + OidBaton* baton = new OidBaton; + baton->request.data = baton; + baton->rawEntry = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, OidWork, (uv_after_work_cb)OidAfterWork); - // return oid; return Undefined(); } -void GitTreeEntry::IdWork(uv_work_t* req) { +void GitTreeEntry::OidWork(uv_work_t* req) { + OidBaton *baton = static_cast(req->data); + baton->rawOid = git_tree_entry_id(const_cast(baton->rawEntry)); } -void GitTreeEntry::IdAfterWork(uv_work_t* req) { +void GitTreeEntry::OidAfterWork(uv_work_t* req) { + HandleScope scope; + OidBaton *baton = static_cast(req->data); + 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); + } + delete req; } Handle GitTreeEntry::ToBlob(const Arguments& args) { From 3c256a2741397a882b0bb197f707292823a21c96 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:12:18 +1300 Subject: [PATCH 134/186] Updated blob's documentation --- lib/blob.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/blob.js b/lib/blob.js index b1e265532..1467ee65e 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -89,7 +89,7 @@ Blob.prototype.createFromFile = function(path, callback) { /** * @callback Blob~createFromFileCallback Callback executed after blob is created. * @param {GitError|null} error An Error or null if successful. - * @param {Blob|null} content The new blob or null. + * @param {Blob|null} blob The new blob or null. */ var self = this; self.rawBlob.createFromFile(path, self.rawRepo, function blobCreateFromFileCallback(error, rawBlob) { From 265b5ef7c5587c06b74d998ca0de61dad3cde6ec Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:12:39 +1300 Subject: [PATCH 135/186] Updated tree entry documentation, implemented oid function --- lib/tree_entry.js | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 3cafe7825..f3eb06caa 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -4,6 +4,13 @@ var git = require('../'), var DIRECTORY = 33188; var FILE = 16384; +/** + * Convenience tree entry constructor. + * + * @constructor + * @param {git.raw.Repo} rawRepo Raw repository object. + * @param {git.raw.TreeEntry} rawTreeEntry Raw tree entry object. + */ var TreeEntry = function(rawRepo, rawTreeEntry) { if(!(rawRepo instanceof git.raw.Repo)) { throw git.error('First parameter for Tree Entry must be a raw repo', 0); @@ -20,9 +27,14 @@ var TreeEntry = function(rawRepo, rawTreeEntry) { /** * Retrieve the Oid for this TreeEntry. * - * @param {Function} callback + * @param {TreeEntry~oidCallback} callback */ TreeEntry.prototype.oid = function(callback) { + /** + * @callback TreeEntry~oidCallback Callback executed after the Oid is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {TreeEntry|null} oid The Oid object or null. + */ this.rawEntry.oid(function(error, rawOid) { if (success(error, callback)) { callback(null, git.oid(rawOid)); @@ -33,22 +45,37 @@ TreeEntry.prototype.oid = function(callback) { /** * Retrieve the SHA for this TreeEntry. * - * @param {Function} callback + * @param {TreeEntry~shaCallback} callback */ TreeEntry.prototype.sha = function(callback) { - this.rawEntry.sha(function(error, sha) { - if (success(error, callback)) { - callback(null, sha); + /** + * @callback TreeEntry~shaCallback Callback executed after the SHA is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} sha The SHA object or null. + */ + this.rawEntry.oid(function(error, oid) { + if (!success(error, callback)) { + return; } + (new git.oid(oid)).sha(function(error, sha) { + if (success(error, callback)) { + callback(null, sha); + } + }); }); }; /** * Determine whether this TreeEntry is a file. * - * @param {Function} callback + * @param {TreeEntry~isFileCallback} callback */ TreeEntry.prototype.isFile = function(callback) { + /** + * @callback TreeEntry~isFileCallback Callback executed after type is determined. + * @param {GitError|null} error An Error or null if successful. + * @param {Boolean|null} content True if the entry is a file, false otherwise. + */ var self = this; if (typeof self._cache.fileMode !== 'undefined') { callback(null, self._cache.fileMode === FILE); @@ -65,7 +92,7 @@ TreeEntry.prototype.isFile = function(callback) { /** * Determine whether this Tree Entry is a directory. * - * @param {Function} callback + * @param {TreeEntry~isDirectoryCallback} callback */ TreeEntry.prototype.isDirectory = function(callback) { var self = this; From daa9f6517ec30d02d8e15c4b75f5abdb3ff9ecb6 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:12:46 +1300 Subject: [PATCH 136/186] Changed Id to Oid --- include/tree_entry.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/tree_entry.h b/include/tree_entry.h index 5672df2da..563eea0f3 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -49,9 +49,9 @@ class GitTreeEntry : ObjectWrap { static void FileModeWork(uv_work_t* req); static void FileModeAfterWork(uv_work_t* req); - static Handle Id(const Arguments& args); - static void IdWork(uv_work_t* req); - static void IdAfterWork(uv_work_t* req); + static Handle Oid(const Arguments& args); + static void OidWork(uv_work_t* req); + static void OidAfterWork(uv_work_t* req); static Handle ToBlob(const Arguments& args); static void ToBlobWork(uv_work_t *req); @@ -79,11 +79,11 @@ class GitTreeEntry : ObjectWrap { Persistent callback; }; - struct IdBaton { + struct OidBaton { uv_work_t request; git_tree_entry* rawEntry; - git_oid* rawOid; + const git_oid* rawOid; Persistent callback; }; From f0b6bc1e21d2b62ac5e9f9ff0183b041d3b08153 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:12:55 +1300 Subject: [PATCH 137/186] Added convenience-entry tests --- test/convenience-entry.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/convenience-entry.js diff --git a/test/convenience-entry.js b/test/convenience-entry.js new file mode 100644 index 000000000..a4a5b80dd --- /dev/null +++ b/test/convenience-entry.js @@ -0,0 +1,23 @@ +var git = require('../'); + +var sha = '5716e9757886eaf38d51c86b192258c960d9cfea'; + +var getEntry = function(callback) { + git.repo('../.git', function(error, repo) { + repo.commit(sha, function(error, commit) { + commit.file('README.md', function(error, entry) { + callback(error, entry); + }); + }); + }); +}; + +exports.sha = function(test) { + test.expect(1); + getEntry(function(error, entry) { + entry.sha(function(error, sha) { + test.equal(sha, '6cb45ba5d32532bf0d1310dc31ca4f20f59964bc', 'Entry SHA should match expected value'); + test.done(); + }); + }); +}; From ea803feb83f48c188ce8591e9cad45e14e0953d5 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:22:07 +1300 Subject: [PATCH 138/186] Updated raw commit tests --- test/raw-commit.js | 60 +++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/test/raw-commit.js b/test/raw-commit.js index 190458f3b..058ed52eb 100644 --- a/test/raw-commit.js +++ b/test/raw-commit.js @@ -1,6 +1,4 @@ -var git = require('../').raw, - rimraf = require('rimraf'), - path = require('path'); +var git = require('../').raw; var testRepo = new git.Repo(); @@ -33,7 +31,7 @@ exports.constructor = function(test){ // Test for function helper.testFunction(test.equals, git.Commit, 'Commit'); - testRepo.open(path.resolve('../.git'), function(err) { + testRepo.open('../.git', function(err) { // Ensure we get an instance of Commit test.ok(new git.Commit(testRepo) instanceof git.Commit, 'Invocation returns an instance of Commit'); @@ -45,47 +43,43 @@ exports.constructor = function(test){ * Commit::Lookup */ exports.lookup = function(test) { + test.expect(7); + var testOid = new git.Oid(), testCommit = new git.Commit(); - testOid.mkstr('cb09e99e91d41705197e0fb60823fdc7df776691'); - - test.expect(8); - // Test for function helper.testFunction(test.equals, testCommit.lookup, 'Commit::Lookup'); - // Test repo argument existence - helper.testException(test.ok, function() { - testCommit.lookup(); - }, 'Throw an exception if no repo'); + testOid.fromString('cb09e99e91d41705197e0fb60823fdc7df776691', function(error, testOid) { - // Test oid argument existence - helper.testException(test.ok, function() { - testCommit.lookup(testRepo); - }, 'Throw an exception if no oid'); + // Test repo argument existence + helper.testException(test.ok, function() { + testCommit.lookup(); + }, 'Throw an exception if no repo'); - // Test callback argument existence - helper.testException(test.ok, function() { - testCommit.lookup(testOid); - }, 'Throw an exception if no callback'); + // Test oid argument existence + helper.testException(test.ok, function() { + testCommit.lookup(testRepo); + }, 'Throw an exception if no oid'); - // Test that all arguments result correctly - helper.testException(test.ifError, function() { - testCommit.lookup(testRepo, testOid, function() {}); - }, 'No exception is thrown with proper arguments'); + // Test callback argument existence + helper.testException(test.ok, function() { + testCommit.lookup(testOid); + }, 'Throw an exception if no callback'); - testRepo.open(path.resolve('../.git'), function() { - // Test invalid commit - testOid.mkstr('100644'); - testCommit.lookup(testRepo, testOid, function(err) { - test.notEqual(0, err, 'Not a valid commit'); + // Test that all arguments result correctly + helper.testException(test.ifError, function() { + testCommit.lookup(testRepo, testOid, function() {}); + }, 'No exception is thrown with proper arguments'); + testRepo.open('../.git', function() { // Test valid commit - testOid.mkstr('cb76e3c030ab29db332aff3b297dc39451a84762'); - testCommit.lookup(testRepo, testOid, function(err) { - test.equals(null, err, 'Valid commit'); - test.done(); + testOid.fromString('cb76e3c030ab29db332aff3b297dc39451a84762', function(error, testOid) { + testCommit.lookup(testRepo, testOid, function(err) { + test.equal(null, err, 'Valid commit'); + test.done(); + }); }); }); }); From 31746e223590c8d6d321ffad7a5c477040e88c47 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:58:36 +1300 Subject: [PATCH 139/186] Added git_filemode_t enum to raw tree entry object --- src/tree_entry.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/tree_entry.cc b/src/tree_entry.cc index bf2b47585..a9d6957ab 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -8,6 +8,8 @@ #include #include +#include "cvv8/v8-convert.hpp" + #include "git2.h" #include "../include/repo.h" @@ -22,6 +24,12 @@ using namespace v8; using namespace node; +using namespace cvv8; + +namespace cvv8 { + template <> + struct NativeToJS : NativeToJS {}; +} void GitTreeEntry::Initialize(Handle target) { Local tpl = FunctionTemplate::New(New); @@ -35,7 +43,18 @@ void GitTreeEntry::Initialize(Handle target) { NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid); NODE_SET_PROTOTYPE_METHOD(tpl, "toBlob", ToBlob); + // Add libgit2 file modes to entry object + Local libgit2FileModes = Object::New(); + + libgit2FileModes->Set(String::NewSymbol("GIT_FILEMODE_NEW"), CastToJS(GIT_FILEMODE_NEW), ReadOnly); + libgit2FileModes->Set(String::NewSymbol("GIT_FILEMODE_TREE"), CastToJS(GIT_FILEMODE_TREE), ReadOnly); + libgit2FileModes->Set(String::NewSymbol("GIT_FILEMODE_BLOB"), CastToJS(GIT_FILEMODE_BLOB), ReadOnly); + libgit2FileModes->Set(String::NewSymbol("GIT_FILEMODE_BLOB_EXECUTABLE"), CastToJS(GIT_FILEMODE_BLOB_EXECUTABLE), ReadOnly); + libgit2FileModes->Set(String::NewSymbol("GIT_FILEMODE_LINK"), CastToJS(GIT_FILEMODE_LINK), ReadOnly); + libgit2FileModes->Set(String::NewSymbol("GIT_FILEMODE_COMMIT"), CastToJS(GIT_FILEMODE_COMMIT), ReadOnly); + constructor_template = Persistent::New(tpl->GetFunction()); + constructor_template->Set(String::NewSymbol("fileModes"), libgit2FileModes, ReadOnly); target->Set(String::NewSymbol("TreeEntry"), constructor_template); } @@ -86,12 +105,6 @@ Handle GitTreeEntry::Root(const Arguments& args) { } Handle GitTreeEntry::Name(const Arguments& args) { - // HandleScope scope; - - // GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); - - // return scope.Close(String::New(git_tree_entry_name(entry->entry))); - // return Undefined(); HandleScope scope; if(args.Length() == 0 || !args[0]->IsFunction()) { From eaeec38b9fcb105cf9f527b6dd5fc94e1de9998b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:58:50 +1300 Subject: [PATCH 140/186] Added tree entry filemode methods' body --- include/tree_entry.h | 2 +- src/tree_entry.cc | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/tree_entry.h b/include/tree_entry.h index 563eea0f3..4b9f6629c 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -74,7 +74,7 @@ class GitTreeEntry : ObjectWrap { uv_work_t request; git_tree_entry* rawEntry; - int fileMode; + git_filemode_t fileMode; Persistent callback; }; diff --git a/src/tree_entry.cc b/src/tree_entry.cc index a9d6957ab..7d0220a14 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -145,19 +145,41 @@ void GitTreeEntry::NameAfterWork(uv_work_t* req) { } Handle GitTreeEntry::FileMode(const Arguments& args) { - // HandleScope scope; + HandleScope scope; - // GitTreeEntry *entry = ObjectWrap::Unwrap(args.This()); + if(args.Length() == 0 || !args[0]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + FileModeBaton *baton = new FileModeBaton; + baton->request.data = baton; + baton->rawEntry = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[0])); + + uv_queue_work(uv_default_loop(), &baton->request, FileModeWork, (uv_after_work_cb)FileModeAfterWork); - // return scope.Close(Number::New(git_tree_entry_filemode(entry->entry))); return Undefined(); } void GitTreeEntry::FileModeWork(uv_work_t* req) { + FileModeBaton *baton = static_cast(req->data); - + baton->fileMode = git_tree_entry_filemode(baton->rawEntry); } void GitTreeEntry::FileModeAfterWork(uv_work_t* req) { + HandleScope scope; + FileModeBaton *baton = static_cast(req->data); + Handle argv[2] = { + Local::New(Null()), + Integer::New(baton->fileMode) + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + delete req; } Handle GitTreeEntry::Oid(const Arguments& args) { From 42dc736bba715c197e6399f04a2bf55ad6e7118b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 22:59:20 +1300 Subject: [PATCH 141/186] Added git_filemode_t to tree entry convenience class --- lib/tree_entry.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index f3eb06caa..f39e6ea7f 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -1,9 +1,6 @@ var git = require('../'), success = require('./utilities').success; -var DIRECTORY = 33188; -var FILE = 16384; - /** * Convenience tree entry constructor. * @@ -22,6 +19,22 @@ var TreeEntry = function(rawRepo, rawTreeEntry) { this.rawRepo = rawRepo; this.rawEntry = rawTreeEntry; + this._cache = {}; +}; + +/** + * Refer to vendor/libgit2/include/git2/types.h for filemode definitions. + * + * @readonly + * @enum {Integer} + */ +TreeEntry.prototype.fileModes = { + /** 0000000 */ GIT_FILEMODE_NEW: git.raw.TreeEntry.GIT_FILEMODE_NEW, + /** 0040000 */ GIT_FILEMODE_TREE: git.raw.TreeEntry.GIT_FILEMODE_TREE, + /** 0100644 */ GIT_FILEMODE_BLOB: git.raw.TreeEntry.GIT_FILEMODE_BLOB, + /** 0100755 */ GIT_FILEMODE_BLOB_EXECUTABLE: git.raw.TreeEntry.GIT_FILEMODE_BLOB_EXECUTABLE, + /** 0120000 */ GIT_FILEMODE_LINK: git.raw.TreeEntry.GIT_FILEMODE_LINK, + /** 0160000 */ GIT_FILEMODE_COMMIT: git.raw.TreeEntry.GIT_FILEMODE_COMMIT }; /** @@ -78,13 +91,13 @@ TreeEntry.prototype.isFile = function(callback) { */ var self = this; if (typeof self._cache.fileMode !== 'undefined') { - callback(null, self._cache.fileMode === FILE); + callback(null, self._cache.fileMode === self.GIT_FILEMODE_BLOB); return; } self.rawEntry.fileMode(function(error, fileMode) { if (success(error, callback)) { self._cache.fileMode = fileMode; - callback(null, self._cache.fileMode === FILE); + callback(null, self._cache.fileMode === self.GIT_FILEMODE_BLOB); } }); }; @@ -97,13 +110,13 @@ TreeEntry.prototype.isFile = function(callback) { TreeEntry.prototype.isDirectory = function(callback) { var self = this; if (typeof self._cache.fileMode !== 'undefined') { - callback(null, self._cache.fileMode === DIRECTORY); + callback(null, self._cache.fileMode === self.GIT_FILEMODE_TREE); return; } self.rawEntry.fileMode(function(error, fileMode) { if (success(error, callback)) { self._cache.fileMode = fileMode; - callback(null, self._cache.fileMode === DIRECTORY); + callback(null, self._cache.fileMode === self.GIT_FILEMODE_TREE); } }); }; From 2d7d237c4ecc9c5c4b124d63e0462ce1dc61ab70 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:40:53 +1300 Subject: [PATCH 142/186] Added blobsOnly flag to walk, if true only blobs & blob executables are returned during a walk --- include/tree.h | 2 ++ lib/tree.js | 35 ++++++++++++++++++----------------- src/tree.cc | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 26 deletions(-) diff --git a/include/tree.h b/include/tree.h index f40518909..9ea01a1ca 100755 --- a/include/tree.h +++ b/include/tree.h @@ -72,6 +72,8 @@ class GitTree : public ObjectWrap { std::vector rawTreeEntries; git_tree* rawTree; + bool blobsOnly; + Persistent entryCallback; Persistent endCallback; }; diff --git a/lib/tree.js b/lib/tree.js index 0a037ba7c..dc825be56 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -48,33 +48,34 @@ Tree.prototype.entry = function(path, callback) { * @fires Tree#entry * @fires Tree#end * + * @param {Boolean} [blobsOnly = true] True to emit only blob & blob executable entries. + * * @return {EventEmitter} */ -Tree.prototype.walk = function() { +Tree.prototype.walk = function(blobsOnly) { + blobsOnly = typeof blobsOnly === 'undefined' ? true : blobsOnly; + var self = this, event = new events.EventEmitter(), entries = []; - self.rawTree.walk(function treeWalkEntries(error, rawEntries) { + var total = 0; + + self.rawTree.walk(blobsOnly, function treeWalkEntries(error, rawEntries) { rawEntries.forEach(function treeWalkEntryEmitter(rawEntry) { var entry = new git.entry(self.rawRepo, rawEntry); entries.push(entry); - if (!error) { - /** - * Entry event. - * - * @event Tree#entry - * - * @param {GitError|null} error An error object if there was an issue, null otherwise. - * @param {Entry} entry The tree entry. - */ - event.emit('entry', null, entry); - } + /** + * Entry event. + * + * @event Tree#entry + * + * @param {GitError|null} error An error object if there was an issue, null otherwise. + * @param {Entry} entry The tree entry. + */ + event.emit('entry', null, entry); }); }, function treeWalkEnd(error) { - if (error) { - event.emit('end', git.error(error), entries); - } /** * End event. * @@ -83,7 +84,7 @@ Tree.prototype.walk = function() { * @param {GitError|null} error An error object if there was an issue, null otherwise. * @param {Entry[]} entries The tree entries. */ - event.emit('end', null, entries); + event.emit('end', error ? git.error(error) : null, entries); }); return event; diff --git a/src/tree.cc b/src/tree.cc index 3bd6a3312..054ce250f 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -66,11 +66,15 @@ Handle GitTree::Walk(const Arguments& args) { return ThrowException(Exception::Error(String::New("No tree list to Walk."))); } - if(args.Length() == 0 || !args[0]->IsFunction()) { - return ThrowException(Exception::Error(String::New("Entry callback is required and must be a Function."))); + if(args.Length() == 0 || !args[0]->IsBoolean()) { + return ThrowException(Exception::Error(String::New("Blobs only flag is required and must be a Boolean."))); } if(args.Length() == 1 || !args[1]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Entry callback is required and must be a Function."))); + } + + if(args.Length() == 2 || !args[2]->IsFunction()) { return ThrowException(Exception::Error(String::New("End callback is required and must be a Function."))); } @@ -82,8 +86,9 @@ Handle GitTree::Walk(const Arguments& args) { baton->rawTree = tree->GetValue(); baton->error = NULL; - baton->entryCallback = Persistent::New(Local::Cast(args[0])); - baton->endCallback = Persistent::New(Local::Cast(args[1])); + baton->blobsOnly = CastFromJS(args[0]->ToBoolean()); + baton->entryCallback = Persistent::New(Local::Cast(args[1])); + baton->endCallback = Persistent::New(Local::Cast(args[2])); uv_thread_create(&baton->threadId, WalkWork, baton); @@ -106,16 +111,32 @@ void GitTree::WalkWork(void* payload) { baton->asyncEnd.data = baton; uv_async_send(&baton->asyncEnd); } -int GitTree::WalkWorkEntry(const char* root, const git_tree_entry* entry, void* payload) { +int GitTree::WalkWorkEntry(const char* root, const git_tree_entry* entry, + void* payload) { WalkBaton *baton = static_cast(payload); uv_mutex_lock(&baton->mutex); - GitTree::WalkEntry* walkEntry = new WalkEntry; - walkEntry->rawEntry = git_tree_entry_dup(entry); - walkEntry->root = root; + if (!baton->blobsOnly) { + + GitTree::WalkEntry* walkEntry = new WalkEntry; + walkEntry->rawEntry = git_tree_entry_dup(entry); + walkEntry->root = root; + baton->rawTreeEntries.push_back(walkEntry); - baton->rawTreeEntries.push_back(walkEntry); + } else { + git_tree_entry* rawEntry = git_tree_entry_dup(entry); + git_filemode_t fileMode = git_tree_entry_filemode(rawEntry); + + if (fileMode == GIT_FILEMODE_BLOB || + fileMode == GIT_FILEMODE_BLOB_EXECUTABLE) { + + GitTree::WalkEntry* walkEntry = new WalkEntry; + walkEntry->rawEntry = rawEntry; + walkEntry->root = root; + baton->rawTreeEntries.push_back(walkEntry); + } + } uv_mutex_unlock(&baton->mutex); From a6a37824688a41d1c48b5f6e280cef3d9f4f128b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:44:28 +1300 Subject: [PATCH 143/186] Updated convenience-commit.js --- test/convenience-commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index f1ebff50f..0740deb35 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -245,7 +245,7 @@ exports.tree = function(test) { test.equals(error, null, 'Getting latest branch commit should not error'); var commitTreeEntryCount = 0; - var expectedCommitTreeEntryCount = 238; + var expectedCommitTreeEntryCount = 198; commit.tree(function commitTree(error, tree) { tree.walk().on('entry', function(error, entry) { From 5e63a2fbb25d95e3c5a7f71c518cc2b55ae8d3b8 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:44:37 +1300 Subject: [PATCH 144/186] Updated convenience-tree test --- test/convenience-tree.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/convenience-tree.js b/test/convenience-tree.js index f4bcf0e2e..7fbe71c0c 100644 --- a/test/convenience-tree.js +++ b/test/convenience-tree.js @@ -3,25 +3,25 @@ var git = require('../'), fs = require('fs'); var sha = '5716e9757886eaf38d51c86b192258c960d9cfea'; -var fileCount = 513; +var fileCount = 512; // Number of blob & blob executabless exports.walk = function(test) { test.expect(516); git.repo('../.git', function(error, repo) { - repo.commit(sha, function(error, commit) { - var entryCount = 0; - commit.tree(function(error, tree) { - tree.walk().on('entry', function(error, index, entry) { - test.equals(error, null, 'There should be no error'); - entryCount++; - }).on('end', function(error, entries) { + repo.commit(sha, function(error, commit) { + var entryCount = 0; + commit.tree(function(error, tree) { + tree.walk().on('entry', function(error, index, entry) { test.equals(error, null, 'There should be no error'); - test.equals(entryCount, fileCount, 'The manual tree entry count and the "end" tree entry count do not match'); - test.equals(entries.length, fileCount, 'The end entries count and the manual entry count do not match'); - test.done(); - }); + entryCount++; + }).on('end', function(error, entries) { + test.equals(error, null, 'There should be no error'); + test.equals(entryCount, fileCount, 'The manual tree entry count and the "end" tree entry count do not match'); + test.equals(entries.length, fileCount, 'The end entries count and the manual entry count do not match'); + test.done(); }); }); - }); + }); + }); }; From c8be2ee63e49f519fea995bddabe73e8adabd56a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:44:47 +1300 Subject: [PATCH 145/186] Tidied error.cc --- src/error.cc | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/error.cc b/src/error.cc index 23f177981..5ecee568a 100755 --- a/src/error.cc +++ b/src/error.cc @@ -9,13 +9,14 @@ #include #include "cvv8/v8-convert.hpp" + #include "git2.h" #include "../include/error.h" using namespace v8; -using namespace cvv8; using namespace node; +using namespace cvv8; /** * Copied from libgit2/include/errors.h, to allow exporting to JS @@ -51,33 +52,33 @@ void GitError::Initialize (Handle target) { // Add libgit2 error codes to error object Local libgit2Errors = Object::New(); - libgit2Errors->Set(String::NewSymbol("GITERR_NOMEMORY"), cvv8::CastToJS(GITERR_NOMEMORY), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_OS"), cvv8::CastToJS(GITERR_OS), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_INVALID"), cvv8::CastToJS(GITERR_INVALID), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_REFERENCE"), cvv8::CastToJS(GITERR_REFERENCE), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_ZLIB"), cvv8::CastToJS(GITERR_ZLIB), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_REPOSITORY"), cvv8::CastToJS(GITERR_REPOSITORY), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_CONFIG"), cvv8::CastToJS(GITERR_CONFIG), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_REGEX"), cvv8::CastToJS(GITERR_REGEX), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_ODB"), cvv8::CastToJS(GITERR_ODB), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_INDEX"), cvv8::CastToJS(GITERR_INDEX), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_OBJECT"), cvv8::CastToJS(GITERR_OBJECT), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_NET"), cvv8::CastToJS(GITERR_NET), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_TAG"), cvv8::CastToJS(GITERR_TAG), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_TREE"), cvv8::CastToJS(GITERR_TREE), ReadOnly); - libgit2Errors->Set(String::NewSymbol("GITERR_INDEXER"), cvv8::CastToJS(GITERR_INDEXER), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_NOMEMORY"), CastToJS(GITERR_NOMEMORY), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_OS"), CastToJS(GITERR_OS), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_INVALID"), CastToJS(GITERR_INVALID), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_REFERENCE"), CastToJS(GITERR_REFERENCE), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_ZLIB"), CastToJS(GITERR_ZLIB), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_REPOSITORY"), CastToJS(GITERR_REPOSITORY), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_CONFIG"), CastToJS(GITERR_CONFIG), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_REGEX"), CastToJS(GITERR_REGEX), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_ODB"), CastToJS(GITERR_ODB), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_INDEX"), CastToJS(GITERR_INDEX), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_OBJECT"), CastToJS(GITERR_OBJECT), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_NET"), CastToJS(GITERR_NET), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_TAG"), CastToJS(GITERR_TAG), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_TREE"), CastToJS(GITERR_TREE), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GITERR_INDEXER"), CastToJS(GITERR_INDEXER), ReadOnly); // Add libgit2 error codes to error object Local libgit2ReturnCodes = Object::New(); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_OK"), cvv8::CastToJS(_GIT_OK), ReadOnly); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_ERROR"), cvv8::CastToJS(_GIT_ERROR), ReadOnly); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_ENOTFOUND"), cvv8::CastToJS(_GIT_ENOTFOUND), ReadOnly); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_EEXISTS"), cvv8::CastToJS(_GIT_EEXISTS), ReadOnly); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_EAMBIGUOUS"), cvv8::CastToJS(_GIT_EAMBIGUOUS), ReadOnly); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_EBUFS"), cvv8::CastToJS(_GIT_EBUFS), ReadOnly); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_PASSTHROUGH"), cvv8::CastToJS(_GIT_PASSTHROUGH), ReadOnly); - libgit2ReturnCodes->Set(String::NewSymbol("GIT_ITEROVER"), cvv8::CastToJS(_GIT_ITEROVER), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_OK"), CastToJS(_GIT_OK), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_ERROR"), CastToJS(_GIT_ERROR), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_ENOTFOUND"), CastToJS(_GIT_ENOTFOUND), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_EEXISTS"), CastToJS(_GIT_EEXISTS), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_EAMBIGUOUS"), CastToJS(_GIT_EAMBIGUOUS), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_EBUFS"), CastToJS(_GIT_EBUFS), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_PASSTHROUGH"), CastToJS(_GIT_PASSTHROUGH), ReadOnly); + libgit2ReturnCodes->Set(String::NewSymbol("GIT_ITEROVER"), CastToJS(_GIT_ITEROVER), ReadOnly); constructor_template = Persistent::New(tpl->GetFunction()); constructor_template->Set(String::NewSymbol("codes"), libgit2Errors, ReadOnly); @@ -92,7 +93,7 @@ Local GitError::WrapError(const git_error* error) { Local gitError = GitError::constructor_template->NewInstance(); Local stackTrace = StackTrace::CurrentStackTrace(10); - gitError->Set(String::NewSymbol("stackTrace"), cvv8::CastToJS(stackTrace->AsArray())); + gitError->Set(String::NewSymbol("stackTrace"), CastToJS(stackTrace->AsArray())); gitError->Set(String::NewSymbol("message"), String::New(error->message)); gitError->Set(String::NewSymbol("code"), Integer::New(error->klass)); From 8fb71bc18895c6f6d4eef42d460b6e37891a02a9 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:44:58 +1300 Subject: [PATCH 146/186] Tidied error.js --- lib/error.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/error.js b/lib/error.js index 103d91dff..857ce8e1f 100644 --- a/lib/error.js +++ b/lib/error.js @@ -26,20 +26,20 @@ util.inherits(GitError, Error); * @enum {Integer} */ GitError.prototype.codes = { - /** 0 */ GITERR_NOMEMORY: git.raw.Error.codes['GITERR_NOMEMORY'], - /** 1 */ GITERR_OS: git.raw.Error.codes['GITERR_OS'], - /** 2 */ GITERR_INVALID: git.raw.Error.codes['GITERR_INVALID'], - /** 3 */ GITERR_REFERENCE: git.raw.Error.codes['GITERR_REFERENCE'], - /** 4 */ GITERR_ZLIB: git.raw.Error.codes['GITERR_ZLIB'], - /** 5 */ GITERR_REPOSITORY: git.raw.Error.codes['GITERR_REPOSITORY'], - /** 6 */ GITERR_CONFIG: git.raw.Error.codes['GITERR_CONFIG'], - /** 7 */ GITERR_REGEX: git.raw.Error.codes['GITERR_REGEX'], - /** 8 */ GITERR_ODB: git.raw.Error.codes['GITERR_ODB'], - /** 9 */ GITERR_INDEX: git.raw.Error.codes['GITERR_INDEX'], - /** 10 */ GITERR_OBJECT: git.raw.Error.codes['GITERR_OBJECT'], - /** 11 */ GITERR_NET: git.raw.Error.codes['GITERR_NET'], - /** 12 */ GITERR_TAG: git.raw.Error.codes['GITERR_TAG'], - /** 13 */ GITERR_TREE: git.raw.Error.codes['GITERR_TREE'] + /** 0 */ GITERR_NOMEMORY: git.raw.Error.codesGITERR_NOMEMORY, + /** 1 */ GITERR_OS: git.raw.Error.codesGITERR_OS, + /** 2 */ GITERR_INVALID: git.raw.Error.codesGITERR_INVALID, + /** 3 */ GITERR_REFERENCE: git.raw.Error.codesGITERR_REFERENCE, + /** 4 */ GITERR_ZLIB: git.raw.Error.codesGITERR_ZLIB, + /** 5 */ GITERR_REPOSITORY: git.raw.Error.codesGITERR_REPOSITORY, + /** 6 */ GITERR_CONFIG: git.raw.Error.codesGITERR_CONFIG, + /** 7 */ GITERR_REGEX: git.raw.Error.codesGITERR_REGEX, + /** 8 */ GITERR_ODB: git.raw.Error.codesGITERR_ODB, + /** 9 */ GITERR_INDEX: git.raw.Error.codesGITERR_INDEX, + /** 10 */ GITERR_OBJECT: git.raw.Error.codesGITERR_OBJECT, + /** 11 */ GITERR_NET: git.raw.Error.codesGITERR_NET, + /** 12 */ GITERR_TAG: git.raw.Error.codesGITERR_TAG, + /** 13 */ GITERR_TREE: git.raw.Error.codesGITERR_TREE }; /** @@ -49,15 +49,15 @@ GitError.prototype.codes = { * @enum {Integer} */ GitError.prototype.returnCodes = { - /** 0 */ GIT_OK: git.raw.Error.returnCodes['GIT_OK'], - /** -1 */ GIT_ERROR: git.raw.Error.returnCodes['GIT_ERROR'], - /** -3 */ GIT_ENOTFOUND: git.raw.Error.returnCodes['GIT_ENOTFOUND'], - /** -4 */ GIT_EEXISTS: git.raw.Error.returnCodes['GIT_EEXISTS'], - /** -5 */ GIT_EAMBIGUOUS: git.raw.Error.returnCodes['GIT_EAMBIGUOUS'], - /** -6 */ GIT_EBUFS: git.raw.Error.returnCodes['GIT_EBUFS'], - /** -30 */ GIT_PASSTHROUGH: git.raw.Error.returnCodes['GIT_PASSTHROUGH'], - /** -31 */ GIT_ITEROVER: git.raw.Error.returnCodes['GIT_ITEROVER'] -} + /** 0 */ GIT_OK: git.raw.Error.returnCodesGIT_OK, + /** -1 */ GIT_ERROR: git.raw.Error.returnCodesGIT_ERROR, + /** -3 */ GIT_ENOTFOUND: git.raw.Error.returnCodesGIT_ENOTFOUND, + /** -4 */ GIT_EEXISTS: git.raw.Error.returnCodesGIT_EEXISTS, + /** -5 */ GIT_EAMBIGUOUS: git.raw.Error.returnCodesGIT_EAMBIGUOUS, + /** -6 */ GIT_EBUFS: git.raw.Error.returnCodesGIT_EBUFS, + /** -30 */ GIT_PASSTHROUGH: git.raw.Error.returnCodesGIT_PASSTHROUGH, + /** -31 */ GIT_ITEROVER: git.raw.Error.returnCodesGIT_ITEROVER +}; exports.error = function(error) { return new GitError(error.message, error.code); From 31d8f881dd5f52ba344f1387af4f970d70433b35 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:45:09 +1300 Subject: [PATCH 147/186] Moved entry below raw assignment --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index f89724f93..b4856ff00 100755 --- a/lib/index.js +++ b/lib/index.js @@ -19,7 +19,6 @@ 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 { @@ -31,6 +30,7 @@ try { // Initialize objects that need to access their raw counterparts exports.diffList = require('./diff_list.js').diffList; exports.error = require('./error.js').error; +exports.entry = require('./tree_entry.js').entry; // Set version exports.version = require('../package').version; From c4bffab74748eeb0e8c747e89ed173d78b74377e Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:45:30 +1300 Subject: [PATCH 148/186] Updated fileMode handling in tree_entry.js --- lib/tree_entry.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index f39e6ea7f..1b3949648 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -1,6 +1,15 @@ var git = require('../'), success = require('./utilities').success; +var fileModeIsFile = function(fileMode, instance) { + return fileMode === instance.fileModes.GIT_FILEMODE_BLOB || + fileMode === instance.fileModes.GIT_FILEMODE_BLOB_EXECUTABLE; +}; + +var fileModeIsDirectory = function(fileMode, instance) { + return fileMode === instance.fileModes.GIT_FILEMODE_TREE; +}; + /** * Convenience tree entry constructor. * @@ -29,12 +38,12 @@ var TreeEntry = function(rawRepo, rawTreeEntry) { * @enum {Integer} */ TreeEntry.prototype.fileModes = { - /** 0000000 */ GIT_FILEMODE_NEW: git.raw.TreeEntry.GIT_FILEMODE_NEW, - /** 0040000 */ GIT_FILEMODE_TREE: git.raw.TreeEntry.GIT_FILEMODE_TREE, - /** 0100644 */ GIT_FILEMODE_BLOB: git.raw.TreeEntry.GIT_FILEMODE_BLOB, - /** 0100755 */ GIT_FILEMODE_BLOB_EXECUTABLE: git.raw.TreeEntry.GIT_FILEMODE_BLOB_EXECUTABLE, - /** 0120000 */ GIT_FILEMODE_LINK: git.raw.TreeEntry.GIT_FILEMODE_LINK, - /** 0160000 */ GIT_FILEMODE_COMMIT: git.raw.TreeEntry.GIT_FILEMODE_COMMIT + /** 0000000 */ GIT_FILEMODE_NEW: git.raw.TreeEntry.fileModes.GIT_FILEMODE_NEW, + /** 0040000 */ GIT_FILEMODE_TREE: git.raw.TreeEntry.fileModes.GIT_FILEMODE_TREE, + /** 0100644 */ GIT_FILEMODE_BLOB: git.raw.TreeEntry.fileModes.GIT_FILEMODE_BLOB, + /** 0100755 */ GIT_FILEMODE_BLOB_EXECUTABLE: git.raw.TreeEntry.fileModes.GIT_FILEMODE_BLOB_EXECUTABLE, + /** 0120000 */ GIT_FILEMODE_LINK: git.raw.TreeEntry.fileModes.GIT_FILEMODE_LINK, + /** 0160000 */ GIT_FILEMODE_COMMIT: git.raw.TreeEntry.fileModes.GIT_FILEMODE_COMMIT }; /** @@ -91,13 +100,13 @@ TreeEntry.prototype.isFile = function(callback) { */ var self = this; if (typeof self._cache.fileMode !== 'undefined') { - callback(null, self._cache.fileMode === self.GIT_FILEMODE_BLOB); + callback(null, fileModeIsFile(self._cache.fileMode, self)); return; } self.rawEntry.fileMode(function(error, fileMode) { if (success(error, callback)) { self._cache.fileMode = fileMode; - callback(null, self._cache.fileMode === self.GIT_FILEMODE_BLOB); + callback(null, fileModeIsFile(self._cache.fileMode, self)); } }); }; @@ -110,13 +119,13 @@ TreeEntry.prototype.isFile = function(callback) { TreeEntry.prototype.isDirectory = function(callback) { var self = this; if (typeof self._cache.fileMode !== 'undefined') { - callback(null, self._cache.fileMode === self.GIT_FILEMODE_TREE); + callback(null, fileModeIsDirectory(self._cache.fileMode, self)); return; } self.rawEntry.fileMode(function(error, fileMode) { if (success(error, callback)) { self._cache.fileMode = fileMode; - callback(null, self._cache.fileMode === self.GIT_FILEMODE_TREE); + callback(null, fileModeIsDirectory(self._cache.fileMode, self)); } }); }; From a811231d505711204368c63d645bf743916e614b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Wed, 3 Apr 2013 23:45:38 +1300 Subject: [PATCH 149/186] Tidied error.h --- include/error.h | 33 ++++----------------------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/include/error.h b/include/error.h index 3da2a90b0..101a51122 100755 --- a/include/error.h +++ b/include/error.h @@ -16,48 +16,23 @@ using namespace v8; using namespace node; /** - * Class: GitError * Wrapper for libgit2 git_error. */ class GitError : public ObjectWrap { public: - /** - * Variable: constructor_template - * Used to create Node.js constructor. - */ + static Persistent constructor_template; - /** - * Function: Initialize - * Used to intialize the EventEmitter from Node.js - * - * Parameters: - * target - Object the Node.js global module object - */ + static void Initialize(Handle target); static Local WrapError(const git_error* error); protected: - const git_error* error; - - /** - * Constructor: GitError - */ GitError() {}; - /** - * Deconstructor: GitError - */ ~GitError() {}; - /** - * Function: New - * - * Parameters: - * args Arguments function call - * - * Returns: - * Object args.This() - */ + const git_error* error; + static Handle New(const Arguments& args); }; From 2f2e10d3827fd28baaa7abf90d4d0bddd379d73a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:11:43 +1300 Subject: [PATCH 150/186] Updated convenience-entry tests --- test/convenience-entry.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/test/convenience-entry.js b/test/convenience-entry.js index a4a5b80dd..77b868424 100644 --- a/test/convenience-entry.js +++ b/test/convenience-entry.js @@ -2,10 +2,10 @@ var git = require('../'); var sha = '5716e9757886eaf38d51c86b192258c960d9cfea'; -var getEntry = function(callback) { +var getEntry = function(path, callback) { git.repo('../.git', function(error, repo) { repo.commit(sha, function(error, commit) { - commit.file('README.md', function(error, entry) { + commit.file(path, function(error, entry) { callback(error, entry); }); }); @@ -14,10 +14,40 @@ var getEntry = function(callback) { exports.sha = function(test) { test.expect(1); - getEntry(function(error, entry) { + getEntry('README.md', function(error, entry) { entry.sha(function(error, sha) { test.equal(sha, '6cb45ba5d32532bf0d1310dc31ca4f20f59964bc', 'Entry SHA should match expected value'); test.done(); }); }); }; + +exports.isFile = function(test) { + test.expect(2); + getEntry('README.md', function(error, entry) { + entry.isFile(function(error, isFile) { + test.equal(isFile, true, 'Entry is a file'); + getEntry('example', function(error, entry) { + entry.isFile(function(error, isFile) { + test.equal(isFile, false, 'Entry is a directory'); + test.done(); + }); + }); + }); + }); +}; + +exports.isDirectory = function(test) { + test.expect(2); + getEntry('example', function(error, entry) { + entry.isFile(function(error, isFile) { + test.equal(isFile, false, 'Entry is a directory'); + getEntry('README.md', function(error, entry) { + entry.isFile(function(error, isFile) { + test.equal(isFile, true, 'Entry is a file'); + test.done(); + }); + }); + }); + }); +}; From 4b3345826451dbb8398b42949224d1faf8eb5419 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:11:54 +1300 Subject: [PATCH 151/186] Added error code & return code tests --- test/convenience-error.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/convenience-error.js b/test/convenience-error.js index cb1b10cca..38393dffa 100644 --- a/test/convenience-error.js +++ b/test/convenience-error.js @@ -34,6 +34,40 @@ exports.method = function(test){ test.done(); }; +exports.codes = function(test) { + test.expect(14); + var error = new git.error(); + test.equal(error.codes.GITERR_NOMEMORY, git.raw.Error.codes.GITERR_NOMEMORY, 'GITERR_NOMEMORY code should match expected value'); + test.equal(error.codes.GITERR_OS, git.raw.Error.codes.GITERR_OS, 'GITERR_OS code should match expected value'); + test.equal(error.codes.GITERR_INVALID, git.raw.Error.codes.GITERR_INVALID, 'GITERR_INVALID code should match expected value'); + test.equal(error.codes.GITERR_REFERENCE, git.raw.Error.codes.GITERR_REFERENCE, 'GITERR_REFERENCE code should match expected value'); + test.equal(error.codes.GITERR_ZLIB, git.raw.Error.codes.GITERR_ZLIB, 'GITERR_ZLIB code should match expected value'); + test.equal(error.codes.GITERR_REPOSITORY, git.raw.Error.codes.GITERR_REPOSITORY, 'GITERR_REPOSITORY code should match expected value'); + test.equal(error.codes.GITERR_CONFIG, git.raw.Error.codes.GITERR_CONFIG, 'GITERR_CONFIG code should match expected value'); + test.equal(error.codes.GITERR_REGEX, git.raw.Error.codes.GITERR_REGEX, 'GITERR_REGEX code should match expected value'); + test.equal(error.codes.GITERR_ODB, git.raw.Error.codes.GITERR_ODB, 'GITERR_ODB code should match expected value'); + test.equal(error.codes.GITERR_INDEX, git.raw.Error.codes.GITERR_INDEX, 'GITERR_INDEX code should match expected value'); + test.equal(error.codes.GITERR_OBJECT, git.raw.Error.codes.GITERR_OBJECT, 'GITERR_OBJECT code should match expected value'); + test.equal(error.codes.GITERR_NET, git.raw.Error.codes.GITERR_NET, 'GITERR_NET code should match expected value'); + test.equal(error.codes.GITERR_TAG, git.raw.Error.codes.GITERR_TAG, 'GITERR_TAG code should match expected value'); + test.equal(error.codes.GITERR_TREE, git.raw.Error.codes.GITERR_TREE, 'GITERR_TREE code should match expected value'); + test.done(); +}; + +exports.returnCodes = function(test) { + test.expect(8); + var error = new git.error(); + test.equal(error.returnCodes.GIT_OK, git.raw.Error.returnCodes.GIT_OK, 'GIT_OK return code should match expected value'); + test.equal(error.returnCodes.GIT_ERROR, git.raw.Error.returnCodes.GIT_ERROR, 'GIT_ERROR return code should match expected value'); + test.equal(error.returnCodes.GIT_ENOTFOUND, git.raw.Error.returnCodes.GIT_ENOTFOUND, 'GIT_ENOTFOUND return code should match expected value'); + test.equal(error.returnCodes.GIT_EEXISTS, git.raw.Error.returnCodes.GIT_EEXISTS, 'GIT_EEXISTS return code should match expected value'); + test.equal(error.returnCodes.GIT_EAMBIGUOUS, git.raw.Error.returnCodes.GIT_EAMBIGUOUS, 'GIT_EAMBIGUOUS return code should match expected value'); + test.equal(error.returnCodes.GIT_EBUFS, git.raw.Error.returnCodes.GIT_EBUFS, 'GIT_EBUFS return code should match expected value'); + test.equal(error.returnCodes.GIT_PASSTHROUGH, git.raw.Error.returnCodes.GIT_PASSTHROUGH, 'GIT_PASSTHROUGH return code should match expected value'); + test.equal(error.returnCodes.GIT_ITEROVER, git.raw.Error.returnCodes.GIT_ITEROVER, 'GIT_ITEROVER return code should match expected value'); + test.done(); +}; + /** * Test that * From 91f4ec8937110ae4ee7cbdd9fad5d53737a982c3 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:12:05 +1300 Subject: [PATCH 152/186] Updated convenience-oid tests --- test/convenience-oid.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/convenience-oid.js b/test/convenience-oid.js index 465c81f2a..b900f56a9 100644 --- a/test/convenience-oid.js +++ b/test/convenience-oid.js @@ -34,15 +34,13 @@ var knownSha = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; exports.fromString = function(test) { test.expect(1); - git.repo('../.git', function(error, repository) { - (new git.oid()).fromString(knownSha, function(error, oid) { - test.equal(error, null, 'Should not error'); - test.done(); - }); + (new git.oid()).fromString(knownSha, function(error, oid) { + test.equal(error, null, 'Should not error'); + test.done(); }); }; -exports.fromString = function(test) { +exports.sha = function(test) { test.expect(2); (new git.oid()).fromString(knownSha, function(error, oid) { oid.sha(function(error, sha) { From b4fce813659d251621b4b8155a488bc1ef052bbb Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:12:15 +1300 Subject: [PATCH 153/186] Updated convenience-tree tests --- test/convenience-tree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/convenience-tree.js b/test/convenience-tree.js index 7fbe71c0c..813fa3d8c 100644 --- a/test/convenience-tree.js +++ b/test/convenience-tree.js @@ -6,7 +6,7 @@ var sha = '5716e9757886eaf38d51c86b192258c960d9cfea'; var fileCount = 512; // Number of blob & blob executabless exports.walk = function(test) { - test.expect(516); + test.expect(515); git.repo('../.git', function(error, repo) { repo.commit(sha, function(error, commit) { From 7b8fcdcc63b4fb14a09aef76d539fb6127be623e Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:12:36 +1300 Subject: [PATCH 154/186] Converted error to use new like all the rest --- lib/error.js | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/error.js b/lib/error.js index 857ce8e1f..9fbeac5a4 100644 --- a/lib/error.js +++ b/lib/error.js @@ -5,7 +5,7 @@ var git = require('../'), * GitError constructor. * * @constructor - * @param {String} message The error description. Set from giterr_last->message. + * @param {String} [message = 'No message'] The error description. Set from giterr_last->message. * @param {Integer} [code = git.raw.Error.codes.GITERR_INVALID] The error code. Set from giterr_last->klass */ var GitError = function(message, code) { @@ -13,7 +13,7 @@ var GitError = function(message, code) { Error.captureStackTrace(this, exports.error); this.name = 'GitError'; - this.message = message; + this.message = message || 'No message'; this.code = code || git.raw.Error.codes.GITERR_INVALID; }; @@ -26,20 +26,20 @@ util.inherits(GitError, Error); * @enum {Integer} */ GitError.prototype.codes = { - /** 0 */ GITERR_NOMEMORY: git.raw.Error.codesGITERR_NOMEMORY, - /** 1 */ GITERR_OS: git.raw.Error.codesGITERR_OS, - /** 2 */ GITERR_INVALID: git.raw.Error.codesGITERR_INVALID, - /** 3 */ GITERR_REFERENCE: git.raw.Error.codesGITERR_REFERENCE, - /** 4 */ GITERR_ZLIB: git.raw.Error.codesGITERR_ZLIB, - /** 5 */ GITERR_REPOSITORY: git.raw.Error.codesGITERR_REPOSITORY, - /** 6 */ GITERR_CONFIG: git.raw.Error.codesGITERR_CONFIG, - /** 7 */ GITERR_REGEX: git.raw.Error.codesGITERR_REGEX, - /** 8 */ GITERR_ODB: git.raw.Error.codesGITERR_ODB, - /** 9 */ GITERR_INDEX: git.raw.Error.codesGITERR_INDEX, - /** 10 */ GITERR_OBJECT: git.raw.Error.codesGITERR_OBJECT, - /** 11 */ GITERR_NET: git.raw.Error.codesGITERR_NET, - /** 12 */ GITERR_TAG: git.raw.Error.codesGITERR_TAG, - /** 13 */ GITERR_TREE: git.raw.Error.codesGITERR_TREE + /** 0 */ GITERR_NOMEMORY: git.raw.Error.codes.GITERR_NOMEMORY, + /** 1 */ GITERR_OS: git.raw.Error.codes.GITERR_OS, + /** 2 */ GITERR_INVALID: git.raw.Error.codes.GITERR_INVALID, + /** 3 */ GITERR_REFERENCE: git.raw.Error.codes.GITERR_REFERENCE, + /** 4 */ GITERR_ZLIB: git.raw.Error.codes.GITERR_ZLIB, + /** 5 */ GITERR_REPOSITORY: git.raw.Error.codes.GITERR_REPOSITORY, + /** 6 */ GITERR_CONFIG: git.raw.Error.codes.GITERR_CONFIG, + /** 7 */ GITERR_REGEX: git.raw.Error.codes.GITERR_REGEX, + /** 8 */ GITERR_ODB: git.raw.Error.codes.GITERR_ODB, + /** 9 */ GITERR_INDEX: git.raw.Error.codes.GITERR_INDEX, + /** 10 */ GITERR_OBJECT: git.raw.Error.codes.GITERR_OBJECT, + /** 11 */ GITERR_NET: git.raw.Error.codes.GITERR_NET, + /** 12 */ GITERR_TAG: git.raw.Error.codes.GITERR_TAG, + /** 13 */ GITERR_TREE: git.raw.Error.codes.GITERR_TREE }; /** @@ -49,16 +49,14 @@ GitError.prototype.codes = { * @enum {Integer} */ GitError.prototype.returnCodes = { - /** 0 */ GIT_OK: git.raw.Error.returnCodesGIT_OK, - /** -1 */ GIT_ERROR: git.raw.Error.returnCodesGIT_ERROR, - /** -3 */ GIT_ENOTFOUND: git.raw.Error.returnCodesGIT_ENOTFOUND, - /** -4 */ GIT_EEXISTS: git.raw.Error.returnCodesGIT_EEXISTS, - /** -5 */ GIT_EAMBIGUOUS: git.raw.Error.returnCodesGIT_EAMBIGUOUS, - /** -6 */ GIT_EBUFS: git.raw.Error.returnCodesGIT_EBUFS, - /** -30 */ GIT_PASSTHROUGH: git.raw.Error.returnCodesGIT_PASSTHROUGH, - /** -31 */ GIT_ITEROVER: git.raw.Error.returnCodesGIT_ITEROVER + /** 0 */ GIT_OK: git.raw.Error.returnCodes.GIT_OK, + /** -1 */ GIT_ERROR: git.raw.Error.returnCodes.GIT_ERROR, + /** -3 */ GIT_ENOTFOUND: git.raw.Error.returnCodes.GIT_ENOTFOUND, + /** -4 */ GIT_EEXISTS: git.raw.Error.returnCodes.GIT_EEXISTS, + /** -5 */ GIT_EAMBIGUOUS: git.raw.Error.returnCodes.GIT_EAMBIGUOUS, + /** -6 */ GIT_EBUFS: git.raw.Error.returnCodes.GIT_EBUFS, + /** -30 */ GIT_PASSTHROUGH: git.raw.Error.returnCodes.GIT_PASSTHROUGH, + /** -31 */ GIT_ITEROVER: git.raw.Error.returnCodes.GIT_ITEROVER }; -exports.error = function(error) { - return new GitError(error.message, error.code); -}; +exports.error = GitError; From 760fc58a75a7d97a097b27c9df2a2d5cabcc8ec9 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:12:55 +1300 Subject: [PATCH 155/186] Fixed minor bugs in oid --- lib/oid.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/oid.js b/lib/oid.js index 63400a94a..c32b58a3c 100644 --- a/lib/oid.js +++ b/lib/oid.js @@ -1,4 +1,5 @@ -var git = require('../'); +var git = require('../'), + success = require('./utilities').success; /** * Convenience Oid constructor. @@ -9,6 +10,8 @@ var git = require('../'); var Oid = function(rawOid) { if(rawOid instanceof git.raw.Oid) { this.rawOid = rawOid; + } else { + this.rawOid = new git.raw.Oid(); } }; @@ -33,7 +36,7 @@ Oid.prototype.fromString = function(sha, callback) { */ var self = this; self.rawOid.fromString(sha, function(error, rawOid) { - if (success(error, rawOid)) { + if (success(error, callback)) { self.rawOid = rawOid; callback(null, self); } From 1af736985fafe4f2b3174f7804c8c62d019a9425 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:13:14 +1300 Subject: [PATCH 156/186] Use new when creating errors --- lib/blob.js | 2 +- lib/commit.js | 2 +- lib/reference.js | 2 +- lib/repo.js | 2 +- lib/revwalk.js | 6 +++--- lib/tree.js | 4 ++-- lib/tree_entry.js | 4 ++-- lib/utilities.js | 5 +++-- test/utilities.js | 5 +---- 9 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/blob.js b/lib/blob.js index 1467ee65e..c3d368008 100644 --- a/lib/blob.js +++ b/lib/blob.js @@ -10,7 +10,7 @@ var git = require('../'), */ var Blob = function(rawRepo, rawBlob) { if(!(rawRepo instanceof git.raw.Repo)) { - throw git.error('First parameter for Blob must be a raw repo'); + throw new git.error('First parameter for Blob must be a raw repo'); } this.rawRepo = rawRepo; diff --git a/lib/commit.js b/lib/commit.js index bb2c6b08a..f8ab4534a 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -11,7 +11,7 @@ var git = require( '../' ), */ var Commit = function(rawRepo, rawCommit) { if (!(rawRepo instanceof git.raw.Repo)) { - throw git.error('First parameter for Commit must be a raw repo'); + throw new git.error('First parameter for Commit must be a raw repo'); } this.rawRepo = rawRepo; diff --git a/lib/reference.js b/lib/reference.js index ebe6bf1c6..9d0c18069 100644 --- a/lib/reference.js +++ b/lib/reference.js @@ -10,7 +10,7 @@ var git = require('../'), */ var Reference = function(rawRepo, rawReference) { if (!(rawRepo instanceof git.raw.Repo)) { - throw git.error('First parameter for Reference must be a raw repo'); + throw new git.error('First parameter for Reference must be a raw repo'); } this.rawRepo = rawRepo; diff --git a/lib/repo.js b/lib/repo.js index 45c3be2a6..36b2ee314 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -13,7 +13,7 @@ var Repo = function() { */ Repo.prototype.open = function(directory, callback) { if (typeof callback === 'undefined') { - throw git.error('Callback is required and must be a Function'); + throw new git.error('Callback is required and must be a Function'); } var self = this; self.rawRepo.open(directory, function openRepository(error, rawRepo) { diff --git a/lib/revwalk.js b/lib/revwalk.js index b85aab22b..30fc2b4b4 100644 --- a/lib/revwalk.js +++ b/lib/revwalk.js @@ -10,7 +10,7 @@ var git = require('../'), */ var RevWalk = function(rawRepo, rawRevWalk) { if (!(rawRepo instanceof git.raw.Repo)) { - throw git.error('First parameter for RevWalk must be a raw repo'); + throw new git.error('First parameter for RevWalk must be a raw repo'); } this.rawRepo = rawRepo; @@ -60,7 +60,7 @@ RevWalk.prototype.walk = function(oid, callback) { self.rawRevWalk.next(function revWalkNext(error, oid, walkOver) { if(error) { - callback(git.error(error), index, commit); + callback(new git.error(error.message, error.code), index, commit); return; } @@ -72,7 +72,7 @@ RevWalk.prototype.walk = function(oid, callback) { (new git.commit(self.rawRepo)).lookup(oid, function revWalkCommitLookup(error, commit) { if(error) { - callback(git.error(error), index, commit); + callback(new git.error(error.message, error.code), index, commit); return; } if(callback(null, index, commit) === false) { diff --git a/lib/tree.js b/lib/tree.js index dc825be56..774689a7e 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -11,7 +11,7 @@ var git = require('../'), */ var Tree = function(rawRepo, rawTree) { if(!(rawRepo instanceof git.raw.Repo)) { - throw git.error('First parameter for Tree must be a raw repo'); + throw new git.error('First parameter for Tree must be a raw repo'); } this.rawRepo = rawRepo; @@ -84,7 +84,7 @@ Tree.prototype.walk = function(blobsOnly) { * @param {GitError|null} error An error object if there was an issue, null otherwise. * @param {Entry[]} entries The tree entries. */ - event.emit('end', error ? git.error(error) : null, entries); + event.emit('end', error ? new git.error(error.message, error.code) : null, entries); }); return event; diff --git a/lib/tree_entry.js b/lib/tree_entry.js index 1b3949648..acad318fd 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -19,11 +19,11 @@ var fileModeIsDirectory = function(fileMode, instance) { */ var TreeEntry = function(rawRepo, rawTreeEntry) { if(!(rawRepo instanceof git.raw.Repo)) { - throw git.error('First parameter for Tree Entry must be a raw repo', 0); + throw new git.error('First parameter for Tree Entry must be a raw repo', 0); } if(!(rawTreeEntry instanceof git.raw.TreeEntry)) { - throw git.error('Second parameter for Tree Entry must be a raw tree entry', 0); + throw new git.error('Second parameter for Tree Entry must be a raw tree entry', 0); } this.rawRepo = rawRepo; diff --git a/lib/utilities.js b/lib/utilities.js index f2bbeeb6a..e21d907fd 100755 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -4,8 +4,9 @@ var git = require('../'); * Check if error is null, if it is not, convert it to a GitError and call * the callback. * - * @param {Object} error + * @param {Object} error * @param {Function} callback + * * @return {Boolean} True if the error was null, false otherwise. */ exports.success = function(error, callback) { @@ -13,7 +14,7 @@ exports.success = function(error, callback) { if (error instanceof git.error) { callback(error); } else { - callback(git.error(error)); + callback(new git.error(error.message, error.code)); } return false; } diff --git a/test/utilities.js b/test/utilities.js index 6ed99f9d9..06f9714f3 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -14,10 +14,7 @@ exports.successNoError = function(test){ */ exports.successError = function(test){ test.expect(3); - utilities.success(git.error({ - code: git.raw.Error.codes.GITERR_INVALID, - message: 'Message' - }), function(error) { + utilities.success(new git.error('Message', git.raw.Error.codes.GITERR_INVALID), function(error) { test.notEqual(error, null, 'Error should not be null'); test.equal(error.code, git.raw.Error.codes.GITERR_INVALID, 'Error code should match input'); test.equal(error.message, 'Message', 'Error message should match input'); From bf8f05df43200094bf59c1546bb720f6c71d80fc Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:53:48 +1300 Subject: [PATCH 157/186] Expanded convenience-entry tests --- test/convenience-entry.js | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/test/convenience-entry.js b/test/convenience-entry.js index 77b868424..f24068a7a 100644 --- a/test/convenience-entry.js +++ b/test/convenience-entry.js @@ -12,6 +12,15 @@ var getEntry = function(path, callback) { }); }; +exports.missingFile = function(test) { + test.expect(1); + + getEntry('test/convenience-entry.js', function(error, entry) { + test.notEqual(error, null, 'Missing file should error'); + test.done(); + }); +}; + exports.sha = function(test) { test.expect(1); getEntry('README.md', function(error, entry) { @@ -51,3 +60,64 @@ exports.isDirectory = function(test) { }); }); }; + +exports.name = function(test) { + test.expect(2); + getEntry('test/raw-commit.js', function(error, entry) { + test.equal(error, null, 'Should not error'); + entry.name(function(error, name) { + test.equal(name, 'raw-commit.js', 'Name should match expected value'); + test.done(); + }); + }); +}; + +exports.root = function(test) { + test.expect(1); + getEntry('test/raw-commit.js', function(error, entry) { + entry.root(function(error, root) { + test.equal(root, 'test', 'Root should match expected value'); + test.done(); + }); + }); +}; + +exports.path = function(test) { + test.expect(1); + getEntry('test/raw-commit.js', function(error, entry) { + entry.path(function(error, path) { + test.equal(path, 'test/raw-commit.js', 'Path should match expected value'); + test.done(); + }); + }); +}; + +exports.content = function(test) { + test.expect(1); + getEntry('test/raw-commit.js', function(error, entry) { + entry.content(function(error, content) { + test.equal(content.length, 2736, 'Content length should match expected value'); + test.done(); + }); + }); +}; + +exports.toBlob = function(test) { + test.expect(1); + getEntry('test/raw-commit.js', function(error, entry) { + entry.toBlob(function(error, blob) { + test.equal(blob instanceof git.blob, true, 'Expected instance of Blob'); + test.done(); + }); + }); +}; + +exports.tree = function(test) { + test.expect(1); + getEntry('test', function(error, entry) { + entry.tree(function(error, tree) { + test.equal(tree instanceof git.tree, true, 'Expected instance of Tree'); + test.done(); + }); + }); +}; From f2fd93af0232a16930eb664d1ee5266e233fee28 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:53:58 +1300 Subject: [PATCH 158/186] Added lookup to tree --- include/tree.h | 15 +++++++++++++ lib/tree.js | 23 +++++++++++++++++++- src/tree.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/include/tree.h b/include/tree.h index 9ea01a1ca..4cc84c457 100755 --- a/include/tree.h +++ b/include/tree.h @@ -42,6 +42,10 @@ class GitTree : public ObjectWrap { static Handle New(const Arguments& args); + static Handle Lookup(const Arguments& args); + static void LookupWork(uv_work_t* req); + static void LookupAfterWork(uv_work_t* req); + static Handle Walk(const Arguments& args); static void WalkWork(void* payload); static int WalkWorkEntry(const char *root, const git_tree_entry *entry, void *payload); @@ -56,6 +60,17 @@ class GitTree : public ObjectWrap { git_tree* tree; + struct LookupBaton { + uv_work_t request; + const git_error* error; + + git_oid rawOid; + git_repository* rawRepo; + git_tree* rawTree; + + Persistent callback; + }; + struct WalkEntry { git_tree_entry* rawEntry; std::string root; diff --git a/lib/tree.js b/lib/tree.js index 774689a7e..d56d11eff 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -22,6 +22,27 @@ var Tree = function(rawRepo, rawTree) { } }; +/** + * Retrieve the raw tree identified by the given Oid. + * + * @param {Oid} oid The Oid identifying a tree. + * @param {Tree~lookupCallback} callback + */ +Tree.prototype.lookup = function(oid, callback) { + /** + * @callback Tree~lookupCallback Callback executed when the tree is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {Tree|null} tree The tree object or null. + */ + var self = this; + self.rawTree.lookup(oid.getRawOid(), self.rawRepo, function(error, rawTree) { + if (success(error, callback)) { + self.rawTree = rawTree; + callback(null, self); + } + }); +}; + /** * Retrieve the entry by path. * @@ -32,7 +53,7 @@ Tree.prototype.entry = function(path, callback) { /** * @callback Tree~entryCallback Callback executed when an entry is retrieved. * @param {GitError|null} error An Error or null if successful. - * @param {Entry|null} blob The tree entry object or null. + * @param {Entry|null} entry The tree entry object or null. */ var self = this; self.rawTree.entryByPath(path, function(error, rawEntry) { diff --git a/src/tree.cc b/src/tree.cc index 054ce250f..3c21e05bf 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -33,6 +33,7 @@ void GitTree::Initialize (Handle target) { tpl->InstanceTemplate()->SetInternalFieldCount(1); tpl->SetClassName(String::NewSymbol("Tree")); + NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); NODE_SET_PROTOTYPE_METHOD(tpl, "walk", Walk); NODE_SET_PROTOTYPE_METHOD(tpl, "entryByPath", EntryByPath); @@ -57,6 +58,64 @@ Handle GitTree::New(const Arguments& args) { return scope.Close(args.This()); } +Handle GitTree::Lookup(const Arguments& args) { + HandleScope scope; + + if(args.Length() == 0 || !args[0]->IsObject()) { + return ThrowException(Exception::Error(String::New("Oid is required and must be a Object."))); + } + + if(args.Length() == 1 || !args[1]->IsObject()) { + return ThrowException(Exception::Error(String::New("Repository is required and must be a Object."))); + } + + if(args.Length() == 2 || !args[2]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + LookupBaton* baton = new LookupBaton; + baton->request.data = baton; + baton->error = NULL; + baton->rawTree = ObjectWrap::Unwrap(args.This())->GetValue(); + baton->rawOid = ObjectWrap::Unwrap(args[0]->ToObject())->GetValue(); + baton->rawRepo = ObjectWrap::Unwrap(args[1]->ToObject())->GetValue(); + baton->callback = Persistent::New(Local::Cast(args[2])); + + uv_queue_work(uv_default_loop(), &baton->request, LookupWork, (uv_after_work_cb)LookupAfterWork); + + return Undefined(); +} +void GitTree::LookupWork(uv_work_t* req) { + LookupBaton* baton = static_cast(req->data); + + int returnCode = git_tree_lookup(&baton->rawTree, baton->rawRepo, &baton->rawOid); + if (returnCode != GIT_OK) { + baton->error = giterr_last(); + } +} +void GitTree::LookupAfterWork(uv_work_t* req) { + HandleScope scope; + LookupBaton* baton = static_cast(req->data); + + if (success(baton->error, baton->callback)) { + Local tree = GitTree::constructor_template->NewInstance(); + GitTree *treeInstance = ObjectWrap::Unwrap(tree); + treeInstance->SetValue(baton->rawTree); + + Handle argv[2] = { + Local::New(Null()), + tree + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } + delete req; +} + Handle GitTree::Walk(const Arguments& args) { HandleScope scope; From ccbeff4c5478b9c9f3faca7692cda22833d1f834 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:54:10 +1300 Subject: [PATCH 159/186] Name anonymous function --- lib/commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index f8ab4534a..4a515f019 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -209,7 +209,7 @@ Commit.prototype.file = function(path, callback) { * @param {GitError|null} error An Error or null if successful. * @param {Entry|null} file Retrieved file entry. */ - this.tree(function commitFile(error, tree) { + this.tree(function commitFileCallback(error, tree) { if (!success(error, callback)) { return; } From 0c2abc97f98fd86d08239e5c7ee02f7361c1ba8f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 00:54:21 +1300 Subject: [PATCH 160/186] Documented tree entry more --- lib/tree_entry.js | 60 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/lib/tree_entry.js b/lib/tree_entry.js index acad318fd..f30653f21 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -1,5 +1,6 @@ var git = require('../'), - success = require('./utilities').success; + path = require('path'), + success = require('./utilities').success; var fileModeIsFile = function(fileMode, instance) { return fileMode === instance.fileModes.GIT_FILEMODE_BLOB || @@ -59,7 +60,7 @@ TreeEntry.prototype.oid = function(callback) { */ this.rawEntry.oid(function(error, rawOid) { if (success(error, callback)) { - callback(null, git.oid(rawOid)); + callback(null, new git.oid(rawOid)); } }); }; @@ -88,7 +89,7 @@ TreeEntry.prototype.sha = function(callback) { }; /** - * Determine whether this TreeEntry is a file. + * Determine whether this TreeEntry is a file (blob or blob executable). * * @param {TreeEntry~isFileCallback} callback */ @@ -96,7 +97,7 @@ TreeEntry.prototype.isFile = function(callback) { /** * @callback TreeEntry~isFileCallback Callback executed after type is determined. * @param {GitError|null} error An Error or null if successful. - * @param {Boolean|null} content True if the entry is a file, false otherwise. + * @param {Boolean|null} content True if the entry is a blob or blob executable, false otherwise. */ var self = this; if (typeof self._cache.fileMode !== 'undefined') { @@ -117,6 +118,11 @@ TreeEntry.prototype.isFile = function(callback) { * @param {TreeEntry~isDirectoryCallback} callback */ TreeEntry.prototype.isDirectory = function(callback) { + /** + * @callback TreeEntry~isDirectoryCallback Callback executed after type is determined. + * @param {GitError|null} error An Error or null if successful. + * @param {Boolean|null} content True if the entry is a directory, false otherwise. + */ var self = this; if (typeof self._cache.fileMode !== 'undefined') { callback(null, fileModeIsDirectory(self._cache.fileMode, self)); @@ -133,9 +139,14 @@ TreeEntry.prototype.isDirectory = function(callback) { /** * Retrieve the name for this TreeEntry. * - * @param {Function} callback + * @param {TreeEntry~nameCallback} callback */ TreeEntry.prototype.name = function(callback) { + /** + * @callback TreeEntry~nameCallback Callback executed after name is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} name the entry's name. + */ this.rawEntry.name(function treeEntryName(error, name) { if (success(error, callback)) { callback(null, name); @@ -146,9 +157,14 @@ TreeEntry.prototype.name = function(callback) { /** * Retrieve the entry's root path. * - * @param {Function} callback + * @param {TreeEntry~rootCallback} callback */ TreeEntry.prototype.root = function(callback) { + /** + * @callback TreeEntry~rootCallback Callback executed after root path is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} root the entry's root path, relative to repository. + */ this.rawEntry.root(function treeEntryRoot(error, root) { if (success(error, callback)) { callback(null, root); @@ -159,9 +175,14 @@ TreeEntry.prototype.root = function(callback) { /** * Retrieve the path relative to the repository root for this TreeEntry. * - * @param {Function} callback + * @param {TreeEntry~pathCallback} callback */ TreeEntry.prototype.path = function(callback) { + /** + * @callback TreeEntry~pathCallback Callback executed after path is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} path the entry's full path relative to repository. + */ var self = this; self.root(function treeEntryRoot(error, root) { if (!success(error, callback)) { @@ -169,7 +190,7 @@ TreeEntry.prototype.path = function(callback) { } self.rawEntry.name(function treeEntryName(error, name) { if (success(error, callback)) { - callback(null, root + name); + callback(null, path.join(root, name)); } }); }); @@ -178,9 +199,14 @@ TreeEntry.prototype.path = function(callback) { /** * Retrieve the TreeEntry's content. * - * @param {Function} callback + * @param {TreeEntry~contentCallback} callback */ TreeEntry.prototype.content = function(callback) { + /** + * @callback TreeEntry~contentCallback Callback executed after content is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {String|null} content the entry's content. + */ this.toBlob(function convertBlob(error, blob) { if (!success(error, callback)) { return; @@ -196,9 +222,14 @@ TreeEntry.prototype.content = function(callback) { /** * Convert the TreeEntry to a blob. * - * @param {Function} callback + * @param {TreeEntry~blobCallback} callback */ TreeEntry.prototype.toBlob = function(callback) { + /** + * @callback TreeEntry~blobCallback Callback executed after blob is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {Blob|null} blob the blob representation of the entry. + */ var self = this; self.rawEntry.toBlob(self.rawRepo, function blobCallback(error, rawBlob) { if (success(error, callback)) { @@ -210,15 +241,20 @@ TreeEntry.prototype.toBlob = function(callback) { /** * Retrieve the TreeEntry's Tree. * - * @param {Function} callback + * @param {TreeEntry~treeCallback} callback */ TreeEntry.prototype.tree = function(callback) { + /** + * @callback TreeEntry~treeCallback Callback executed after tree is retrieved. + * @param {GitError|null} error An Error or null if successful. + * @param {Tree|null} tree the entry's tree. + */ var self = this; self.oid(function treeEntryOid(error, oid) { if (!success(error, callback)) { return; } - (new git.raw.Tree(self.rawRepo)).lookup(oid.getRawOid(), function(error, tree) { + (new git.tree(self.rawRepo)).lookup(oid, function(error, tree) { if (!success(error, callback)) { return; } From 628a944e831efd95d9adebfd85873da666b078bc Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 01:01:59 +1300 Subject: [PATCH 161/186] Removed object --- binding.gyp | 1 - include/blob.h | 1 + include/diff_list.h | 3 +- include/object.h | 95 -------------------- include/repo.h | 3 - include/tree_entry.h | 1 - lib/index.js | 1 - lib/object.js | 71 --------------- src/base.cc | 2 - src/object.cc | 201 ------------------------------------------- src/repo.cc | 1 - src/tree_entry.cc | 1 - test/raw-object.js | 38 -------- 13 files changed, 3 insertions(+), 416 deletions(-) delete mode 100755 include/object.h delete mode 100644 lib/object.js delete mode 100755 src/object.cc delete mode 100644 test/raw-object.js diff --git a/binding.gyp b/binding.gyp index 368d36b11..b683da9ea 100644 --- a/binding.gyp +++ b/binding.gyp @@ -7,7 +7,6 @@ 'src/blob.cc', 'src/commit.cc', 'src/error.cc', - 'src/object.cc', 'src/oid.cc', 'src/reference.cc', 'src/repo.cc', diff --git a/include/blob.h b/include/blob.h index 0afdb6c9a..f857d23e1 100755 --- a/include/blob.h +++ b/include/blob.h @@ -15,6 +15,7 @@ #include "git2.h" #include "repo.h" +#include "oid.h" using namespace v8; using namespace node; diff --git a/include/diff_list.h b/include/diff_list.h index 37b550d4c..58913866e 100644 --- a/include/diff_list.h +++ b/include/diff_list.h @@ -13,7 +13,8 @@ #include "git2.h" -#include "../include/repo.h" +#include "repo.h" +#include "oid.h" using namespace node; using namespace v8; diff --git a/include/object.h b/include/object.h deleted file mode 100755 index ff8f26bb9..000000000 --- a/include/object.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2013, Tim Branyen @tbranyen - * @author Michael Robinson @codeofinterest - * - * Dual licensed under the MIT and GPL licenses. - */ - -#ifndef OBJ_H -#define OBJ_H - -#include -#include - -#include "git2.h" - -#include "repo.h" -#include "oid.h" - -using namespace node; - -/** - * Class wrapper for libgit2 git_object - */ -class GitObject : public ObjectWrap { - public: - /** - * v8::FunctionTemplate used to create Node.js constructor - */ - static Persistent constructor_template; - - /** - * Used to intialize the EventEmitter from Node.js - * - * @param target v8::Object the Node.js module object - */ - static void Initialize(Handle target); - - /** - * Accessor for Object - * - * @return the internal git_object reference - */ - git_object* GetValue(); - - /** - * Mutator for Object - * - * @param obj a git_object object - */ - void SetValue(git_object* obj); - - const git_oid* Id(); - git_otype Type(); - - git_repository* Owner(); - const char* Type2String(git_otype type); - git_otype String2Type(const char* type); - int TypeIsLoose(git_otype type); - size_t Size(git_otype type); - - protected: - /** - * Constructor - */ - GitObject() {}; - - /** - * Deconstructor - */ - ~GitObject() {}; - - /** - * Mutator for GitObject - * - * @param args v8::Arguments function call arguments from Node.js - * - * @return v8::Object args.This() - */ - static Handle New(const Arguments& args); - static Handle Id(const Arguments& args); - static Handle Type(const Arguments& args); - static Handle Owner(const Arguments& args); - static Handle Type2String(const Arguments& args); - static Handle String2Type(const Arguments& args); - static Handle TypeIsLoose(const Arguments& args); - static Handle Size(const Arguments& args); - - private: - /** - * Internal reference to git_object object - */ - git_object* obj; -}; - -#endif diff --git a/include/repo.h b/include/repo.h index b0cea0ba4..55eb04d38 100755 --- a/include/repo.h +++ b/include/repo.h @@ -14,8 +14,6 @@ #include "git2.h" -#include "object.h" - using namespace node; using namespace v8; @@ -27,7 +25,6 @@ class GitRepo : public ObjectWrap { git_repository* GetValue(); void SetValue(git_repository* repo); - // Synchronous void Free(); protected: diff --git a/include/tree_entry.h b/include/tree_entry.h index 4b9f6629c..eb97ad6a6 100755 --- a/include/tree_entry.h +++ b/include/tree_entry.h @@ -17,7 +17,6 @@ #include "repo.h" #include "tree.h" #include "oid.h" -#include "object.h" using namespace v8; using namespace node; diff --git a/lib/index.js b/lib/index.js index b4856ff00..197f77abb 100755 --- a/lib/index.js +++ b/lib/index.js @@ -14,7 +14,6 @@ exports.blob = require('./blob.js').blob; exports.repo = require('./repo.js').repo; exports.signature = require('./signature.js').signature; 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; diff --git a/lib/object.js b/lib/object.js deleted file mode 100644 index 1c99d9fa7..000000000 --- a/lib/object.js +++ /dev/null @@ -1,71 +0,0 @@ -var git = require( '../' ); - -var _Object = function( obj ) { - var self = {}; - - if( object instanceof git.raw.Object ) { - self.object = obj; - } - else { - self.object = new git.raw.Object(); - } - - Object.defineProperty( self, 'id', { - get: function() { - }, - enumerable: true - }); - - Object.defineProperty( self, 'type', { - get: function() { - return self.object.type(); - }, - enumerable: true - }); - - Object.defineProperty( self, 'length', { - get: function() { - return self.object.size(); - }, - enumerable: true - }); - - Object.defineProperty( self, 'isLoose', { - get: function() { - return self.object.typeIsLoose(); - }, - enumerable: true - }); - - self.id = function() { - var oid = git.oid(); - - self.object.id( oid.oid ); - - return oid; - }; - - self.owner = function() { - var repo = git.repo(); - - self.object.owner( repo.repo ); - - return repo; - }; - - self.toString = function() { - return self.object.type2String(); - }; - - self.toType = function( type ) { - return self.object.toType( type ); - }; - - self.free = function() { - return self.object.free(); - }; - - return self; -}; - -exports.object = _Object; diff --git a/src/base.cc b/src/base.cc index a106d2228..725303bec 100755 --- a/src/base.cc +++ b/src/base.cc @@ -16,7 +16,6 @@ #include "../include/blob.h" #include "../include/repo.h" #include "../include/oid.h" -#include "../include/object.h" #include "../include/commit.h" #include "../include/revwalk.h" #include "../include/tree.h" @@ -33,7 +32,6 @@ extern "C" void init(Handle target) { GitSignature::Initialize(target); GitBlob::Initialize(target); GitOid::Initialize(target); - GitObject::Initialize(target); GitRepo::Initialize(target); GitCommit::Initialize(target); GitRevWalk::Initialize(target); diff --git a/src/object.cc b/src/object.cc deleted file mode 100755 index 6b1c43654..000000000 --- a/src/object.cc +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2013, Tim Branyen @tbranyen - * @author Michael Robinson @codeofinterest - * - * Dual licensed under the MIT and GPL licenses. - */ - -#include -#include - -#include "cvv8/v8-convert.hpp" -#include "git2.h" - -#include "../include/object.h" -#include "../include/repo.h" -#include "../include/oid.h" - -using namespace v8; -using namespace node; - -namespace cvv8 { - template <> - struct NativeToJS : NativeToJS {}; -} - -void GitObject::Initialize (Handle target) { - Local tpl = FunctionTemplate::New(New); - - tpl->InstanceTemplate()->SetInternalFieldCount(1); - tpl->SetClassName(String::NewSymbol("Object")); - - NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id); - NODE_SET_PROTOTYPE_METHOD(tpl, "type", Type); - NODE_SET_PROTOTYPE_METHOD(tpl, "owner", Owner); - NODE_SET_PROTOTYPE_METHOD(tpl, "type2String", Type2String); - NODE_SET_PROTOTYPE_METHOD(tpl, "string2Type", String2Type); - NODE_SET_PROTOTYPE_METHOD(tpl, "typeIsLoose", TypeIsLoose); - NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size); - - Local types = Object::New(); - - types->Set(String::New("GIT_OBJ_ANY"), cvv8::CastToJS(GIT_OBJ_ANY)); - types->Set(String::New("GIT_OBJ_BAD"), cvv8::CastToJS(GIT_OBJ_BAD)); - types->Set(String::New("GIT_OBJ__EXT1"), cvv8::CastToJS(GIT_OBJ__EXT1)); - types->Set(String::New("GIT_OBJ_COMMIT"), cvv8::CastToJS(GIT_OBJ_COMMIT)); - types->Set(String::New("GIT_OBJ_TREE"), cvv8::CastToJS(GIT_OBJ_TREE)); - types->Set(String::New("GIT_OBJ_BLOB"), cvv8::CastToJS(GIT_OBJ_BLOB)); - types->Set(String::New("GIT_OBJ_TAG"), cvv8::CastToJS(GIT_OBJ_TAG)); - types->Set(String::New("GIT_OBJ__EXT2"), cvv8::CastToJS(GIT_OBJ__EXT2)); - types->Set(String::New("GIT_OBJ_OFS_DELTA"), cvv8::CastToJS(GIT_OBJ_OFS_DELTA)); - types->Set(String::New("GIT_OBJ_REF_DELTA"), cvv8::CastToJS(GIT_OBJ_REF_DELTA)); - - tpl->Set(String::New("types"), types); - - constructor_template = Persistent::New(tpl->GetFunction()); - target->Set(String::NewSymbol("Object"), constructor_template); -} - -git_object* GitObject::GetValue() { - return this->obj; -} - -void GitObject::SetValue(git_object* obj) { - this->obj = obj; -} - -const git_oid* GitObject::Id() { - return git_object_id(this->obj); -} - -git_otype GitObject::Type() { - return git_object_type(this->obj); -} - -git_repository* GitObject::Owner() { - return git_object_owner(this->obj); -} - -const char* GitObject::Type2String(git_otype type) { - return git_object_type2string(type); -} - -git_otype GitObject::String2Type(const char* type) { - return git_object_string2type(type); -} - -int GitObject::TypeIsLoose(git_otype type) { - return git_object_typeisloose(type); -} - -size_t GitObject::Size(git_otype type) { - return git_object__size(type); -} - -Handle GitObject::New(const Arguments& args) { - HandleScope scope; - - GitObject *obj = new GitObject(); - - obj->Wrap(args.This()); - - return scope.Close( args.This() ); -} - -Handle GitObject::Id(const Arguments& args) { - HandleScope scope; - - GitObject *obj = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Oid is required and must be an Object."))); - } - - GitOid *oid = ObjectWrap::Unwrap(args[0]->ToObject()); - - oid->SetValue(*const_cast(obj->Id())); - - return scope.Close( Undefined() ); -} - -Handle GitObject::Type(const Arguments& args) { - HandleScope scope; - - GitObject *obj = ObjectWrap::Unwrap(args.This()); - - return scope.Close( Integer::New(obj->Type()) ); -} - -Handle GitObject::Owner(const Arguments& args) { - HandleScope scope; - - GitObject *obj = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); - } - - GitRepo *repo = ObjectWrap::Unwrap(args[0]->ToObject()); - - repo->SetValue(obj->Owner()); - - return scope.Close( Undefined() ); -} - -Handle GitObject::Type2String(const Arguments& args) { - HandleScope scope; - - GitObject *obj = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Type is required and must be a Number."))); - } - - git_otype type = (git_otype)args[0]->ToInteger()->Value(); - - return scope.Close( String::New(obj->Type2String(type)) ); -} - -Handle GitObject::String2Type(const Arguments& args) { - HandleScope scope; - - GitObject *obj = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsString()) { - return ThrowException(Exception::Error(String::New("Type is required and must be a String."))); - } - - String::Utf8Value type(args[0]); - - return scope.Close( Integer::New(obj->String2Type(*type)) ); -} - -Handle GitObject::TypeIsLoose(const Arguments& args) { - HandleScope scope; - - GitObject *obj = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Type is required and must be a Number."))); - } - - git_otype type = (git_otype)args[0]->ToInteger()->Value(); - - return scope.Close( Integer::New(obj->TypeIsLoose(type)) ); -} - -Handle GitObject::Size(const Arguments& args) { - HandleScope scope; - - GitObject *obj = ObjectWrap::Unwrap(args.This()); - - if(args.Length() == 0 || !args[0]->IsNumber()) { - return ThrowException(Exception::Error(String::New("Type is required and must be a Number."))); - } - - git_otype type = (git_otype)args[0]->ToInteger()->Value(); - - return scope.Close( Integer::New(obj->Size(type)) ); -} - -Persistent GitObject::constructor_template; diff --git a/src/repo.cc b/src/repo.cc index 1a31b4a3c..6644803a4 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -10,7 +10,6 @@ #include "git2.h" -#include "../include/object.h" #include "../include/repo.h" #include "../include/commit.h" #include "../include/error.h" diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 7d0220a14..78578cb4c 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -15,7 +15,6 @@ #include "../include/repo.h" #include "../include/blob.h" #include "../include/tree.h" -#include "../include/object.h" #include "../include/oid.h" #include "../include/tree_entry.h" #include "../include/error.h" diff --git a/test/raw-object.js b/test/raw-object.js deleted file mode 100644 index df9235a8b..000000000 --- a/test/raw-object.js +++ /dev/null @@ -1,38 +0,0 @@ -var git = require('../').raw, - rimraf = require('rimraf'); - -// Helper functions -var helper = { - // Test if obj is a true function - testFunction: function(test, obj, label) { - // The object reports itself as a function - test(typeof obj, 'function', label +' reports as a function.'); - // This ensures the repo is actually a derivative of the Function [[Class]] - test(toString.call(obj), '[object Function]', label +' [[Class]] is of type function.'); - }, - // Test code and handle exception thrown - testException: function(test, fun, label) { - try { - fun(); - test(false, label); - } - catch (ex) { - test(true, label); - } - } -}; - -var repo = new git.Repo(); - -// Obj -exports.constructor = function(test){ - test.expect(3); - - // Test for function - helper.testFunction(test.equals, git.Object, 'GitObject'); - - // Ensure we get an instance of Obj - test.ok(new git.Object() instanceof git.Object, 'Invocation returns an instance of GitObject'); - - test.done(); -}; From b025abae2ca0e3416b06b8b1be353e5baaeb7623 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 21:35:48 +1300 Subject: [PATCH 162/186] Whitespace --- test/convenience-commit.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index 0740deb35..b9de4cecb 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -230,7 +230,6 @@ exports.parents = function(test) { test.done(); }); }); - }); }); }; @@ -252,7 +251,6 @@ exports.tree = function(test) { commitTreeEntryCount++; }).on('end', function(error, entries) { test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected'); - test.done(); }); }); From 7ba0b8ac0ec7f9ca3afaa6b9cf17808ed1779469 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 21:35:59 +1300 Subject: [PATCH 163/186] Removed useless comment --- test/convenience-oid.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/convenience-oid.js b/test/convenience-oid.js index b900f56a9..91f359370 100644 --- a/test/convenience-oid.js +++ b/test/convenience-oid.js @@ -21,9 +21,6 @@ var helper = { } }; -/** - * Test that the commit object is present. - */ exports.method = function(test){ test.expect(2); helper.testFunction(test.equals, git.commit, 'Oid'); From e9d50fc68e544b14c35f898f8901de12c6ad7af1 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 21:36:13 +1300 Subject: [PATCH 164/186] Close async handles --- src/diff_list.cc | 4 ++++ src/tree.cc | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/diff_list.cc b/src/diff_list.cc index fcd90df9a..1ff3951d1 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -471,6 +471,10 @@ void GitDiffList::WalkWorkSendEnd(uv_async_t *handle, int status /*UNUSED*/) { WalkBaton *baton = static_cast(handle->data); uv_mutex_destroy(&baton->mutex); + uv_close((uv_handle_t*) &baton->asyncFile, NULL); + uv_close((uv_handle_t*) &baton->asyncHunk, NULL); + uv_close((uv_handle_t*) &baton->asyncData, NULL); + uv_close((uv_handle_t*) &baton->asyncEnd, NULL); Local argv[1]; if (baton->error) { diff --git a/src/tree.cc b/src/tree.cc index 3c21e05bf..915164e36 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -247,6 +247,8 @@ void GitTree::WalkWorkSendEnd(uv_async_t *handle, int status /*UNUSED*/) { WalkBaton *baton = static_cast(handle->data); uv_mutex_destroy(&baton->mutex); + uv_close((uv_handle_t*) &baton->asyncEnd, NULL); + uv_close((uv_handle_t*) &baton->asyncEntry, NULL); Local argv[1]; if (baton->error) { @@ -256,9 +258,7 @@ void GitTree::WalkWorkSendEnd(uv_async_t *handle, int status /*UNUSED*/) { } TryCatch try_catch; - baton->endCallback->Call(Context::GetCurrent()->Global(), 1, argv); - if (try_catch.HasCaught()) { node::FatalException(try_catch); } From 13cc948369b3cbfdfaaf5fb12da69bbc7cf2ecc8 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 21:56:39 +1300 Subject: [PATCH 165/186] Updated documentation --- lib/repo.js | 71 +++++++++++++++++++++++++++++++---------------- lib/tree_entry.js | 12 ++++---- lib/utilities.js | 36 ++++++++++++++---------- 3 files changed, 74 insertions(+), 45 deletions(-) diff --git a/lib/repo.js b/lib/repo.js index 36b2ee314..235745fad 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -1,6 +1,11 @@ var git = require('../'), success = require('./utilities').success; +/** + * Convenience repository class. + * + * @constructor + */ var Repo = function() { this.rawRepo = new git.raw.Repo(); }; @@ -8,13 +13,18 @@ var Repo = function() { /** * Open the git repository at directory. * - * @param {String} directory - * @param {Function} callback + * @example + * git.repo('/path/to/repository/.git', function(error, repo) { }); + * + * @param {String} directory The .git directory for the repository to open. + * @param {Repo~openCallback} callback */ Repo.prototype.open = function(directory, callback) { - if (typeof callback === 'undefined') { - throw new git.error('Callback is required and must be a Function'); - } + /** + * @callback Repo~openCallback Callback executed when repository is opened. + * @param {GitError|null} error An Error or null if successful. + * @param {Repo|null} repo Opened repository. + */ var self = this; self.rawRepo.open(directory, function openRepository(error, rawRepo) { if (success(error, callback)) { @@ -27,10 +37,15 @@ Repo.prototype.open = function(directory, callback) { /** * Look up a branch's most recent commit. * - * @param {String} name Branch name, e.g. 'master' - * @param {Function} callback + * @param {String} name Branch name, e.g. 'master' + * @param {Repo~branchCallback} callback */ Repo.prototype.branch = function(name, callback) { + /** + * @callback Repo~branchCallback Callback executed when the branch is checked out. + * @param {GitError|null} error An Error or null if successful. + * @param {Commit|null} repo HEAD commit for the branch. + */ var self = this; (new git.reference(self.rawRepo)).lookup('refs/heads/' + name, function referenceLookupCallback(error, reference) { if (!success(error, callback)) { @@ -51,11 +66,17 @@ Repo.prototype.branch = function(name, callback) { }; /** - * Retrieve the commit identified buy oid. - * @param {String|git.oid|git.raw.Oid} oid - * @param {Function} callback + * Retrieve the commit identified by oid. + * + * @param {String|Oid|git.raw.Oid} sha + * @param {Repo~commitCallback} callback */ Repo.prototype.commit = function(sha, callback) { + /** + * @callback Repo~commitCallback Callback executed when the commit is looked up. + * @param {GitError|null} error An Error or null if successful. + * @param {Commit|null} commit Commit represented by sha. + */ (new git.commit(this.rawRepo)).lookup(sha, function(error, commit) { if (success(error, callback)) { callback(null, commit); @@ -66,11 +87,16 @@ Repo.prototype.commit = function(sha, callback) { /** * Initialise a git repository at directory. * - * @param {String} directory - * @param {Boolean} isBare True if the repository is to be bare, false otherwise. - * @param {Function} callback + * @param {String} directory + * @param {Boolean} isBare True if the repository is to be bare, false otherwise. + * @param {Repo~initCallback} callback */ Repo.prototype.init = function(directory, isBare, callback) { + /** + * @callback Repo~initCallback Callback executed when repository is initialized. + * @param {GitError|null} error An Error or null if successful. + * @param {Repo|null} repo Initialized repository. + */ var self = this; self.rawRepo.init(directory, isBare, function(error, rawRepo) { if (success(error, callback)) { @@ -80,24 +106,21 @@ Repo.prototype.init = function(directory, isBare, callback) { }); }; -/** - * @todo necessary? - */ -Repo.prototype.free = function() { - this.rawRepo.free(); - delete self.repo; -}; - /** * Create a new Repo object. If directory is not provided, simply return it. * Otherwise open the repo asynchronously. * - * @param {String|null} directory The directory for the git repo to open. Null - * if one does not want to open a repo. - * @param {Function|null} callback + * @param {String|null} directory The directory for the git repo to open. Null + * if one does not want to open a repo. + * @param {repoCallback|null} callback * @return {Repo|null} The Repo if no directory is provided, else undefined. */ exports.repo = function(directory, callback) { + /** + * @callback repoCallback Callback executed if repository is opened. + * @param {GitError|null} error An Error or null if successful. + * @param {Repo|null} repo Opened repository. + */ var repo = new Repo(); if (typeof directory === 'undefined') { return repo; diff --git a/lib/tree_entry.js b/lib/tree_entry.js index f30653f21..a78de137b 100644 --- a/lib/tree_entry.js +++ b/lib/tree_entry.js @@ -39,12 +39,12 @@ var TreeEntry = function(rawRepo, rawTreeEntry) { * @enum {Integer} */ TreeEntry.prototype.fileModes = { - /** 0000000 */ GIT_FILEMODE_NEW: git.raw.TreeEntry.fileModes.GIT_FILEMODE_NEW, - /** 0040000 */ GIT_FILEMODE_TREE: git.raw.TreeEntry.fileModes.GIT_FILEMODE_TREE, - /** 0100644 */ GIT_FILEMODE_BLOB: git.raw.TreeEntry.fileModes.GIT_FILEMODE_BLOB, - /** 0100755 */ GIT_FILEMODE_BLOB_EXECUTABLE: git.raw.TreeEntry.fileModes.GIT_FILEMODE_BLOB_EXECUTABLE, - /** 0120000 */ GIT_FILEMODE_LINK: git.raw.TreeEntry.fileModes.GIT_FILEMODE_LINK, - /** 0160000 */ GIT_FILEMODE_COMMIT: git.raw.TreeEntry.fileModes.GIT_FILEMODE_COMMIT + /** 0 (0000000) */ GIT_FILEMODE_NEW: git.raw.TreeEntry.fileModes.GIT_FILEMODE_NEW, + /** 16384 (0040000) */ GIT_FILEMODE_TREE: git.raw.TreeEntry.fileModes.GIT_FILEMODE_TREE, + /** 33188 (0100644) */ GIT_FILEMODE_BLOB: git.raw.TreeEntry.fileModes.GIT_FILEMODE_BLOB, + /** 33261 (0100755) */ GIT_FILEMODE_BLOB_EXECUTABLE: git.raw.TreeEntry.fileModes.GIT_FILEMODE_BLOB_EXECUTABLE, + /** 40960 (0120000) */ GIT_FILEMODE_LINK: git.raw.TreeEntry.fileModes.GIT_FILEMODE_LINK, + /** 57344 (0160000) */ GIT_FILEMODE_COMMIT: git.raw.TreeEntry.fileModes.GIT_FILEMODE_COMMIT }; /** diff --git a/lib/utilities.js b/lib/utilities.js index e21d907fd..35c0fc493 100755 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -1,22 +1,28 @@ var git = require('../'); /** - * Check if error is null, if it is not, convert it to a GitError and call - * the callback. - * - * @param {Object} error - * @param {Function} callback - * - * @return {Boolean} True if the error was null, false otherwise. + * @namespace */ -exports.success = function(error, callback) { - if (error) { - if (error instanceof git.error) { - callback(error); - } else { - callback(new git.error(error.message, error.code)); +var utilities = { + /** + * Check if error is null, if it is not, convert it to a GitError and call + * the callback. + * + * @param {Object} error + * @param {Function} callback + * + * @return {Boolean} True if the error was null, false otherwise. + */ + success: function(error, callback) { + if (error) { + if (error instanceof git.error) { + callback(error); + } else { + callback(new git.error(error.message, error.code)); + } + return false; } - return false; + return true; } - return true; }; +exports = utilities; From 603d892cc78f0ed1ec3edcc4d1a75f956938da75 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 22:22:26 +1300 Subject: [PATCH 166/186] Updated utilities --- lib/utilities.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/utilities.js b/lib/utilities.js index 35c0fc493..f7d62b3c0 100755 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -14,6 +14,9 @@ var utilities = { * @return {Boolean} True if the error was null, false otherwise. */ success: function(error, callback) { + if (typeof callback !== 'function') { + throw new Error('Callback must be provided'); + } if (error) { if (error instanceof git.error) { callback(error); @@ -25,4 +28,4 @@ var utilities = { return true; } }; -exports = utilities; +exports.success = utilities.success; From 330cfb5e247eedee94ec699b89c54e029d96fddd Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Thu, 4 Apr 2013 22:22:39 +1300 Subject: [PATCH 167/186] Reverted removal of callback check in repo.open --- lib/repo.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/repo.js b/lib/repo.js index 235745fad..343af1dd4 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -25,6 +25,9 @@ Repo.prototype.open = function(directory, callback) { * @param {GitError|null} error An Error or null if successful. * @param {Repo|null} repo Opened repository. */ + if (typeof callback !== 'function') { + throw new git.error('Callback is required and must be a Function'); + } var self = this; self.rawRepo.open(directory, function openRepository(error, rawRepo) { if (success(error, callback)) { From fe54c8f6fcee303b53898a2b20e41a32fea0f5f5 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 00:37:19 +1300 Subject: [PATCH 168/186] Updated examples --- example/convenience-commit.js | 86 +++++++++++++++++++---------------- example/convenience-tree.js | 35 +++++++------- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/example/convenience-commit.js b/example/convenience-commit.js index 235e39d04..d117de5cd 100644 --- a/example/convenience-commit.js +++ b/example/convenience-commit.js @@ -1,43 +1,49 @@ -var git = require( '../' ); - -git.repo( '../.git', function( err, repo ) { - if( err ) { throw new Error( err ); } - - repo.commit( '59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function( err, commit ) { - if( err ) { throw new Error( err ); } - - var history = commit.history(); - history.on( 'commit', function() { - // console.log(arguments); - }); - - history.on( 'end', function( commits ) { - // Read first commit tree - var tree = commits[0].tree(); - - // Synchronous - tree.walk().on('entry', function( i, entry ) { - console.log( entry.content ); - return false; - }); - - // Asynchronous - not yet implemented - //tree.walk().on( 'entry', function( err, i, entry ) { - // console.log( entry ); - //}); +// Load in the module. +var git = require('nodegit'), + async = require('async'); + +// Open the repository in the current directory. +git.repo('.git', function(error, repository) { + if (error) { + throw error; + } + + // Use the master branch. + repository.branch('master', function(error, branch) { + if (error) { + throw error; + } + + // Iterate over the revision history. + branch.history().on('commit', function(error, commit) { + + // Print out `git log` emulation. + async.series([ + function(callback) { + commit.sha(callback); + }, + function(callback) { + commit.time(callback); + }, + function(callback) { + commit.author(function(error, author) { + author.name(callback); + }); + }, + function(callback) { + commit.author(function(error, author) { + author.email(callback); + }); + }, + function(callback) { + commit.message(callback); + } + ], function printCommit(error, results) { + console.log('SHA ' + results[0]); + console.log(new Date(results[1] * 1000)); + console.log(results[2] + ' <' + results[3] + '>'); + console.log(results[4]); + }); }); }); - - //repo.branch( 'master', function( err, branch ) { - // if( err ) { throw new Error( err ); } - - // var history = branch.history(); - // console.log( history ); - - // //branch.tree().each( function( i, entry ) { - // // console.log( entry.name ); - // // console.log( entry.contents ); - - // //}); - //}); }); diff --git a/example/convenience-tree.js b/example/convenience-tree.js index dbec82cc3..efe4cb928 100644 --- a/example/convenience-tree.js +++ b/example/convenience-tree.js @@ -1,24 +1,23 @@ -var git = require( '../' ); +// Load in the module. +var git = require('nodegit'); -git.repo( '../.git', function( err, repo ) { - if( err ) { throw err; } +// Open the repository in the current directory. +git.repo('.git', function(error, repository) { + if (error) throw error; - repo.branch( 'master', function( err, branch ) { - if( err ) { throw err; } + // Use the master branch. + repository.branch('master', function(error, branch) { + if (error) throw error; - branch.tree().walk().on('entry', function( idx, entry ) { - //console.log(entry.entry); - console.log( entry.name, entry.attributes ); - //console.log( entry.content ); + // Iterate over the revision history. + branch.tree(function(error, tree) { + console.log(tree); + if (error) throw error; + tree.walk().on('entry', function(error, entry) { + entry.name(function(error, name) { + console.log(name); + }); + }); }); - - //branch.tree().entry('example/raw-blob.js', function( entry ) { - // if( entry ) { - // console.log(entry.name); - // } - // else { - // console.log('not found'); - // } - //}); }); }); From b5f7bd12f8e6e30d74c9f63d79b94b69398114fa Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 01:02:45 +1300 Subject: [PATCH 169/186] Update README.md --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 30bd1cb9a..b56cbdc2c 100644 --- a/README.md +++ b/README.md @@ -202,14 +202,6 @@ Documentation Recent documentation may be found here: [`nodegit` documentation](http://tbranyen.github.com/nodegit/) -__`nodegit` native and library code is documented to be built with `Natural Docs`.__ - -To create the documentation, `cd` into the `nodegit` dir and run the following: - $ cd nodegit - $ make doc - -The documentation will then generate in the `doc/` subfolder as HTML. - Release information ------------------- From 45c9d2ca6719499e747ff84f4b1231fb95f4d04c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 01:08:11 +1300 Subject: [PATCH 170/186] Update README.md --- README.md | 159 ++++++++++++++++-------------------------------------- 1 file changed, 46 insertions(+), 113 deletions(-) diff --git a/README.md b/README.md index b56cbdc2c..383e938c9 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,11 @@ Robinson [@codeofinterest](http://twitter.com/codeofinterest), with help from [awesome contributors](https://github.com/tbranyen/nodegit/contributors)! +API Documentation +------------------------ + +Documentation may be found here: [`nodegit` documentation](http://tbranyen.github.com/nodegit/). + Contributing ------------ @@ -70,123 +75,56 @@ API Example Usage #### Convenience API #### ```JavaScript -var git = require("nodegit"); - -// Read a repository -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(error, branch) { - if (error) { throw error; } - - // 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(new Date(commit.time * 1000)); - console.log("\n"); - console.log(commit.message); - console.log("\n"); - }); - }); -}); -``` - -#### Raw API #### - -```` javascript -var git = require('nodegit').raw; - -// Create instance of Repo constructor -var repo = new git.Repo(); - -// Read a repository -repo.open('.git', function(err) { - // Err is an integer, success is 0, use strError for string representation - if (err) { - var error = new git.Error(); - throw error.strError(err); +// Load in the module. +var git = require('nodegit'), + async = require('async'); + +// Open the repository in the current directory. +git.repo('.git', function(error, repository) { + if (error) { + throw error; } - // Create instance of Ref constructor with this repository - var ref = new git.Ref(repo); - - // Find the master branch - repo.lookupRef(ref, '/refs/heads/master', function(err) { - if (err) { - var error = new git.Error(); - throw error.strError(err); + // Use the master branch. + repository.branch('master', function(error, branch) { + if (error) { + throw error; } - // Create instance of Commit constructor with this repository - var commit = new git.Commit(repo); - - // Create instance of Oid constructor - var oid = new git.Oid(); - - // Set the oid constructor internal reference to this branch reference - ref.oid(oid); - - // Lookup the commit for this oid - commit.lookup(oid, function(err) { - if (err) { - var error = new git.Error(); - throw error.strError(err); - } - - // Create instance of RevWalk constructor with this repository - var revwalk = new git.RevWalk(repo); - - // Push the commit as the start to walk - revwalk.push(commit); - - // Recursive walk - function walk() { - // Each revision walk iteration yields a commit - var revisionCommit = new git.Commit(repo); - - revwalk.next(revisionCommit, function(err) { - // Finish recursion once no more revision commits are left - if (err) { return; } - - // Create instance of Oid for sha - var oid = new git.Oid(); - - // Set oid to the revision commit - revisionCommit.id(oid); - - // Create instance of Sig for author - var author = new git.Sig(); - - // Set the author to the revision commit author - revisionCommit.author(author); - - // Convert timestamp to milliseconds and set new Date object - var time = new Date( revisionCommit.time() * 1000 ); - - // Print out `git log` emulation - console.log(oid.toString( 40 )); - console.log(author.name() + '<' + author.email() + '>'); - console.log(time); - console.log('\n'); - console.log(revisionCommit.message()); - console.log('\n'); + // Iterate over the revision history. + branch.history().on('commit', function(error, commit) { - // Recurse! - walk(); + // Print out `git log` emulation. + async.series([ + function(callback) { + commit.sha(callback); + }, + function(callback) { + commit.time(callback); + }, + function(callback) { + commit.author(function(error, author) { + author.name(callback); + }); + }, + function(callback) { + commit.author(function(error, author) { + author.email(callback); + }); + }, + function(callback) { + commit.message(callback); + } + ], function printCommit(error, results) { + console.log('SHA ' + results[0]); + console.log(new Date(results[1] * 1000)); + console.log(results[2] + ' <' + results[3] + '>'); + console.log(results[4]); }); - } - - // Initiate recursion - walk(): }); }); }); -```` +``` Running tests ------------- @@ -197,11 +135,6 @@ __To run unit tests ensure to update the submodules with `git submodule update - Then simply run `npm test` in the project root. -Documentation ------------------------- - -Recent documentation may be found here: [`nodegit` documentation](http://tbranyen.github.com/nodegit/) - Release information ------------------- From dd5a5a197cab886bfe32fda57325367885957743 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 18:56:34 +1300 Subject: [PATCH 171/186] Added date method to commit, resolves #62 --- lib/commit.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/commit.js b/lib/commit.js index 4a515f019..8939c7061 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -123,6 +123,24 @@ Commit.prototype.time = function(callback) { }); }; +/** + * Retrieve the commit time as a Date object. + * + * @param {Commit~dateCallback} callback + */ +Commit.prototype.date = function(callback) { + /** + * @callback Commit~dateCallback Callback executed on date retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Date|null} time Retrieved time as a Date object. + */ + this.time(function(error, time) { + if (success(error, callback)) { + callback(null, new Date(time * 1000)); + } + }); +}; + /** * Retrieve the commit's positive or negative timezone offset, in minutes from UTC. * From 6f491b18c408b1771efcbeb5fd7349697b16bb2a Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 18:56:44 +1300 Subject: [PATCH 172/186] Updated convenience commit example --- example/convenience-commit.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/example/convenience-commit.js b/example/convenience-commit.js index d117de5cd..1e2320a85 100644 --- a/example/convenience-commit.js +++ b/example/convenience-commit.js @@ -1,29 +1,27 @@ // Load in the module. var git = require('nodegit'), - async = require('async'); + async = require('async'); // Open the repository in the current directory. git.repo('.git', function(error, repository) { - if (error) { - throw error; - } + if (error) throw error; - // Use the master branch. + // Use the master branch (a branch is the HEAD commit) repository.branch('master', function(error, branch) { - if (error) { - throw error; - } + if (error) throw error; - // Iterate over the revision history. - branch.history().on('commit', function(error, commit) { + // History returns an event, and begins walking the history + var history = branch.history(); + // History emits 'commit' event for each commit in the branch's history + history.on('commit', function(error, commit) { // Print out `git log` emulation. async.series([ function(callback) { commit.sha(callback); }, function(callback) { - commit.time(callback); + commit.date(callback); }, function(callback) { commit.author(function(error, author) { @@ -39,8 +37,9 @@ git.repo('.git', function(error, repository) { commit.message(callback); } ], function printCommit(error, results) { + if (error) throw error; console.log('SHA ' + results[0]); - console.log(new Date(results[1] * 1000)); + console.log(results[1] * 1000); console.log(results[2] + ' <' + results[3] + '>'); console.log(results[4]); }); From 650019f9754a7b433f864f2552c05309bcf129c7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 19:00:45 +1300 Subject: [PATCH 173/186] Added commit date tests --- test/convenience-commit.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index b9de4cecb..a3292a65e 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -76,6 +76,21 @@ exports.time = function(test) { }); }; +exports.date = function(test) { + test.expect(4); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.date(function(error, date) { + test.equals(error, null, 'There should be no error'); + test.notEqual(date, null, 'Date should not be null'); + test.equal(date instanceof Date, true, 'Date should be a date object'); + test.equals(date.getTime(), 1362012884000, 'Date should match expected value'); + test.done(); + }); + }); + }); +}; + exports.offset = function(test) { test.expect(3); git.repo('../.git', function(error, repository) { From a134965775c4cf52b1ed42e42fc85165ee9e99b7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 19:08:48 +1300 Subject: [PATCH 174/186] Updated Commit documentation . Resolves #63 --- lib/commit.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 8939c7061..0092ebc64 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -180,7 +180,7 @@ Commit.prototype.author = function(callback) { /** * Retrieve the commit's committer. * - * @param {Commit~committerCalback} callback + * @param {Commit~committerCallback} callback */ Commit.prototype.committer = function(callback) { /** @@ -240,7 +240,9 @@ Commit.prototype.file = function(path, callback) { }; /** - * Walk the history of this commit. + * Walk the history from this commit backwards. + * An EventEmitter is returned that will emit a 'commit' event for each + * commit in the history, and one 'end' event when the walk is completed. * * @fires Commit#commit * @fires Commit#end @@ -292,9 +294,14 @@ Commit.prototype.history = function() { /** * Retrieve the commit's parents. * - * @param {Function} callback + * @param {Commit~parentsCallback} callback */ Commit.prototype.parents = function(callback) { + /** + * @callback Commit~parentsCallback Callback executed on parents retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Commit[]|null} parents Commit's parent(s). + */ var self = this; self.rawCommit.parents(function processParent(error, rawParents) { if (success(error, callback)) { @@ -308,11 +315,17 @@ Commit.prototype.parents = function(callback) { }; /** - * Get a diff tree showing changes between this commit and its parent(s). + * Generate an array of diff trees showing changes between this commit + * and its parent(s). * - * @param {Function} callback + * @param {Commit~parentsDiffTreesCallback} callback */ Commit.prototype.parentsDiffTrees = function(callback) { + /** + * @callback Commit~parentsDiffTreesCallback Callback executed on diff trees retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {DiffList[]|null} diffLists Array of DiffTrees showing changes between this commit and its parent(s) + */ var self = this; self.sha(function(error, commitSha) { if (!success(error, callback)) { From 4b10496a8348b913a77871ffc43342ef5cbf8ac2 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 23:08:41 +1300 Subject: [PATCH 175/186] Convert time to milliseconds before passing it to the callback in commit.time. Closes #62 --- lib/commit.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/commit.js b/lib/commit.js index 0092ebc64..ea4fab3ef 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -106,7 +106,7 @@ Commit.prototype.message = function(callback) { }; /** - * Retrieve the commit time as a unix timestamp in seconds. + * Retrieve the commit time as a unix timestamp. * * @param {Commit~timeCallback} callback */ @@ -118,7 +118,8 @@ Commit.prototype.time = function(callback) { */ this.rawCommit.time(function(error, time) { if (success(error, callback)) { - callback(null, time); + // git_commit_time returns timestamp in s, converting to ms here + callback(null, time * 1000); } }); }; @@ -136,7 +137,7 @@ Commit.prototype.date = function(callback) { */ this.time(function(error, time) { if (success(error, callback)) { - callback(null, new Date(time * 1000)); + callback(null, new Date(time)); } }); }; From 2bb2290a9bfdad7e7f028acd8e62624bc92be3b0 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 23:09:01 +1300 Subject: [PATCH 176/186] Normalised diff_list.js --- lib/diff_list.js | 133 +++++++++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 55 deletions(-) diff --git a/lib/diff_list.js b/lib/diff_list.js index caf1a055b..6e57333d4 100644 --- a/lib/diff_list.js +++ b/lib/diff_list.js @@ -1,67 +1,90 @@ var git = require('../'), events = require('events'); -var GitDiffList = function(rawRepo, rawDiffList) { - var self = { - repo: rawRepo, - diffList: rawDiffList || new git.raw.DiffList() - }; +/** + * Convenience diff list class. + * + * @param {git.raw.Repo} rawRepo + * @param {[type]} rawDiffList [description] + */ +var DiffList = function(rawRepo, rawDiffList) { + if (!(rawRepo instanceof git.raw.Repo)) { + throw new git.error('First parameter for DiffList must be a raw repo'); + } + this.rawRepo = rawRepo; - self.walk = function() { - var event = new events.EventEmitter(), - allFileDeltas = []; + if (rawDiffList instanceof git.raw.DiffList) { + this.rawDiffList = rawDiffList; + } else { + this.rawDiffList = new git.raw.DiffList(); + } +}; - process.nextTick(function() { - self.diffList.walk(function fileCallback(error, fileDeltas) { - if (error) { - event.emit('end', error, null); - } - fileDeltas.forEach(function(fileDelta) { - event.emit('file', null, fileDelta); - allFileDeltas.push(fileDelta); - }); - }, function hunkCallback(error, diffHunk) { - // @todo implement? - }, function lineCallback(error, diffLine) { - // @todo implement? - }, function endCallback(error) { - event.emit('end', error, allFileDeltas); - }); - }); +/** + * Refer to vendor/libgit2/include/git2/diff.h for delta type definitions. + * + * @readonly + * @enum {Integer} + */ +DiffList.prototype.deltaTypes = { + /** 0 */ GIT_DELTA_UNMODIFIED: git.raw.DiffList.deltaTypes.GIT_DELTA_UNMODIFIED, + /** 1 */ GIT_DELTA_ADDED: git.raw.DiffList.deltaTypes.GIT_DELTA_ADDED, + /** 2 */ GIT_DELTA_DELETED: git.raw.DiffList.deltaTypes.GIT_DELTA_DELETED, + /** 3 */ GIT_DELTA_MODIFIED: git.raw.DiffList.deltaTypes.GIT_DELTA_MODIFIED, + /** 4 */ GIT_DELTA_RENAMED: git.raw.DiffList.deltaTypes.GIT_DELTA_RENAMED, + /** 5 */ GIT_DELTA_COPIED: git.raw.DiffList.deltaTypes.GIT_DELTA_COPIED, + /** 6 */ GIT_DELTA_IGNORED: git.raw.DiffList.deltaTypes.GIT_DELTA_IGNORED, + /** 7 */ GIT_DELTA_UNTRACKED: git.raw.DiffList.deltaTypes.GIT_DELTA_UNTRACKED, + /** 8 */ GIT_DELTA_TYPECHANGE: git.raw.DiffList.deltaTypes.GIT_DELTA_TYPECHANGE +}; - return event; - }; +/** + * Refer to vendor/libgit2/include/git2/diff.h for line origin type definitions. + * + * @readOnly + * @enum {String} + */ +DiffList.prototype.lineOriginTypes = { + /** ' ' */ GIT_DIFF_LINE_CONTEXT: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, + /** '+' */ GIT_DIFF_LINE_ADDITION: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, + /** '-' */ GIT_DIFF_LINE_DELETION: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, + /** '\n' */ GIT_DIFF_LINE_ADD_EOFNL: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_ADD_EOFNL, + /** '' */ GIT_DIFF_LINE_DEL_EOFNL: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_DEL_EOFNL, + /** 'F' */ GIT_DIFF_LINE_FILE_HDR: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_FILE_HDR, + /** 'H' */ GIT_DIFF_LINE_HUNK_HDR: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_HUNK_HDR, + /** 'B' */ GIT_DIFF_LINE_BINARY: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_BINARY +}; - self.treeToTree = function(oldSha, newSha, callback) { - self.diffList.treeToTree(self.repo, oldSha, newSha, function(error, rawDifflist) { - if (error) { - callback(error, null); - return; - } - self.diffList = rawDifflist; - callback(null, self); +DiffList.prototype.walk = function() { + var event = new events.EventEmitter(), + allFileDeltas = [], + self = this; + + self.rawDiffList.walk(function fileCallback(error, fileDeltas) { + if (error) { + event.emit('end', new git.error(error.message, error.code), null); + } + fileDeltas.forEach(function(fileDelta) { + event.emit('file', null, fileDelta); + allFileDeltas.push(fileDelta); }); - }; - - /** - * Add libgit2 delta types to git.diffList object. - * - * Refer to vendor/libgit2/include/git2/diff.h for definitions. - */ - for (var deltaType in git.raw.DiffList.deltaTypes) { - self[deltaType] = git.raw.DiffList.deltaTypes[deltaType]; - } + }, function endCallback(error) { + event.emit('end', error ? new git.error(error.message, error.code) : null, allFileDeltas); + }); - /** - * Add libgit2 line origin types to git.diffList object. - * - * Refer to vendor/libgit2/include/git2/diff.h for definitions. - */ - for (var lineOriginType in git.raw.DiffList.lineOriginTypes) { - self[lineOriginType] = git.raw.DiffList.lineOriginTypes[lineOriginType]; - } + return event; +}; - return self; +DiffList.prototype.treeToTree = function(oldSha, newSha, callback) { + var self = this; + self.rawDiffList.treeToTree(self.rawRepo, oldSha, newSha, function(error, rawDifflist) { + if (error) { + callback(new git.error(error.message, error.code), null); + return; + } + self.rawDiffList = rawDifflist; + callback(null, self); + }); }; -exports.diffList = GitDiffList; +exports.diffList = DiffList; From c7293606f201545d86086a06910b9e2d3f2b605c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 23:35:36 +1300 Subject: [PATCH 177/186] Added convenience-difflist tests --- test/convenience-difflist.js | 106 +++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/convenience-difflist.js diff --git a/test/convenience-difflist.js b/test/convenience-difflist.js new file mode 100644 index 000000000..24f5c8f9f --- /dev/null +++ b/test/convenience-difflist.js @@ -0,0 +1,106 @@ +var git = require('../'), + rimraf = require('rimraf'), + fs = require( 'fs' ); + +var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; + +// Helper functions +var helper = { + // Test if obj is a true function + testFunction: function(test, obj, label) { + // The object reports itself as a function + test(typeof obj, 'function', label + ' reports as a function.'); + // This ensures the repo is actually a derivative of the Function [[Class]] + test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.'); + }, + // Test code and handle exception thrown + testException: function(test, fun, label) { + try { + fun(); + test(false, label); + } + catch (ex) { + test(true, label); + } + } +}; + +/** + * Test that the commit object is present. + */ +exports.method = function(test){ + test.expect(2); + helper.testFunction(test.equals, git.diffList, 'DiffList'); + test.done(); +}; + +/** + * Test that retreiving parent works as expected. + * + * @param {Object} test + */ +exports.walking = function(test) { + test.expect(16); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.parents(function(error, parents) { + test.equals(parents.length, 1, 'Commit should have exactly one parent'); + parents[0].sha(function(error, parentSha) { + (new git.diffList(commit.rawRepo)).treeToTree(parentSha, historyCountKnownSHA, function(error, diffList) { + test.equal(null, error, 'Should not error'); + diffList.walk().on('file', function(error, diff) { + test.equal(null, error, 'Should not error'); + test.equal(diff.oldFile.path, 'README.md', 'Old file path should match expected'); + test.equal(diff.newFile.path, 'README.md', 'New file path should match expected'); + test.equal(diff.content.length, 5, 'Content array should be of known length'); + test.equal(diff.status, diffList.deltaTypes.GIT_DELTA_MODIFIED, 'Status should be known type'); + test.equal(diff.content[0].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'First content item should be context'); + test.equal(diff.content[1].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Second content item should be context'); + test.equal(diff.content[2].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Third content item should be context'); + + var oldContent = '__Before submitting a pull request, please ensure both unit tests and lint checks pass.__\n'; + test.equal(diff.content[3].content, oldContent, 'Old content should match known value'); + test.equal(diff.content[3].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, 'Fourth content item should be deletion'); + test.equal(diff.content[3].contentLength, 90, 'Fourth content length should match known value'); + + var newContent = '__Before submitting a pull request, please ensure both that you\'ve added unit tests to cover your shiny new code, and that all unit tests and lint checks pass.__\n'; + test.equal(diff.content[4].content, newContent, 'New content should match known value'); + test.equal(diff.content[4].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, 'Fifth content item should be addition'); + test.equal(diff.content[4].contentLength, 162, 'Fifth content length should match known value'); + test.done(); + }); + }); + }); + }); + }); + }); +}; + +exports.deltaTypes = function(test) { + test.expect(9); + var diffList = new git.diffList((new git.repo()).rawRepo); + test.equal(diffList.deltaTypes.GIT_DELTA_UNMODIFIED, git.raw.DiffList.deltaTypes.GIT_DELTA_UNMODIFIED, 'GIT_DELTA_UNMODIFIED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_ADDED, git.raw.DiffList.deltaTypes.GIT_DELTA_ADDED, 'GIT_DELTA_ADDED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_DELETED, git.raw.DiffList.deltaTypes.GIT_DELTA_DELETED, 'GIT_DELTA_DELETED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_MODIFIED, git.raw.DiffList.deltaTypes.GIT_DELTA_MODIFIED, 'GIT_DELTA_MODIFIED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_RENAMED, git.raw.DiffList.deltaTypes.GIT_DELTA_RENAMED, 'GIT_DELTA_RENAMED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_COPIED, git.raw.DiffList.deltaTypes.GIT_DELTA_COPIED, 'GIT_DELTA_COPIED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_IGNORED, git.raw.DiffList.deltaTypes.GIT_DELTA_IGNORED, 'GIT_DELTA_IGNORED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_UNTRACKED, git.raw.DiffList.deltaTypes.GIT_DELTA_UNTRACKED, 'GIT_DELTA_UNTRACKED delta type should match expected value'); + test.equal(diffList.deltaTypes.GIT_DELTA_TYPECHANGE, git.raw.DiffList.deltaTypes.GIT_DELTA_TYPECHANGE, 'GIT_DELTA_TYPECHANGE delta type should match expected value'); + test.done(); +}; + +exports.lineOriginTypes = function(test) { + test.expect(8); + var diffList = new git.diffList((new git.repo()).rawRepo); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'GIT_DIFF_LINE_CONTEXT line origin type should match expected value'); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, 'GIT_DIFF_LINE_ADDITION line origin type should match expected value'); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, 'GIT_DIFF_LINE_DELETION line origin type should match expected value'); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_ADD_EOFNL, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_ADD_EOFNL, 'GIT_DIFF_LINE_ADD_EOFNL line origin type should match expected value'); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_DEL_EOFNL, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_DEL_EOFNL, 'GIT_DIFF_LINE_DEL_EOFNL line origin type should match expected value'); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_FILE_HDR, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_FILE_HDR, 'GIT_DIFF_LINE_FILE_HDR line origin type should match expected value'); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_HUNK_HDR, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_HUNK_HDR, 'GIT_DIFF_LINE_HUNK_HDR line origin type should match expected value'); + test.equal(diffList.lineOriginTypes.GIT_DIFF_LINE_BINARY, git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_BINARY, 'GIT_DIFF_LINE_BINARY line origin type should match expected value'); + test.done(); +}; From 4dd76f233458111ce9214ef3b67717664f028632 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 23:35:52 +1300 Subject: [PATCH 178/186] Re-added todo diff list walk callbacks --- lib/diff_list.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/diff_list.js b/lib/diff_list.js index 6e57333d4..1953c86e3 100644 --- a/lib/diff_list.js +++ b/lib/diff_list.js @@ -68,6 +68,10 @@ DiffList.prototype.walk = function() { event.emit('file', null, fileDelta); allFileDeltas.push(fileDelta); }); + }, function hunkCallback(error, diffHunk) { + /** TO BE IMPLEMENTED */ + }, function lineCallback(error, diffLine) { + /** TO BE IMPLEMENTED */ }, function endCallback(error) { event.emit('end', error ? new git.error(error.message, error.code) : null, allFileDeltas); }); From ff2f3dac001c25138a1c6394532f23eafd9f5a22 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Fri, 5 Apr 2013 23:36:06 +1300 Subject: [PATCH 179/186] Updated convenience-commit time & date test --- test/convenience-commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/convenience-commit.js b/test/convenience-commit.js index a3292a65e..663ffe99d 100644 --- a/test/convenience-commit.js +++ b/test/convenience-commit.js @@ -69,7 +69,7 @@ exports.time = function(test) { commit.time(function(error, time) { test.equals(error, null, 'There should be no error'); test.notEqual(time, null, 'Time should not be null'); - test.equals(time, 1362012884, 'Time should match expected value'); + test.equals(time, 1362012884000, 'Time should match expected value'); test.done(); }); }); From edae9e0b6504f49b22593f31e25ad9b677e22de7 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 6 Apr 2013 00:21:31 +1300 Subject: [PATCH 180/186] Updated commit documentation --- lib/commit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commit.js b/lib/commit.js index ea4fab3ef..75f2fc18e 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -248,7 +248,7 @@ Commit.prototype.file = function(path, callback) { * @fires Commit#commit * @fires Commit#end * - * @return {EventEmitter} Event + * @return {EventEmitter} historyWalkEmitter */ Commit.prototype.history = function() { var event = new events.EventEmitter(), From 50712bfc51636d51ce4851e6a770a9fe4d240698 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 6 Apr 2013 00:22:01 +1300 Subject: [PATCH 181/186] Added diff walk end test --- test/convenience-difflist.js | 54 ++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/test/convenience-difflist.js b/test/convenience-difflist.js index 24f5c8f9f..77b6bb9ed 100644 --- a/test/convenience-difflist.js +++ b/test/convenience-difflist.js @@ -39,34 +39,54 @@ exports.method = function(test){ * * @param {Object} test */ -exports.walking = function(test) { - test.expect(16); +exports.walkingDiffs = function(test) { + test.expect(15); git.repo('../.git', function(error, repository) { repository.commit(historyCountKnownSHA, function(error, commit) { commit.parents(function(error, parents) { - test.equals(parents.length, 1, 'Commit should have exactly one parent'); parents[0].sha(function(error, parentSha) { (new git.diffList(commit.rawRepo)).treeToTree(parentSha, historyCountKnownSHA, function(error, diffList) { test.equal(null, error, 'Should not error'); - diffList.walk().on('file', function(error, diff) { + diffList.walk().on('delta', function(error, delta) { + console.log(delta.content[0].range); + process.exit(); test.equal(null, error, 'Should not error'); - test.equal(diff.oldFile.path, 'README.md', 'Old file path should match expected'); - test.equal(diff.newFile.path, 'README.md', 'New file path should match expected'); - test.equal(diff.content.length, 5, 'Content array should be of known length'); - test.equal(diff.status, diffList.deltaTypes.GIT_DELTA_MODIFIED, 'Status should be known type'); - test.equal(diff.content[0].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'First content item should be context'); - test.equal(diff.content[1].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Second content item should be context'); - test.equal(diff.content[2].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Third content item should be context'); + test.equal(delta.oldFile.path, 'README.md', 'Old file path should match expected'); + test.equal(delta.newFile.path, 'README.md', 'New file path should match expected'); + test.equal(delta.content.length, 5, 'Content array should be of known length'); + test.equal(delta.status, diffList.deltaTypes.GIT_DELTA_MODIFIED, 'Status should be known type'); + test.equal(delta.content[0].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'First content item should be context'); + test.equal(delta.content[1].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Second content item should be context'); + test.equal(delta.content[2].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_CONTEXT, 'Third content item should be context'); var oldContent = '__Before submitting a pull request, please ensure both unit tests and lint checks pass.__\n'; - test.equal(diff.content[3].content, oldContent, 'Old content should match known value'); - test.equal(diff.content[3].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, 'Fourth content item should be deletion'); - test.equal(diff.content[3].contentLength, 90, 'Fourth content length should match known value'); + test.equal(delta.content[3].content, oldContent, 'Old content should match known value'); + test.equal(delta.content[3].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_DELETION, 'Fourth content item should be deletion'); + test.equal(delta.content[3].contentLength, 90, 'Fourth content length should match known value'); var newContent = '__Before submitting a pull request, please ensure both that you\'ve added unit tests to cover your shiny new code, and that all unit tests and lint checks pass.__\n'; - test.equal(diff.content[4].content, newContent, 'New content should match known value'); - test.equal(diff.content[4].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, 'Fifth content item should be addition'); - test.equal(diff.content[4].contentLength, 162, 'Fifth content length should match known value'); + test.equal(delta.content[4].content, newContent, 'New content should match known value'); + test.equal(delta.content[4].lineOrigin, diffList.lineOriginTypes.GIT_DIFF_LINE_ADDITION, 'Fifth content item should be addition'); + test.equal(delta.content[4].contentLength, 162, 'Fifth content length should match known value'); + test.done(); + }); + }); + }); + }); + }); + }); +}; + +exports.walkingEnd = function(test) { + test.expect(2); + git.repo('../.git', function(error, repository) { + repository.commit(historyCountKnownSHA, function(error, commit) { + commit.parents(function(error, parents) { + parents[0].sha(function(error, parentSha) { + (new git.diffList(commit.rawRepo)).treeToTree(parentSha, historyCountKnownSHA, function(error, diffList) { + diffList.walk().on('end', function(error, diffs) { + test.equal(null, error, 'Should not error'); + test.equal(diffs.length, 1, 'Diffs array should be of known length'); test.done(); }); }); From 6f83d7dc7f8f4556cfe22aadda78b0414cc6d32c Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 6 Apr 2013 00:44:49 +1300 Subject: [PATCH 182/186] Removed console log --- test/convenience-difflist.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/convenience-difflist.js b/test/convenience-difflist.js index 77b6bb9ed..c010691c1 100644 --- a/test/convenience-difflist.js +++ b/test/convenience-difflist.js @@ -48,8 +48,6 @@ exports.walkingDiffs = function(test) { (new git.diffList(commit.rawRepo)).treeToTree(parentSha, historyCountKnownSHA, function(error, diffList) { test.equal(null, error, 'Should not error'); diffList.walk().on('delta', function(error, delta) { - console.log(delta.content[0].range); - process.exit(); test.equal(null, error, 'Should not error'); test.equal(delta.oldFile.path, 'README.md', 'Old file path should match expected'); test.equal(delta.newFile.path, 'README.md', 'New file path should match expected'); From df83cc8a22987ee4df10ccce2138adbf010ca80b Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 6 Apr 2013 00:46:27 +1300 Subject: [PATCH 183/186] Added FileDelta object documentation --- lib/diff_list.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/lib/diff_list.js b/lib/diff_list.js index 1953c86e3..56a269314 100644 --- a/lib/diff_list.js +++ b/lib/diff_list.js @@ -3,9 +3,10 @@ var git = require('../'), /** * Convenience diff list class. - * + * + * @constructor * @param {git.raw.Repo} rawRepo - * @param {[type]} rawDiffList [description] + * @param {git.raw.DiffList} [rawDiffList = new git.raw.DiffList] */ var DiffList = function(rawRepo, rawDiffList) { if (!(rawRepo instanceof git.raw.Repo)) { @@ -55,6 +56,14 @@ DiffList.prototype.lineOriginTypes = { /** 'B' */ GIT_DIFF_LINE_BINARY: git.raw.DiffList.lineOriginTypes.GIT_DIFF_LINE_BINARY }; +/** + * Walk the current diff list tree. + * + * @fires DiffList#delta + * @fires DiffList#end + * + * @return {EventEmitter} diffListWalkEmitter + */ DiffList.prototype.walk = function() { var event = new events.EventEmitter(), allFileDeltas = [], @@ -65,7 +74,15 @@ DiffList.prototype.walk = function() { event.emit('end', new git.error(error.message, error.code), null); } fileDeltas.forEach(function(fileDelta) { - event.emit('file', null, fileDelta); + /** + * Delta event. + * + * @event DiffList#delta + * + * @param {GitError|null} error An error object if there was an issue, null otherwise. + * @param {FileDelta} fileDelta The file delta object. + */ + event.emit('delta', null, fileDelta); allFileDeltas.push(fileDelta); }); }, function hunkCallback(error, diffHunk) { @@ -73,6 +90,14 @@ DiffList.prototype.walk = function() { }, function lineCallback(error, diffLine) { /** TO BE IMPLEMENTED */ }, function endCallback(error) { + /** + * End event. + * + * @event DiffList#end + * + * @param {GitError|null} error An error object if there was an issue, null otherwise. + * @param {FileDelta[]} fileDeltas The file delta objects. + */ event.emit('end', error ? new git.error(error.message, error.code) : null, allFileDeltas); }); @@ -92,3 +117,49 @@ DiffList.prototype.treeToTree = function(oldSha, newSha, callback) { }; exports.diffList = DiffList; + +/** + * @namespace + * @property {Object} oldFile Contains details for the old file state + * @property {String} oldFile.path The path to the old file, relative to the repository + * @property {Object} newFile Contains details for the new file state + * @property {String} newFile.path The path to the new file, relative to the repository + * @property {Object[]} content Array of context & differences + * @property {Object} content[].range + * @property {Object} content[].range.old + * @property {Integer} content[].range.old.start + * @property {Integer} content[].range.old.lines + * @property {Object} content[].range.new + * @property {Integer} content[].range.new.start + * @property {Integer} content[].range.new.lines + * @property {Object} content[].content Content of the delta + * @property {DiffList.lineOriginTypes} content[].lineOrigin + * @property {Integer} content[].contentLength + * @property {Integer} status Type of delta + */ +var FileDelta = { + oldFile: { + path: String + }, + newFile: { + path: String + }, + content: [ + { + range: { + old: { + start: Number, + lines: Number + }, + 'new': { + start: Number, + lines: Number + } + }, + content: String, + lineOrigin: String, + contentLength: Number + } + ], + status: Number +}; From 1825d63ffb07d663a31ea454d128c22a045b1971 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 6 Apr 2013 00:52:15 +1300 Subject: [PATCH 184/186] Updated reference documentation --- lib/reference.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/reference.js b/lib/reference.js index 9d0c18069..51e7d5a2f 100644 --- a/lib/reference.js +++ b/lib/reference.js @@ -6,7 +6,7 @@ var git = require('../'), * * @constructor * @param {git.raw.Repo} rawRepo - * @param {git.raw.Reference|null} rawReference + * @param {git.raw.Reference} [rawReference = new git.raw.Reference()] */ var Reference = function(rawRepo, rawReference) { if (!(rawRepo instanceof git.raw.Repo)) { @@ -24,10 +24,15 @@ var Reference = function(rawRepo, rawReference) { /** * Lookup the reference with the given name. * - * @param {String} name - * @param {Function} callback + * @param {String} name + * @param {Reference~lookupCallback} callback */ Reference.prototype.lookup = function(name, callback) { + /** + * @callback Reference~lookupCallback Callback executed on lookup completion. + * @param {GitError|null} error An Error or null if successful. + * @param {Reference|null} reference Retrieved reference object or null. + */ var self = this; self.rawReference.lookup(self.rawRepo, name, function referenceLookup(error, rawReference) { if (!success(error, callback)) { @@ -41,9 +46,14 @@ Reference.prototype.lookup = function(name, callback) { /** * Get the Oid representing this reference. * - * @param {Function} callback + * @param {Reference~oidCallback} callback */ Reference.prototype.oid = function(callback) { + /** + * @callback Reference~oidCallback Callback executed on oid retrieval. + * @param {GitError|null} error An Error or null if successful. + * @param {Oid|null} oid Retrieved Oid object or null. + */ this.rawReference.oid(function referenceOid(error, rawOid) { if (success(error, callback)) { callback(null, new git.oid(rawOid)); From ca583c61f327c84a4a12d855005a643e364ca56f Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 6 Apr 2013 01:03:36 +1300 Subject: [PATCH 185/186] Changed way char is converted to string for JS --- src/diff_list.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/diff_list.cc b/src/diff_list.cc index 1ff3951d1..1204f6399 100755 --- a/src/diff_list.cc +++ b/src/diff_list.cc @@ -435,8 +435,12 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) { content->Set(String::New("range"), range); content->Set(String::New("content"), String::New(rawContent->content.c_str())); + // char lineOrigin[2]; + // strncpy(lineOrigin, &rawContent->lineOrigin, 1); char lineOrigin[2]; - strncpy(lineOrigin, &rawContent->lineOrigin, 1); + lineOrigin[0] = rawContent->lineOrigin; + lineOrigin[1] = '\0'; + // std::string lineOrigin(rawContent->lineOrigin); content->Set(String::New("lineOrigin"), String::New(lineOrigin)); content->Set(String::New("contentLength"), Integer::New(rawContent->contentLength)); From 0dbc698c2bc4db307aa9abc21a11d815682d85a3 Mon Sep 17 00:00:00 2001 From: Michael Robinson Date: Sat, 6 Apr 2013 01:05:29 +1300 Subject: [PATCH 186/186] Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2d168229..314dd6df0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nodegit", "description": "Node.js libgit2 asynchronous native bindings", - "version": "0.0.78", + "version": "0.0.79", "homepage": "https://github.com/tbranyen/nodegit", "keywords": [ "libgit2",