Commit 0981b884 authored by tbranyen's avatar tbranyen

Implement entry attributes, return null on rawContent call when not a file

parent bd78b6dd
......@@ -50,12 +50,14 @@ class GitTreeEntry : EventEmitter {
*/
void SetValue(git_tree_entry* tree);
const char* Name();
int Attributes();
const git_oid* Id();
int ToObject(git_repository* repo, git_object** obj);
protected:
static Handle<Value> New(const Arguments& args);
static Handle<Value> Name(const Arguments& args);
static Handle<Value> Attributes(const Arguments& args);
static Handle<Value> Id(const Arguments& args);
static Handle<Value> ToObject(const Arguments& args);
......
......@@ -18,17 +18,36 @@ var _TreeEntry = function( obj ) {
enumerable: true
});
Object.defineProperty( self, 'attributes', {
get: function() {
return self.entry.attributes();
},
enumerable: true
});
Object.defineProperty( self, 'content', {
get: function() {
var blob = git.blob( self.repo );
if( self.isFile() ) {
var blob = git.blob( self.repo );
self.entry.toObject( self.repo, blob.blob );
self.entry.toObject( self.repo, blob.blob );
return blob.raw;
}
return blob.raw;
return null;
},
enumerable: true
});
self.isFile = function() {
return self.attributes === 33188;
};
self.isDir = function() {
return self.attributes === 16384;
};
return self;
};
......
{
"name": "nodegit",
"description": "NodeJS libgit2 asynchronous native bindings",
"version": "0.0.3",
"description": "Node.js libgit2 asynchronous native bindings",
"version": "0.0.4",
"homepage": "https://github.com/tbranyen/nodegit",
"author": "Tim Branyen <tim@tabdeveloper.com> (http://twitter.com/tbranyen)",
"main": "./lib/index.js",
......
......@@ -139,14 +139,10 @@ int GitBlob::EIO_AfterLookup(eio_req* req) {
Handle<Value> GitBlob::RawContent(const Arguments& args) {
GitBlob* blob = ObjectWrap::Unwrap<GitBlob>(args.This());
//if(args.Length() == 0 || !args[0]->IsObject()) {
// return ThrowException(Exception::Error(String::New("Buffer is required and must be an Object.")));
//}
int rawSize = blob->RawSize();
const char* contents = (const char *)const_cast<void *>(blob->RawContent());
Buffer* buffer = Buffer::New(const_cast<char *>(contents), rawSize);
Buffer* buffer = Buffer::New(const_cast<char *>(contents), strlen(contents));
return buffer->handle_;
}
......
......@@ -26,6 +26,7 @@ void GitTreeEntry::Initialize(Handle<v8::Object> target) {
constructor_template->SetClassName(String::NewSymbol("TreeEntry"));
NODE_SET_PROTOTYPE_METHOD(constructor_template, "name", Name);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "attributes", Attributes);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "toObject", ToObject);
target->Set(String::NewSymbol("TreeEntry"), constructor_template->GetFunction());
......@@ -39,6 +40,10 @@ const char* GitTreeEntry::Name() {
return git_tree_entry_name(this->entry);
}
int GitTreeEntry::Attributes() {
return git_tree_entry_attributes(this->entry);
}
const git_oid* GitTreeEntry::Id() {
return git_tree_entry_id(this->entry);
}
......@@ -65,6 +70,14 @@ Handle<Value> GitTreeEntry::Name(const Arguments& args) {
return String::New(entry->Name());
}
Handle<Value> GitTreeEntry::Attributes(const Arguments& args) {
HandleScope scope;
GitTreeEntry *entry = ObjectWrap::Unwrap<GitTreeEntry>(args.This());
return Number::New(entry->Attributes());
}
Handle<Value> GitTreeEntry::Id(const Arguments& args) {
HandleScope scope;
......
......@@ -4,7 +4,7 @@ import os, shutil, platform
from os import system
from os.path import exists, abspath
VERSION = '0.0.3'
VERSION = '0.0.4'
APPNAME = 'nodegit'
srcdir = '.'
blddir = 'build'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment