| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | 'src/tree_entry.cc', | |
| 17 | 17 | 'src/diff_list.cc', | |
| 18 | 18 | 'src/threads.cc', | |
| 19 | + 'src/wrapper.cc', | ||
| 19 | 20 | 'src/functions/string.cc', | |
| 20 | 21 | 'src/functions/utilities.cc' | |
| 21 | 22 | ], | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,8 +8,10 @@ var idefs = JSON.parse(fs.readFileSync('v0.18.0.json')), | |||
| 8 | 8 | ||
| 9 | 9 | for (var i in idefs) { | |
| 10 | 10 | var idef = idefs[i]; | |
| 11 | - if (idef.jsClassName != "Oid") continue; | ||
| 12 | - | ||
| 13 | - fs.writeFileSync(path.resolve("./include/" + idef.filename), headerTemplate(idef)); | ||
| 14 | - fs.writeFileSync(path.resolve("./src/" + path.basename(idef.filename, '.h') + '.cc'), classTemplate(idef)); | ||
| 11 | + if (["Oid", "Blob"].indexOf(idef.jsClassName) > -1) { | ||
| 12 | + fs.writeFileSync( | ||
| 13 | + path.resolve("./include/" + idef.filename), headerTemplate(idef)); | ||
| 14 | + fs.writeFileSync( | ||
| 15 | + path.resolve("./src/" + path.basename(idef.filename, '.h') + '.cc'), classTemplate(idef)); | ||
| 16 | + } | ||
| 15 | 17 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,112 +1,75 @@ | |||
| 1 | 1 | /** | |
| 2 | - * Copyright (c) 2011, Tim Branyen @tbranyen <tim@tabdeveloper.com> | ||
| 3 | - * @author Michael Robinson @codeofinterest <mike@pagesofinterest.net> | ||
| 4 | - * | ||
| 5 | - * Dual licensed under the MIT and GPL licenses. | ||
| 6 | - */ | ||
| 2 | + * This code is auto-generated; unless you know what you're doing, do not modify! | ||
| 3 | + **/ | ||
| 7 | 4 | ||
| 8 | - #ifndef BLOB_H | ||
| 9 | - #define BLOB_H | ||
| 5 | + #ifndef GITBLOB_H | ||
| 6 | + #define GITBLOB_H | ||
| 10 | 7 | ||
| 11 | 8 | #include <v8.h> | |
| 12 | 9 | #include <node.h> | |
| 13 | - #include <string.h> | ||
| 10 | + #include <string> | ||
| 14 | 11 | ||
| 15 | 12 | #include "git2.h" | |
| 16 | 13 | ||
| 17 | - #include "repo.h" | ||
| 18 | - #include "oid.h" | ||
| 19 | - | ||
| 20 | - using namespace v8; | ||
| 21 | 14 | using namespace node; | |
| 15 | + using namespace v8; | ||
| 22 | 16 | ||
| 23 | - /** | ||
| 24 | - * Wrapper for libgit2 git_blob. | ||
| 25 | - */ | ||
| 26 | 17 | class GitBlob : public ObjectWrap { | |
| 27 | 18 | public: | |
| 28 | 19 | ||
| 29 | 20 | static Persistent<Function> constructor_template; | |
| 21 | + static void Initialize (Handle<v8::Object> target); | ||
| 30 | 22 | ||
| 31 | - static void Initialize(Handle<Object> target); | ||
| 32 | - | ||
| 33 | - git_blob* GetValue(); | ||
| 34 | - void SetValue(git_blob* blob); | ||
| 23 | + git_blob *GetValue(); | ||
| 35 | 24 | ||
| 36 | - protected: | ||
| 37 | - GitBlob() {}; | ||
| 38 | - ~GitBlob() {}; | ||
| 25 | + private: | ||
| 26 | + GitBlob(git_blob *raw); | ||
| 27 | + ~GitBlob(); | ||
| 39 | 28 | ||
| 40 | 29 | static Handle<Value> New(const Arguments& args); | |
| 41 | - static Handle<Value> Free(const Arguments& args); | ||
| 42 | 30 | ||
| 43 | 31 | static Handle<Value> Lookup(const Arguments& args); | |
| 44 | 32 | static void LookupWork(uv_work_t* req); | |
| 45 | 33 | static void LookupAfterWork(uv_work_t* req); | |
| 46 | 34 | ||
| 47 | - static Handle<Value> RawContent(const Arguments& args); | ||
| 48 | - static void RawContentWork(uv_work_t* req); | ||
| 49 | - static void RawContentAfterWork(uv_work_t* req); | ||
| 50 | - | ||
| 35 | + struct LookupBaton { | ||
| 36 | + uv_work_t request; | ||
| 37 | + const git_error* error; | ||
| 38 | + git_blob *out; | ||
| 39 | + git_repository * repo; | ||
| 40 | + const git_oid * id; | ||
| 41 | + Persistent<Function> callback; | ||
| 42 | + }; | ||
| 43 | + static Handle<Value> Oid(const Arguments& args); | ||
| 44 | + static Handle<Value> Content(const Arguments& args); | ||
| 45 | + static Handle<Value> Size(const Arguments& args); | ||
| 51 | 46 | static Handle<Value> CreateFromFile(const Arguments& args); | |
| 52 | 47 | static void CreateFromFileWork(uv_work_t* req); | |
| 53 | 48 | static void CreateFromFileAfterWork(uv_work_t* req); | |
| 54 | 49 | ||
| 50 | + struct CreateFromFileBaton { | ||
| 51 | + uv_work_t request; | ||
| 52 | + const git_error* error; | ||
| 53 | + git_oid * id; | ||
| 54 | + git_repository * repo; | ||
| 55 | + const char * path; | ||
| 56 | + Persistent<Function> callback; | ||
| 57 | + }; | ||
| 55 | 58 | static Handle<Value> CreateFromBuffer(const Arguments& args); | |
| 56 | 59 | static void CreateFromBufferWork(uv_work_t* req); | |
| 57 | 60 | static void CreateFromBufferAfterWork(uv_work_t* req); | |
| 58 | 61 | ||
| 59 | - private: | ||
| 60 | - | ||
| 61 | - git_blob* blob; | ||
| 62 | - | ||
| 63 | - struct LookupBaton { | ||
| 62 | + struct CreateFromBufferBaton { | ||
| 64 | 63 | uv_work_t request; | |
| 65 | 64 | const git_error* error; | |
| 66 | - | ||
| 67 | - GitBlob* blob; | ||
| 68 | - git_blob* rawBlob; | ||
| 69 | - git_repository* rawRepo; | ||
| 70 | - git_oid rawOid; | ||
| 71 | - | ||
| 65 | + git_oid * oid; | ||
| 66 | + git_repository * repo; | ||
| 67 | + const void * buffer; | ||
| 68 | + size_t len; | ||
| 72 | 69 | Persistent<Function> callback; | |
| 73 | 70 | }; | |
| 74 | - | ||
| 75 | - struct RawContentBaton { | ||
| 76 | - uv_work_t request; | ||
| 77 | - | ||
| 78 | - GitBlob* blob; | ||
| 79 | - git_blob* rawBlob; | ||
| 80 | - std::string rawContent; | ||
| 81 | - int rawSize; | ||
| 82 | - | ||
| 83 | - Persistent<Function> callback; | ||
| 84 | - }; | ||
| 85 | - | ||
| 86 | - struct CreateFromFileBaton { | ||
| 87 | - uv_work_t request; | ||
| 88 | - const git_error* error; | ||
| 89 | - | ||
| 90 | - GitBlob* blob; | ||
| 91 | - git_blob* rawBlob; | ||
| 92 | - git_repository* rawRepo; | ||
| 93 | - std::string path; | ||
| 94 | - | ||
| 95 | - Persistent<Function> callback; | ||
| 96 | - }; | ||
| 97 | - | ||
| 98 | - struct CreateFromBufferBaton { | ||
| 99 | - uv_work_t request; | ||
| 100 | - const git_error* error; | ||
| 101 | - | ||
| 102 | - GitBlob* blob; | ||
| 103 | - git_blob* rawBlob; | ||
| 104 | - git_repository* rawRepo; | ||
| 105 | - const void* data; | ||
| 106 | - size_t dataLength; | ||
| 107 | - | ||
| 108 | - Persistent<Function> callback; | ||
| 109 | - }; | ||
| 71 | + static Handle<Value> IsBinary(const Arguments& args); | ||
| 72 | + git_blob *raw; | ||
| 110 | 73 | }; | |
| 111 | 74 | ||
| 112 | 75 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ class GitOid : public ObjectWrap { | |||
| 20 | 20 | static Persistent<Function> constructor_template; | |
| 21 | 21 | static void Initialize (Handle<v8::Object> target); | |
| 22 | 22 | ||
| 23 | - git_oid GetValue(); | ||
| 23 | + git_oid *GetValue(); | ||
| 24 | 24 | ||
| 25 | 25 | private: | |
| 26 | 26 | GitOid(git_oid *raw); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,31 @@ | |||
| 1 | + /** | ||
| 2 | + * This code is auto-generated; unless you know what you're doing, do not modify! | ||
| 3 | + **/ | ||
| 4 | + | ||
| 5 | + #ifndef WRAPPER_H | ||
| 6 | + #define WRAPPER_H | ||
| 7 | + | ||
| 8 | + #include <v8.h> | ||
| 9 | + #include <node.h> | ||
| 10 | + | ||
| 11 | + using namespace node; | ||
| 12 | + using namespace v8; | ||
| 13 | + | ||
| 14 | + class Wrapper : public ObjectWrap { | ||
| 15 | + public: | ||
| 16 | + | ||
| 17 | + static Persistent<Function> constructor_template; | ||
| 18 | + static void Initialize (Handle<v8::Object> target); | ||
| 19 | + | ||
| 20 | + void *GetValue(); | ||
| 21 | + | ||
| 22 | + private: | ||
| 23 | + Wrapper(void *raw); | ||
| 24 | + | ||
| 25 | + static Handle<Value> New(const Arguments& args); | ||
| 26 | + static Handle<Value> ToBuffer(const Arguments& args); | ||
| 27 | + | ||
| 28 | + void *raw; | ||
| 29 | + }; | ||
| 30 | + | ||
| 31 | + #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,38 +45,17 @@ Blob.prototype.lookup = function(oid, callback) { | |||
| 45 | 45 | ||
| 46 | 46 | /** | |
| 47 | 47 | * Retrieve the blob's raw content buffer. | |
| 48 | - * | ||
| 49 | - * @param {Blob~rawContentCallback} callback | ||
| 50 | 48 | */ | |
| 51 | - Blob.prototype.rawContent = function(callback) { | ||
| 52 | - /** | ||
| 53 | - * @callback Blob~rawContentCallback Callback executed after raw content is retrieved. | ||
| 54 | - * @param {GitError|null} error An Error or null if successful. | ||
| 55 | - * @param {Buffer|null} content The raw content of the blob or null. | ||
| 56 | - */ | ||
| 57 | - this.rawBlob.rawContent(function(error, content) { | ||
| 58 | - if (success(error, callback)) { | ||
| 59 | - callback(null, content); | ||
| 60 | - } | ||
| 61 | - }); | ||
| 49 | + Blob.prototype.rawContent = function() { | ||
| 50 | + return this.rawBlob.content().toBuffer(this.rawBlob.size()); | ||
| 62 | 51 | }; | |
| 63 | 52 | ||
| 64 | 53 | /** | |
| 65 | 54 | * Retrieve the blob's content. | |
| 66 | - * | ||
| 67 | - * @param {Blob~contentCallback} callback | ||
| 68 | 55 | */ | |
| 69 | 56 | Blob.prototype.content = function(callback) { | |
| 70 | - /** | ||
| 71 | - * @callback Blob~contentCallback Callback executed after content is retrieved. | ||
| 72 | - * @param {GitError|null} error An Error or null if successful. | ||
| 73 | - * @param {String|null} content The content of the blob or null. | ||
| 74 | - */ | ||
| 75 | - this.rawContent(function(error, content) { | ||
| 76 | - if (success(error, callback)) { | ||
| 77 | - callback(null, content.toString()); | ||
| 78 | - } | ||
| 79 | - }); | ||
| 57 | + var content = this.rawContent(); | ||
| 58 | + return content.toString(); | ||
| 80 | 59 | }; | |
| 81 | 60 | ||
| 82 | 61 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,11 +208,8 @@ TreeEntry.prototype.content = function(callback) { | |||
| 208 | 208 | if (!success(error, callback)) { | |
| 209 | 209 | return; | |
| 210 | 210 | } | |
| 211 | - blob.content(function blobContent(error, content) { | ||
| 212 | - if (success(error, callback)) { | ||
| 213 | - callback(null, content); | ||
| 214 | - } | ||
| 215 | - }); | ||
| 211 | + var content = blob.content(); | ||
| 212 | + callback(null, content); | ||
| 216 | 213 | }); | |
| 217 | 214 | }; | |
| 218 | 215 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | #include "git2.h" | |
| 12 | 12 | ||
| 13 | + #include "../include/wrapper.h" | ||
| 13 | 14 | #include "../include/reference.h" | |
| 14 | 15 | #include "../include/signature.h" | |
| 15 | 16 | #include "../include/error.h" | |
@@ -24,6 +25,10 @@ | |||
| 24 | 25 | #include "../include/threads.h" | |
| 25 | 26 | ||
| 26 | 27 | extern "C" void init(Handle<v8::Object> target) { | |
| 28 | + HandleScope scope; | ||
| 29 | + | ||
| 30 | + Wrapper::Initialize(target); | ||
| 31 | + | ||
| 27 | 32 | GitError::Initialize(target); | |
| 28 | 33 | ||
| 29 | 34 | GitReference::Initialize(target); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments