@@ -66,11 +66,15 @@ Handle<Value> GitTree::Walk(const Arguments& args) {
6666 return ThrowException (Exception::Error (String::New (" No tree list to Walk." )));
6767 }
6868
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 ." )));
7171 }
7272
7373 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 ()) {
7478 return ThrowException (Exception::Error (String::New (" End callback is required and must be a Function." )));
7579 }
7680
@@ -82,8 +86,9 @@ Handle<Value> GitTree::Walk(const Arguments& args) {
8286
8387 baton->rawTree = tree->GetValue ();
8488 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 ]));
8792
8893 uv_thread_create (&baton->threadId , WalkWork, baton);
8994
@@ -106,16 +111,32 @@ void GitTree::WalkWork(void* payload) {
106111 baton->asyncEnd .data = baton;
107112 uv_async_send (&baton->asyncEnd );
108113}
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) {
110116 WalkBaton *baton = static_cast <WalkBaton *>(payload);
111117
112118 uv_mutex_lock (&baton->mutex );
113119
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);
117126
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+ }
119140
120141 uv_mutex_unlock (&baton->mutex );
121142
0 commit comments