/* * Copyright 2011, Tim Branyen @tbranyen * Dual licensed under the MIT and GPL licenses. */ #ifndef COMMIT_H #define COMMIT_H #include #include #include "../vendor/libgit2/include/git2.h" #include "reference.h" #include "repo.h" #include "oid.h" #include "tree.h" using namespace node; using namespace v8; /** * Class wrapper for libgit2 git_commit */ class GitCommit : public ObjectWrap { public: /** * v8::FunctionTemplate used to create Node.js constructor */ static Persistent constructor_template; /** * Used to intialize the EventEmitter from Node.js * * @param target v8::Object the Node.js module object */ static void Initialize (Handle target); git_commit* GetValue(); void SetValue(git_commit* commit); int Lookup(git_repository* repo, git_oid* oid); void Close(); const git_oid* Id(); const char* MessageShort(); const char* Message(); time_t Time(); int TimeOffset(); const git_signature* Committer(); const git_signature* Author(); int Tree(git_tree** tree); unsigned int ParentCount(); int Parent(git_commit** commit, int pos); protected: GitCommit() {} ~GitCommit() {} static Handle New(const Arguments& args); static Handle NewInstance(); static Handle Lookup(const Arguments& args); static void LookupWork(uv_work_t *req); static void LookupAfterWork(uv_work_t *req); static Handle Close(const Arguments& args); static Handle Id(const Arguments& args); static Handle MessageShort(const Arguments& args); static Handle Message(const Arguments& args); static Handle Time(const Arguments& args); static Handle TimeOffset(const Arguments& args); static Handle Committer(const Arguments& args); static Handle Author(const Arguments& args); static Handle Tree(const Arguments& args); static void TreeWork(uv_work_t* req); static void TreeAfterWork(uv_work_t* req); static Handle ParentCount(const Arguments& args); static Handle ParentSync(const Arguments& args); static Handle Parent(const Arguments& args); static void ParentWork(uv_work_t* req); static void ParentAfterWork(uv_work_t* req); private: git_commit* commit; git_oid* oid; struct lookup_request { GitCommit* commit; GitRepo* repo; GitOid* oid; int err; Persistent callback; }; /** * Struct: parent_request * Contains references to the current commit, parent commit (output) * parent commit's index, also contains references to an error code post * lookup, and a callback function to execute. */ struct ParentBaton { uv_work_t request; int errorCode; const char* errorMessage; int index; GitCommit *commit; git_commit *rawParentCommit; Persistent callback; }; }; #endif