| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,6 +72,8 @@ class GitTree : public ObjectWrap { | |||
| 72 | 72 | std::vector<WalkEntry* > rawTreeEntries; | |
| 73 | 73 | ||
| 74 | 74 | git_tree* rawTree; | |
| 75 | + bool blobsOnly; | ||
| 76 | + | ||
| 75 | 77 | Persistent<Function> entryCallback; | |
| 76 | 78 | Persistent<Function> endCallback; | |
| 77 | 79 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,33 +48,34 @@ Tree.prototype.entry = function(path, callback) { | |||
| 48 | 48 | * @fires Tree#entry | |
| 49 | 49 | * @fires Tree#end | |
| 50 | 50 | * | |
| 51 | + * @param {Boolean} [blobsOnly = true] True to emit only blob & blob executable entries. | ||
| 52 | + * | ||
| 51 | 53 | * @return {EventEmitter} | |
| 52 | 54 | */ | |
| 53 | - Tree.prototype.walk = function() { | ||
| 55 | + Tree.prototype.walk = function(blobsOnly) { | ||
| 56 | + blobsOnly = typeof blobsOnly === 'undefined' ? true : blobsOnly; | ||
| 57 | + | ||
| 54 | 58 | var self = this, | |
| 55 | 59 | event = new events.EventEmitter(), | |
| 56 | 60 | entries = []; | |
| 57 | 61 | ||
| 58 | - self.rawTree.walk(function treeWalkEntries(error, rawEntries) { | ||
| 62 | + var total = 0; | ||
| 63 | + | ||
| 64 | + self.rawTree.walk(blobsOnly, function treeWalkEntries(error, rawEntries) { | ||
| 59 | 65 | rawEntries.forEach(function treeWalkEntryEmitter(rawEntry) { | |
| 60 | 66 | var entry = new git.entry(self.rawRepo, rawEntry); | |
| 61 | 67 | entries.push(entry); | |
| 62 | - if (!error) { | ||
| 63 | - /** | ||
| 64 | - * Entry event. | ||
| 65 | - * | ||
| 66 | - * @event Tree#entry | ||
| 67 | - * | ||
| 68 | - * @param {GitError|null} error An error object if there was an issue, null otherwise. | ||
| 69 | - * @param {Entry} entry The tree entry. | ||
| 70 | - */ | ||
| 71 | - event.emit('entry', null, entry); | ||
| 72 | - } | ||
| 68 | + /** | ||
| 69 | + * Entry event. | ||
| 70 | + * | ||
| 71 | + * @event Tree#entry | ||
| 72 | + * | ||
| 73 | + * @param {GitError|null} error An error object if there was an issue, null otherwise. | ||
| 74 | + * @param {Entry} entry The tree entry. | ||
| 75 | + */ | ||
| 76 | + event.emit('entry', null, entry); | ||
| 73 | 77 | }); | |
| 74 | 78 | }, function treeWalkEnd(error) { | |
| 75 | - if (error) { | ||
| 76 | - event.emit('end', git.error(error), entries); | ||
| 77 | - } | ||
| 78 | 79 | /** | |
| 79 | 80 | * End event. | |
| 80 | 81 | * | |
@@ -83,7 +84,7 @@ Tree.prototype.walk = function() { | |||
| 83 | 84 | * @param {GitError|null} error An error object if there was an issue, null otherwise. | |
| 84 | 85 | * @param {Entry[]} entries The tree entries. | |
| 85 | 86 | */ | |
| 86 | - event.emit('end', null, entries); | ||
| 87 | + event.emit('end', error ? git.error(error) : null, entries); | ||
| 87 | 88 | }); | |
| 88 | 89 | ||
| 89 | 90 | return event; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,11 +66,15 @@ Handle<Value> GitTree::Walk(const Arguments& args) { | |||
| 66 | 66 | return ThrowException(Exception::Error(String::New("No tree list to Walk."))); | |
| 67 | 67 | } | |
| 68 | 68 | ||
| 69 | - if(args.Length() == 0 || !args[0]->IsFunction()) { | ||
| 70 | - return ThrowException(Exception::Error(String::New("Entry callback is required and must be a Function."))); | ||
| 69 | + if(args.Length() == 0 || !args[0]->IsBoolean()) { | ||
| 70 | + return ThrowException(Exception::Error(String::New("Blobs only flag is required and must be a Boolean."))); | ||
| 71 | 71 | } | |
| 72 | 72 | ||
| 73 | 73 | if(args.Length() == 1 || !args[1]->IsFunction()) { | |
| 74 | + return ThrowException(Exception::Error(String::New("Entry callback is required and must be a Function."))); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + if(args.Length() == 2 || !args[2]->IsFunction()) { | ||
| 74 | 78 | return ThrowException(Exception::Error(String::New("End callback is required and must be a Function."))); | |
| 75 | 79 | } | |
| 76 | 80 | ||
@@ -82,8 +86,9 @@ Handle<Value> GitTree::Walk(const Arguments& args) { | |||
| 82 | 86 | ||
| 83 | 87 | baton->rawTree = tree->GetValue(); | |
| 84 | 88 | baton->error = NULL; | |
| 85 | - baton->entryCallback = Persistent<Function>::New(Local<Function>::Cast(args[0])); | ||
| 86 | - baton->endCallback = Persistent<Function>::New(Local<Function>::Cast(args[1])); | ||
| 89 | + baton->blobsOnly = CastFromJS<bool>(args[0]->ToBoolean()); | ||
| 90 | + baton->entryCallback = Persistent<Function>::New(Local<Function>::Cast(args[1])); | ||
| 91 | + baton->endCallback = Persistent<Function>::New(Local<Function>::Cast(args[2])); | ||
| 87 | 92 | ||
| 88 | 93 | uv_thread_create(&baton->threadId, WalkWork, baton); | |
| 89 | 94 | ||
@@ -106,16 +111,32 @@ void GitTree::WalkWork(void* payload) { | |||
| 106 | 111 | baton->asyncEnd.data = baton; | |
| 107 | 112 | uv_async_send(&baton->asyncEnd); | |
| 108 | 113 | } | |
| 109 | - int GitTree::WalkWorkEntry(const char* root, const git_tree_entry* entry, void* payload) { | ||
| 114 | + int GitTree::WalkWorkEntry(const char* root, const git_tree_entry* entry, | ||
| 115 | + void* payload) { | ||
| 110 | 116 | WalkBaton *baton = static_cast<WalkBaton *>(payload); | |
| 111 | 117 | ||
| 112 | 118 | uv_mutex_lock(&baton->mutex); | |
| 113 | 119 | ||
| 114 | - GitTree::WalkEntry* walkEntry = new WalkEntry; | ||
| 115 | - walkEntry->rawEntry = git_tree_entry_dup(entry); | ||
| 116 | - walkEntry->root = root; | ||
| 120 | + if (!baton->blobsOnly) { | ||
| 121 | + | ||
| 122 | + GitTree::WalkEntry* walkEntry = new WalkEntry; | ||
| 123 | + walkEntry->rawEntry = git_tree_entry_dup(entry); | ||
| 124 | + walkEntry->root = root; | ||
| 125 | + baton->rawTreeEntries.push_back(walkEntry); | ||
| 117 | 126 | ||
| 118 | - baton->rawTreeEntries.push_back(walkEntry); | ||
| 127 | + } else { | ||
| 128 | + git_tree_entry* rawEntry = git_tree_entry_dup(entry); | ||
| 129 | + git_filemode_t fileMode = git_tree_entry_filemode(rawEntry); | ||
| 130 | + | ||
| 131 | + if (fileMode == GIT_FILEMODE_BLOB || | ||
| 132 | + fileMode == GIT_FILEMODE_BLOB_EXECUTABLE) { | ||
| 133 | + | ||
| 134 | + GitTree::WalkEntry* walkEntry = new WalkEntry; | ||
| 135 | + walkEntry->rawEntry = rawEntry; | ||
| 136 | + walkEntry->root = root; | ||
| 137 | + baton->rawTreeEntries.push_back(walkEntry); | ||
| 138 | + } | ||
| 139 | + } | ||
| 119 | 140 | ||
| 120 | 141 | uv_mutex_unlock(&baton->mutex); | |
| 121 | 142 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments