Skip to content

Commit 53d64cd

Browse files
committed
Got lookup reference working again in repo
1 parent 28f328a commit 53d64cd

6 files changed

Lines changed: 38 additions & 25 deletions

File tree

example/convenience-repo.js

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

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

77
// Read a commit
8-
this.commit( '75054b7130858db1c1cba13cf8a8febb26b14771', function( err, commit ) {
8+
repo.commit( '2f6cbe055f1a6ca0a3ba524ba88a7806ba507a89', function( err, commit ) {
99
if( err ) { throw err; }
1010

11-
console.log( this.msg() );
11+
console.log( commit.msg() );
1212

1313
var author = commit.author();
1414
console.log( author.name );
1515
console.log( author.email );
1616
});
17+
18+
repo.head( 'master', function( err ) {
19+
20+
console.log( err );
21+
22+
});
1723
});

lib/commit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var _Commit = function( obj ) {
88
self.repo = obj;
99
self.commit = new git.git2.Commit( obj );
1010
}
11-
else if ( obj instanceof git.git2.Commit ) {
11+
else if( obj instanceof git.git2.Commit ) {
1212
self.commit = obj;
1313
}
1414

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var util = require( './util.js' ).util,
22
repo = require( './repo.js' ).repo,
33
error = require( './error.js' ).error,
44
sig = require( './sig.js' ).sig,
5+
oid = require( './oid.js' ).oid,
56
ref = require( './ref.js' ).ref,
67
revwalk = require( './revwalk.js' ).revwalk,
78
commit = require( './commit.js' ).commit;
@@ -10,6 +11,7 @@ exports.git2 = require( '../build/default/nodegit2.node' );
1011
exports.util = util;
1112
exports.repo = repo;
1213
exports.ref = ref;
14+
exports.oid = oid;
1315
exports.sig = sig;
1416
exports.error = error;
1517
exports.revwalk = revwalk;

lib/ref.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
var git2 = require( '../' );
1+
var git = require( '../' );
22

3-
var _Ref = function( ref ) {
3+
var _Ref = function( obj ) {
44
var self = {};
55

6-
// Internal reference to a Git reference
7-
self.ref = ref || new git2.Ref();
6+
if( obj instanceof git.git2.Repo ) {
7+
self.repo = obj;
8+
self.ref = new git.git2.Ref( obj );
9+
}
10+
else if( obj instanceof git.git2.Ref ) {
11+
self.ref = obj;
12+
}
813

914
return self;
1015
};

lib/repo.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,26 @@ var _Repo = function( path, callback ) {
1010
// Internal reference to a Git repository
1111
self.repo = new git.git2.Repo();
1212

13-
// Work with a specific branch
14-
//self.branch = function( name, callback ) {
15-
// var branch = new git.git2.Ref( self.repo );
16-
//
17-
// self.repo.lookupRef( branch, 'refs/heads/'+ name, function() {
18-
// var args = Array.prototype.slice.call( arguments );
19-
// args[0] = git.error().toString( args[0] );
20-
// callback.apply( branch, args.concat( branch ) );
21-
// });
22-
//};
13+
// Work with a specific head reference
14+
self.head = function( name, callback ) {
15+
var head = git.ref( self.repo );
16+
17+
self.repo.lookupRef( head.ref, 'refs/heads/'+ name, function() {
18+
var args = Array.prototype.slice.call( arguments );
19+
args[0] = git.error().toString( args[0] );
20+
21+
callback.apply( head, args.concat( head ) );
22+
});
23+
};
2324

2425
// Find a single commit
2526
self.commit = function( sha, callback ) {
26-
var oid = new git.git2.Oid();
27+
var oid = git.oid( sha );
2728

2829
if( !callback ) { return; }
2930

30-
oid.mkstr( sha );
31-
3231
var commit = git.commit( self.repo );
33-
commit.lookup( oid, callback );
32+
commit.lookup( oid.oid, callback );
3433
};
3534

3635
//self.find = function( name, callback ) {

src/repo.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,14 @@ int Repo::EIO_LookupRef(eio_req *req) {
339339
lookupref_request *ar = static_cast<lookupref_request *>(req->data);
340340

341341
String::Utf8Value name(ar->name);
342-
git_reference *ref;
342+
git_reference* ref = ar->ref->GetValue();
343+
git_reference** out = &ref;
343344

344-
int err = ar->repo->LookupRef((git_reference **)ref, *name);
345+
int err = ar->repo->LookupRef(out, *name);
345346
ar->err = Persistent<Value>::New(Integer::New(err));
346347

347348
if(Int32::Cast(*ar->err)->Value() == 0) {
348-
ar->ref->SetValue(*&ref);
349+
ar->ref->SetValue(*out);
349350
}
350351

351352
return 0;

0 commit comments

Comments
 (0)