Skip to content

Commit b47ce58

Browse files
committed
Updated to get blob reading working
1 parent 908d7c5 commit b47ce58

8 files changed

Lines changed: 48 additions & 27 deletions

File tree

example/convenience-tree.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ git.repo( '../.git', function( err, repo ) {
77
if( err ) { throw err; }
88

99
branch.tree().each( function( i, entry ) {
10-
1110
console.log( entry.name );
12-
console.log( entry.content );
1311

12+
console.log( entry.contents );
13+
14+
var blob = git.blob( repo.repo );
15+
entry.entry.toObject( blob.blob );
16+
console.log( blob.blob.rawContent() );
1417
});
1518
});
1619
});

lib/blob.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var _Blob = function( obj ) {
77
self.repo = obj;
88
self.blob = new git.raw.Blob( obj );
99
}
10-
else if ( obj instanceof git.raw.Blob ) {
10+
else if( obj instanceof git.raw.Blob ) {
1111
self.blob = obj;
1212
}
1313

@@ -18,7 +18,6 @@ var _Blob = function( obj ) {
1818
enumerable: true
1919
});
2020

21-
2221
self.lookup = function( oid ) {
2322
self.blob.lookup( self.repo, oid, function() {
2423
var args = Array.prototype.slice.call( arguments );

lib/commit.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var git = require( '../' );
22

33
var _Commit = function( obj ) {
4-
var self = {};
4+
var self = { _cache: {} };
55

66
if( obj instanceof git.raw.Repo ) {
77
self.repo = obj;
@@ -36,7 +36,6 @@ var _Commit = function( obj ) {
3636
enumerable: true
3737
});
3838

39-
4039
Object.defineProperty( self, 'msg', {
4140
get: function() {
4241
return self.commit.messageShort();

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var util = require( './util.js' ).util,
44
error = require( './error.js' ).error,
55
sig = require( './sig.js' ).sig,
66
oid = require( './oid.js' ).oid,
7-
oid = require( './obj.js' ).obj,
7+
obj = require( './obj.js' ).obj,
88
ref = require( './ref.js' ).ref,
99
revwalk = require( './revwalk.js' ).revwalk,
1010
commit = require( './commit.js' ).commit,

lib/tree_entry.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ var git = require( '../' );
33
var _TreeEntry = function( obj ) {
44
var self = {};
55

6+
if( obj instanceof git.raw.TreeEntry ) {
7+
self.entry = obj;
8+
}
9+
else {
10+
self.entry = new git.raw.TreeEntry();
11+
}
12+
613
Object.defineProperty( self, 'name', {
714
get: function() {
815
return self.entry.name();
@@ -12,27 +19,15 @@ var _TreeEntry = function( obj ) {
1219

1320
Object.defineProperty( self, 'content', {
1421
get: function() {
15-
var obj = git.obj(),
16-
blob;
17-
18-
self.entry.toObject( obj.obj );
22+
var blob = git.blob( self.repo );
1923

20-
blob = git.blob( obj.owner() );
21-
blob.lookup( oid.oid );
24+
self.entry.toObject( blob.blob );
2225

23-
return blob.content();
26+
return blob.raw;
2427
},
2528
enumerable: true
2629
});
2730

28-
// Internal references to Git references
29-
if ( obj instanceof git.raw.TreeEntry ) {
30-
self.entry = obj;
31-
}
32-
else {
33-
self.entry = new git.raw.TreeEntry();
34-
}
35-
3631
return self;
3732
};
3833

src/blob.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Handle<Value> Blob::New(const Arguments& args) {
7474
Handle<Value> Blob::RawContent(const Arguments& args) {
7575
HandleScope scope;
7676

77-
Blob *blob = new Blob();
77+
Blob *blob = ObjectWrap::Unwrap<Blob>(args.This());
7878

7979
return String::New(blob->RawContent());
8080
}

src/tree_entry.cc

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com>
99
#include "../vendor/libgit2/src/git2.h"
1010

1111
#include "repo.h"
12+
#include "blob.h"
1213
#include "tree.h"
1314
#include "object.h"
15+
#include "oid.h"
1416
#include "tree_entry.h"
1517

1618
using namespace v8;
@@ -37,8 +39,12 @@ const char* GitTreeEntry::Name() {
3739
return git_tree_entry_name(this->entry);
3840
}
3941

42+
const git_oid* GitTreeEntry::Id() {
43+
return git_tree_entry_id(this->entry);
44+
}
45+
4046
int GitTreeEntry::ToObject(git_object** obj) {
41-
return git_tree_entry_2object(obj, entry);
47+
return git_tree_entry_2object(obj, this->entry);
4248
}
4349

4450
Handle<Value> GitTreeEntry::New(const Arguments& args) {
@@ -59,20 +65,36 @@ Handle<Value> GitTreeEntry::Name(const Arguments& args) {
5965
return String::New(entry->Name());
6066
}
6167

68+
Handle<Value> GitTreeEntry::Id(const Arguments& args) {
69+
HandleScope scope;
70+
71+
GitTreeEntry *entry = ObjectWrap::Unwrap<GitTreeEntry>(args.This());
72+
73+
if(args.Length() == 0 || !args[0]->IsObject()) {
74+
return ThrowException(Exception::Error(String::New("Oid is required and must be an Object.")));
75+
}
76+
77+
Oid* oid = ObjectWrap::Unwrap<Oid>(args[0]->ToObject());
78+
79+
oid->SetValue(const_cast<git_oid *>(entry->Id()));
80+
81+
return Undefined();
82+
}
83+
6284
Handle<Value> GitTreeEntry::ToObject(const Arguments& args) {
6385
HandleScope scope;
6486

6587
GitTreeEntry *entry = ObjectWrap::Unwrap<GitTreeEntry>(args.This());
6688

6789
if(args.Length() == 0 || !args[0]->IsObject()) {
68-
return ThrowException(Exception::Error(String::New("Object is required and must be an Object.")));
90+
return ThrowException(Exception::Error(String::New("Blob is required and must be an Object.")));
6991
}
7092

71-
GitObject*obj = ObjectWrap::Unwrap<GitObject>(args[0]->ToObject());
93+
Blob* blob = ObjectWrap::Unwrap<Blob>(args[0]->ToObject());
7294

7395
git_object* out;
7496
entry->ToObject(&out);
75-
obj->SetValue(out);
97+
blob->SetValue((git_blob *)out);
7698

7799
return Undefined();
78100
}

src/tree_entry.h

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

1414
#include "repo.h"
1515
#include "tree.h"
16+
#include "oid.h"
1617
#include "object.h"
1718

1819
using namespace v8;
@@ -49,11 +50,13 @@ class GitTreeEntry : EventEmitter {
4950
*/
5051
void SetValue(git_tree_entry* tree);
5152
const char* Name();
53+
const git_oid* Id();
5254
int ToObject(git_object** obj);
5355

5456
protected:
5557
static Handle<Value> New(const Arguments& args);
5658
static Handle<Value> Name(const Arguments& args);
59+
static Handle<Value> Id(const Arguments& args);
5760
static Handle<Value> ToObject(const Arguments& args);
5861

5962
private:

0 commit comments

Comments
 (0)