Skip to content

Commit 290338b

Browse files
committed
Fixed blob issues
1 parent b1ec5f1 commit 290338b

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

example/raw-blob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repo.open( path.resolve( '../.git' ), function() {
1818

1919
console.log( entry.name() + ':' );
2020
console.log( blob.rawSize() );
21-
console.log( blob.rawContent().toString() );
21+
console.log( blob.rawContent() );
2222
}
2323
});
2424
});

src/blob.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ Handle<Value> GitBlob::Lookup(const Arguments& args) {
7676
HandleScope scope;
7777

7878
if(args.Length() == 0 || !args[0]->IsObject()) {
79-
return ThrowException(Exception::Error(String::New("Repo is required and must be a Object.")));
79+
return ThrowException(Exception::Error(String::New("Repo is required and must be an Object.")));
8080
}
8181

8282
if(args.Length() == 1 || !args[1]->IsObject()) {
83-
return ThrowException(Exception::Error(String::New("Oid is required and must be a Object.")));
83+
return ThrowException(Exception::Error(String::New("Oid is required and must be an Object.")));
8484
}
8585

8686
if(args.Length() == 2 || !args[2]->IsFunction()) {
@@ -139,10 +139,15 @@ int GitBlob::EIO_AfterLookup(eio_req* req) {
139139
Handle<Value> GitBlob::RawContent(const Arguments& args) {
140140
GitBlob* blob = ObjectWrap::Unwrap<GitBlob>(args.This());
141141

142+
if(args.Length() == 0 || !args[0]->IsObject()) {
143+
return ThrowException(Exception::Error(String::New("Buffer is required and must be an Object.")));
144+
}
145+
142146
int rawSize = blob->RawSize();
143-
const char* buffer = (const char *)const_cast<void *>(blob->RawContent());
147+
const char* contents = (const char *)const_cast<void *>(blob->RawContent());
144148

145-
return Buffer::New(const_cast<char *>(buffer), rawSize)->handle_;
149+
Buffer* buffer = Buffer::New(const_cast<char *>(contents), rawSize);
150+
return buffer->handle_;
146151
}
147152

148153
Handle<Value> GitBlob::RawSize(const Arguments& args) {

test/raw-blob.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var git = require( '../' ).raw,
2-
rimraf = require( '../vendor/rimraf' );
1+
var git = require( '../' ).raw
2+
, path = require( 'path' )
3+
, rimraf = require( '../vendor/rimraf' );
34

45
var testRepo = new git.Repo();
56

@@ -86,18 +87,18 @@ exports.rawContent = function( test ) {
8687
testRepo.open( path.resolve( '../.git' ), function() {
8788
testOid.mkstr( '59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5' );
8889

89-
commit.lookup( repo, oid, function( err ) {
90-
var tree = new git.Tree( repo ),
90+
testCommit.lookup( testRepo, testOid, function( err ) {
91+
var tree = new git.Tree( testRepo ),
9192
entry = new git.TreeEntry(),
92-
blob = new git.Blob( repo );
93+
blob = new git.Blob( testRepo );
9394

94-
if( !commit.tree( tree ) && tree.entryCount() > 1 ) {
95+
if( !testCommit.tree( tree ) && tree.entryCount() > 1 ) {
9596
tree.entryByIndex( entry, 1 );
96-
entry.toObject( repo, blob );
97+
entry.toObject( testRepo, blob );
9798

98-
console.log( entry.name() + ':' );
99-
console.log( blob.rawSize() );
100-
console.dir( blob.rawContent() );
99+
//console.log( entry.name() + ':' );
100+
//console.log( blob.rawSize() );
101+
//console.dir( blob.rawContent() );
101102
}
102103
});
103104
});

0 commit comments

Comments
 (0)