Skip to content

Commit cc513ea

Browse files
committed
Removed extraneous callback vars, fixed Oid method name for now, need namespacing
1 parent c685156 commit cc513ea

9 files changed

Lines changed: 40 additions & 39 deletions

File tree

CONTRIBUTORS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
nodegit2 contributors (sorted alphabeticaly)
22
============================================
3+
* **[Ben Alman](https://github.com/cowboy)**
4+
5+
* JS API suggestions
6+
37
* **[inimino](https://github.com/inimino)**
48

59
* JS API suggestions

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Building and installing
1111
### Dependancies ###
1212
To run `nodegit2` you need `Node.js` and to run unit tests you will need to have `git` installed and accessible from your `PATH` to fetch any `vendor/` addons.
1313

14-
### Easy install ###
14+
### Easy install (Recommended!) ###
15+
This will install and configure everything you need to use `nodegit2`.
1516

1617
[tim@thinkpad Projects]$ sudo npm install nodegit2
1718

@@ -97,7 +98,7 @@ Running tests
9798

9899
__ `nodegit2` library code is written adhering to a modified `JSHint`. Run these tests with `make lint`. __
99100

100-
__ Ensure the submodules `nodeunit` and `rimraf` are located in the `vendor/` subdirectory. __
101+
__ To run unit tests ensure the submodules `nodeunit` and `rimraf` are located in the `vendor/` subdirectory. __
101102

102103
If they are not, `cd` into the `nodegit2` dir and run the following `git` commands to automatically fetch them:
103104
[tim@thinkpad Projects]$ cd nodegit2

example/convenience-repo.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
var git = require( '../' );
22

3-
// Read the current repository
4-
git.repo( './dummyrepo/.git', function( err, path, repo ) {
3+
git.repo( './dummyrepo/.git', function( err, repo ) {
54
if( err ) { throw err; }
65

7-
// Read a commit
8-
//repo.commit( '2f6cbe055f1a6ca0a3ba524ba88a7806ba507a89', function( err, commit ) {
9-
// if( err ) { throw err; }
10-
11-
// console.log( commit.msg() );
12-
13-
// var author = commit.author();
14-
// console.log( author.name );
15-
// console.log( author.email );
16-
//});
6+
// Read a commit when you know the sha1
7+
repo.commit( '2f6cbe055f1a6ca0a3ba524ba88a7806ba507a89', function( err, commit ) {
8+
console.log( commit.author().name );
9+
});
1710

18-
repo.head( 'master', function( err, path, head ) {
19-
console.log( git.error( err ) );
11+
// Read a commit when you know the name
12+
repo.head( 'master', function( err, head ) {
13+
git.commit( repo.repo ).lookup( head.oid().oid, function( err, commit ) {
14+
console.log( commit.author().name );
15+
});
2016
});
2117
});

lib/ref.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ var _Ref = function( obj ) {
1111
self.ref = obj;
1212
}
1313

14+
self.oid = function() {
15+
var oid = git.oid();
16+
17+
self.ref.oid( oid.oid );
18+
19+
return oid;
20+
};
21+
1422
return self;
1523
};
1624

src/oid.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ void Oid::Initialize(Handle<Object> target) {
2828
target->Set(String::NewSymbol("Oid"), constructor_template->GetFunction());
2929
}
3030

31-
Handle<Value> Oid::WrapObj(Local<Object> obj) {
32-
this->Wrap(obj);
33-
return obj;
34-
}
35-
3631
git_oid* Oid::GetValue() {
3732
return &this->oid;
3833
}
@@ -53,7 +48,7 @@ char* Oid::Fmt(char* buffer) {
5348
git_oid_fmt(*&buffer, &this->oid);
5449
}
5550

56-
void Oid::PathFmt(char *str) {
51+
void Oid::PathFmt(char* str) {
5752
git_oid_pathfmt(str, &this->oid);
5853
}
5954

src/oid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
1414
using namespace node;
1515
using namespace v8;
1616

17-
class Oid : public ObjectWrap {
17+
class Oid : public EventEmitter {
1818
public:
1919
static Persistent<FunctionTemplate> constructor_template;
2020
static void Initialize (Handle<v8::Object> target);

src/reference.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void Reference::Initialize(Handle<Object> target) {
2424
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
2525
constructor_template->SetClassName(String::NewSymbol("Ref"));
2626

27-
NODE_SET_PROTOTYPE_METHOD(constructor_template, "oid", Oid);
27+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "oid", _Oid);
2828

2929
target->Set(String::NewSymbol("Ref"), constructor_template->GetFunction());
3030
}
@@ -41,7 +41,7 @@ int Reference::New(git_repository* repo) {
4141
return git_reference_new(&this->ref, repo);
4242
}
4343

44-
const git_oid* Reference::Oid() {
44+
const git_oid* Reference::_Oid() {
4545
return git_reference_oid(*&this->ref);
4646
}
4747

@@ -62,16 +62,16 @@ Handle<Value> Reference::New(const Arguments& args) {
6262
return args.This();
6363
}
6464

65-
Handle<Value> Reference::Oid(const Arguments& args) {
65+
Handle<Value> Reference::_Oid(const Arguments& args) {
6666
Reference *ref = ObjectWrap::Unwrap<Reference>(args.This());
6767
HandleScope scope;
6868

6969
if(args.Length() == 0 || !args[0]->IsObject()) {
7070
return ThrowException(Exception::Error(String::New("Oid is required and must be an Object.")));
7171
}
7272

73-
//Oid *oid = ObjectWrap::Unwrap<Oid>(args[0]->ToObject());
74-
//oid->SetValue( (git_oid *)ref->Oid() );
73+
Oid *oid = ObjectWrap::Unwrap<Oid>(args[0]->ToObject());
74+
oid->SetValue( const_cast<git_oid *>(ref->_Oid()) );
7575

7676
return Undefined();
7777
}

src/reference.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ class Reference : public EventEmitter {
2424
// Synchronous
2525
int New(git_repository* repo);
2626
void SetValue(git_reference* ref);
27-
const git_oid* Oid();
27+
const git_oid* _Oid();
2828

2929
protected:
3030
Reference() {}
3131
~Reference() {}
3232
static Handle<Value> New(const Arguments& args);
3333

34-
static Handle<Value> Oid(const Arguments& args);
34+
static Handle<Value> _Oid(const Arguments& args);
3535

3636
private:
3737
git_reference *ref;

src/repo.cc

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,12 @@ int Repo::EIO_AfterOpen(eio_req *req) {
119119
ev_unref(EV_DEFAULT_UC);
120120
ar->repo->Unref();
121121

122-
Local<Value> argv[2];
122+
Local<Value> argv[1];
123123
argv[0] = Number::Cast(*ar->err);
124-
argv[1] = String::Cast(*ar->path);
125124

126125
TryCatch try_catch;
127126

128-
ar->callback->Call(Context::GetCurrent()->Global(), 2, argv);
127+
ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);
129128

130129
if(try_catch.HasCaught())
131130
FatalException(try_catch);
@@ -281,12 +280,11 @@ int Repo::EIO_AfterInit(eio_req *req) {
281280

282281
Local<Value> argv[3];
283282
argv[0] = Number::Cast(*ar->err);
284-
argv[1] = String::Cast(*ar->path);
285-
argv[2] = *ar->is_bare;
283+
argv[1] = *ar->is_bare;
286284

287285
TryCatch try_catch;
288286

289-
ar->callback->Call(Context::GetCurrent()->Global(), 3, argv);
287+
ar->callback->Call(Context::GetCurrent()->Global(), 2, argv);
290288

291289
if(try_catch.HasCaught())
292290
FatalException(try_catch);
@@ -359,13 +357,12 @@ int Repo::EIO_AfterLookupRef(eio_req *req) {
359357
ev_unref(EV_DEFAULT_UC);
360358
ar->repo->Unref();
361359

362-
Local<Value> argv[2];
360+
Local<Value> argv[1];
363361
argv[0] = Number::Cast(*ar->err);
364-
argv[1] = String::Cast(*ar->name);
365362

366363
TryCatch try_catch;
367364

368-
ar->callback->Call(Context::GetCurrent()->Global(), 2, argv);
365+
ar->callback->Call(Context::GetCurrent()->Global(), 1, argv);
369366

370367
if(try_catch.HasCaught())
371368
FatalException(try_catch);

0 commit comments

Comments
 (0)