-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> | ||
*/ | ||
|
||
#include <v8.h> | ||
#include <node.h> | ||
#include <node_events.h> | ||
|
||
#include <git2.h> | ||
|
||
#include "repo.h" | ||
#include "tree.h" | ||
|
||
using namespace v8; | ||
using namespace node; | ||
|
||
void Tree::Initialize (Handle<v8::Object> target) { | ||
HandleScope scope; | ||
|
||
Local<FunctionTemplate> t = FunctionTemplate::New(New); | ||
|
||
constructor_template = Persistent<FunctionTemplate>::New(t); | ||
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); | ||
constructor_template->SetClassName(String::NewSymbol("Tree")); | ||
|
||
target->Set(String::NewSymbol("Tree"), constructor_template->GetFunction()); | ||
} | ||
|
||
git_tree* Tree::GetValue() { | ||
return this->tree; | ||
} | ||
|
||
void Tree::SetValue(git_tree* tree) { | ||
this->tree = tree; | ||
} | ||
|
||
int Tree::New(git_repository* repo) { | ||
return git_tree_new(&this->tree, repo); | ||
} | ||
|
||
Handle<Value> Tree::New(const Arguments& args) { | ||
HandleScope scope; | ||
|
||
Tree *tree = new Tree(); | ||
|
||
if(args.Length() == 0 || !args[0]->IsObject()) { | ||
return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); | ||
} | ||
|
||
Repo *repo = ObjectWrap::Unwrap<Repo>(args[0]->ToObject()); | ||
int err = tree->New((git_repository *)repo); | ||
|
||
tree->Wrap(args.This()); | ||
|
||
return args.This(); | ||
} | ||
Persistent<FunctionTemplate> Tree::constructor_template; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> | ||
*/ | ||
|
||
#ifndef TREE_H | ||
#define TREE_H | ||
|
||
#include <v8.h> | ||
#include <node.h> | ||
#include <node_events.h> | ||
|
||
#include <git2.h> | ||
|
||
#include "repo.h" | ||
|
||
using namespace v8; | ||
using namespace node; | ||
|
||
/** | ||
* Class wrapper for libgit2 git_tree | ||
*/ | ||
class Tree : public EventEmitter { | ||
public: | ||
/** | ||
* v8::FunctionTemplate used to create Node.js constructor | ||
*/ | ||
static Persistent<FunctionTemplate> constructor_template; | ||
|
||
/** | ||
* Used to intialize the EventEmitter from Node.js | ||
* | ||
* @param target v8::Object the Node.js module object | ||
*/ | ||
static void Initialize(Handle<v8::Object> target); | ||
|
||
/** | ||
* Creates new internal git_tree reference | ||
* | ||
* @param repo the repo to use when creating the tree. | ||
* @return 0 on success; error code otherwise | ||
*/ | ||
int New(git_repository *repo); | ||
|
||
/** | ||
* Accessor for Tree | ||
* | ||
* @return the internal git_tree reference | ||
*/ | ||
git_tree* GetValue(); | ||
|
||
/** | ||
* Mutator for Object | ||
* | ||
* @param obj a git_object object | ||
*/ | ||
void SetValue(git_tree* tree); | ||
|
||
/** | ||
* Lookup a tree object from a repository. | ||
* | ||
* @param tree pointer to the looked up tree | ||
* @param repo the repo to use when locating the tree. | ||
* @param id identity of the tree to locate. | ||
* | ||
* @return 0 on success; error code otherwise | ||
*/ | ||
int Lookup(git_tree **tree, git_repository *repo, const git_oid *id); | ||
|
||
protected: | ||
/** | ||
* Constructor | ||
*/ | ||
Tree() {}; | ||
|
||
/** | ||
* Deconstructor | ||
*/ | ||
~Tree() {}; | ||
|
||
/** | ||
* Creates a new instance of Tree to Node.js | ||
* | ||
* @param args v8::Arguments function call arguments from Node.js | ||
* | ||
* @return v8::Object args.This() | ||
*/ | ||
static Handle<Value> New(const Arguments& args); | ||
|
||
private: | ||
/** | ||
* Internal reference to git_tree object | ||
*/ | ||
git_tree *tree; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters