Skip to content

Commit 9a174f8

Browse files
committed
For some reason had to change Ref to Reference which fixed nearly all issues, got reference lookup working, and updated readme
1 parent cf3f788 commit 9a174f8

10 files changed

Lines changed: 46 additions & 38 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ To use `nodegit2`, you will need to have the `libgit2` shared library in `/usr/l
1313
framework installed, you will also need `git` installed and accessible from your `PATH` to fetch any `vendor/` addons.
1414

1515
### Linux/Mac OS X/BSD Variants ###
16-
__ You can skip this step and `nodegit2` will automatically fetch and install a fresh copy of `libgit2` for you. \*However! If you have `nodegit2` install `libgit2` for you, you must run `make` with a user that has priviledges to write to `/usr/local/lib`__
16+
__ You can skip this step and `nodegit2` will automatically fetch and install a fresh copy of `libgit2` for you. __
17+
\*However! If you have `nodegit2` install `libgit2` for you, you must run `make` with a user that has priviledges to write to `/usr/local/lib`\*
1718

1819
#### Install `libgit2` from [http://libgit2.github.com/](http://libgit2.github.com/) ####
1920

‎example/raw-repo.js‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
var git2 = require('../build/default/git2');
1+
var git2 = require( 'nodegit2' ).git2;
22

33
var repo = new git2.Repo();
44

5-
// Creating a git repo
6-
repo.init('./.git', true, function(err, path, is_bare) {
7-
console.log("Is the repo created bare?", is_bare);
8-
// Access existing repository
9-
repo.open('./.git', function(err, path) {
10-
console.log(err, path);
5+
// Access existing repository
6+
repo.open('./.git', function(err, path) {
7+
console.log(err, path);
8+
9+
var ref = new git2.Reference();
10+
repo.lookup_ref( ref, "HEAD", function( err ) {
11+
console.log( err );
1112
});
1213
});

‎src/commit.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
88

99
#include <git2.h>
1010

11-
#include "commit.h"
11+
#include "reference.h"
1212
#include "repo.h"
1313
#include "oid.h"
14+
#include "commit.h"
1415

1516
using namespace v8;
1617
using namespace node;

‎src/commit.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
1111

1212
#include <git2.h>
1313

14+
#include "reference.h"
1415
#include "repo.h"
1516
#include "oid.h"
1617

1718
using namespace node;
1819
using namespace v8;
1920

20-
class Repo;
2121
class Commit : public EventEmitter {
2222
public:
2323
static Persistent<FunctionTemplate> constructor_template;

‎src/index.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
88

99
#include <git2.h>
1010

11-
#include "ref.h"
11+
#include "reference.h"
1212
#include "repo.h"
1313
#include "oid.h"
1414
#include "commit.h"
@@ -20,7 +20,7 @@ using namespace v8;
2020
extern "C" void init(Handle<Object> target) {
2121
HandleScope scope;
2222

23-
Ref::Initialize(target);
23+
Reference::Initialize(target);
2424
Oid::Initialize(target);
2525
Repo::Initialize(target);
2626
Commit::Initialize(target);

src/ref.cc renamed to src/reference.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,38 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
88

99
#include <git2.h>
1010

11-
#include "ref.h"
11+
#include "reference.h"
1212

1313
using namespace v8;
1414
using namespace node;
1515

16-
void Ref::Initialize(Handle<Object> target) {
16+
void Reference::Initialize(Handle<Object> target) {
1717
HandleScope scope;
1818

1919
Local<FunctionTemplate> t = FunctionTemplate::New(New);
2020

2121
constructor_template = Persistent<FunctionTemplate>::New(t);
2222
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
23-
constructor_template->SetClassName(String::NewSymbol("Ref"));
23+
constructor_template->SetClassName(String::NewSymbol("Reference"));
2424

25-
target->Set(String::NewSymbol("Ref"), constructor_template->GetFunction());
25+
target->Set(String::NewSymbol("Reference"), constructor_template->GetFunction());
2626
}
2727

28-
git_reference* Ref::GetValue() {
28+
git_reference* Reference::GetValue() {
2929
return this->ref;
3030
}
3131

32-
void Ref::SetValue(git_reference *ref) {
32+
void Reference::SetValue(git_reference *ref) {
3333
this->ref = ref;
3434
}
3535

36-
Handle<Value> Ref::New(const Arguments& args) {
36+
Handle<Value> Reference::New(const Arguments& args) {
3737
HandleScope scope;
3838

39-
Ref *ref = new Ref();
39+
Reference *ref = new Reference();
4040
ref->Wrap(args.This());
4141

4242
return args.This();
4343
}
4444

45-
Persistent<FunctionTemplate> Ref::constructor_template;
45+
Persistent<FunctionTemplate> Reference::constructor_template;

src/ref.h renamed to src/reference.h

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

17-
class Ref : public EventEmitter {
17+
class Reference : public EventEmitter {
1818
public:
1919
static Persistent<FunctionTemplate> constructor_template;
2020
static void Initialize (Handle<v8::Object> target);
2121
git_reference* GetValue();
2222
void SetValue (git_reference* ref);
2323

2424
protected:
25-
Ref() {}
26-
~Ref() {}
25+
Reference() {}
26+
~Reference() {}
2727
static Handle<Value> New(const Arguments& args);
2828

2929
private:

‎src/repo.cc‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
88

99
#include <git2.h>
1010

11+
#include "reference.h"
1112
#include "repo.h"
12-
#include "ref.h"
1313
#include "commit.h"
1414

1515
using namespace v8;
@@ -55,8 +55,8 @@ int Repo::Init(const char* path, bool is_bare) {
5555
return err;
5656
}
5757

58-
int Repo::LookupRef(Ref* ref, char* name) {
59-
return git_repository_lookup_ref(&ref->GetValue(), this->repo, name);
58+
int Repo::LookupRef(git_reference** ref, const char* name) {
59+
return git_repository_lookup_ref(ref, this->repo, name);
6060
}
6161

6262
Handle<Value> Repo::New(const Arguments& args) {
@@ -222,19 +222,23 @@ Handle<Value> Repo::LookupRef(const Arguments& args) {
222222

223223
HandleScope scope;
224224

225-
if(args.Length() == 0 || !args[0]->IsString()) {
225+
if(args.Length() == 0 || !args[0]->IsObject()) {
226+
return ThrowException(Exception::Error(String::New("Reference is required and must be a Object.")));
227+
}
228+
229+
if(args.Length() == 1 || !args[1]->IsString()) {
226230
return ThrowException(Exception::Error(String::New("Name is required and must be a String.")));
227231
}
228232

229-
if(args.Length() == 1 || !args[1]->IsFunction()) {
233+
if(args.Length() == 2 || !args[2]->IsFunction()) {
230234
return ThrowException(Exception::Error(String::New("Callback is required and must be a Function.")));
231235
}
232236

233237
callback = Local<Function>::Cast(args[2]);
234238

235239
lookupref_request *ar = new lookupref_request();
236240
ar->repo = repo;
237-
ar->ref = new Ref();
241+
ar->ref = ObjectWrap::Unwrap<Reference>(args[0]->ToObject());
238242
ar->name = Persistent<Value>::New(args[1]);
239243
ar->callback = Persistent<Function>::New(callback);
240244

@@ -250,11 +254,12 @@ int Repo::EIO_LookupRef(eio_req *req) {
250254
lookupref_request *ar = static_cast<lookupref_request *>(req->data);
251255

252256
String::Utf8Value name(ar->name);
253-
ar->err = Persistent<Value>::New(Integer::New(ar->repo->LookupRef(ar->ref, *name)));
257+
git_reference **ref;
258+
ar->err = Persistent<Value>::New(Integer::New(ar->repo->LookupRef(ref, *name)));
254259

255-
//if(Int32::Cast(*ar->err)->Value() == 0) {
256-
// //ar->ref->SetValue(ref);
257-
//}
260+
if(Int32::Cast(*ar->err)->Value() == 0) {
261+
ar->ref->SetValue(*ref);
262+
}
258263

259264
return 0;
260265
}

‎src/repo.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
1111

1212
#include <git2.h>
1313

14-
#include "ref.h"
14+
#include "reference.h"
1515

1616
using namespace node;
1717
using namespace v8;
@@ -24,7 +24,7 @@ class Repo : public EventEmitter {
2424
int Open(const char* path);
2525
void Free();
2626
int Init(const char* path, bool is_bare);
27-
int LookupRef(Ref* ref, char* name);
27+
int LookupRef(git_reference** ref, const char* name);
2828

2929
// TODO: Implement these methods
3030
//int Open2(const char* path);
@@ -74,7 +74,7 @@ struct init_request {
7474

7575
struct lookupref_request {
7676
Repo *repo;
77-
Ref *ref;
77+
Reference *ref;
7878
Persistent<Value> err;
7979
Persistent<Value> name;
8080
Persistent<Function> callback;

‎wscript‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ def build(bld):
2323
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
2424
obj.target = 'git2'
2525
obj.rpath = '/usr/local/lib'
26-
obj.source = 'src/index.cc src/repo.cc src/commit.cc src/oid.cc src/revwalk.cc'
26+
obj.source = 'src/index.cc src/reference.cc src/repo.cc src/commit.cc src/oid.cc src/revwalk.cc'
2727
obj.uselib = 'GIT2'

0 commit comments

Comments
 (0)