1515#include " ../include/error.h"
1616
1717#include " ../include/functions/string.h"
18+ #include " ../include/functions/utilities.h"
1819
1920using namespace v8 ;
2021using namespace node ;
22+ using namespace cvv8 ;
2123
2224namespace cvv8 {
2325 template <>
@@ -143,7 +145,7 @@ Handle<Value> GitDiffList::TreeToTree(const Arguments& args) {
143145 return ThrowException (Exception::Error (String::New (" Callback is required and must be a Function." )));
144146 }
145147
146- TreeToTreeBaton *baton = new TreeToTreeBaton () ;
148+ TreeToTreeBaton *baton = new TreeToTreeBaton;
147149 baton->request .data = baton;
148150 baton->error = NULL ;
149151 baton->diffList = ObjectWrap::Unwrap<GitDiffList>(args.This ());
@@ -293,7 +295,7 @@ Handle<Value> GitDiffList::Walk(const Arguments& args) {
293295
294296 baton->rawDiffList = diffList->GetValue ();
295297 diffList->Ref ();
296-
298+ baton-> error = NULL ;
297299 baton->fileCallback = Persistent<Function>::New (Local<Function>::Cast (args[0 ]));
298300 baton->hunkCallback = Persistent<Function>::New (Local<Function>::Cast (args[1 ]));
299301 baton->lineCallback = Persistent<Function>::New (Local<Function>::Cast (args[2 ]));
@@ -341,7 +343,7 @@ int GitDiffList::WalkWorkFile(const git_diff_delta *delta, float progress,
341343
342344 uv_mutex_lock (&baton->mutex );
343345
344- GitDiffList:: Delta* newDelta = new GitDiffList:: Delta() ;
346+ Delta* newDelta = new Delta;
345347 newDelta->raw = (git_diff_delta*)malloc (sizeof (git_diff_delta));
346348 memcpy (newDelta->raw , delta, sizeof (git_diff_delta));
347349
@@ -352,6 +354,7 @@ int GitDiffList::WalkWorkFile(const git_diff_delta *delta, float progress,
352354 uv_mutex_unlock (&baton->mutex );
353355
354356 if ((unsigned int )baton->fileDeltas .size () == (unsigned int )GitDiffList::WALK_DELTA_SEND_THRESHHOLD) {
357+ baton->asyncFile .data = baton;
355358 uv_async_send (&baton->asyncFile );
356359 }
357360
@@ -389,19 +392,8 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) {
389392
390393 WalkBaton *baton = static_cast <WalkBaton *>(handle->data );
391394
392- if (baton->error ) {
393- Local<Value> argv[1 ] = {
394- GitError::WrapError (baton->error )
395- };
396-
397- TryCatch try_catch;
398- baton->fileCallback ->Call (Context::GetCurrent ()->Global (), 1 , argv);
399- if (try_catch.HasCaught ()) {
400- node::FatalException (try_catch);
401- }
402- } else {
403-
404- uv_mutex_lock (&baton->mutex );
395+ uv_mutex_lock (&baton->mutex );
396+ if (success (baton->error , baton->fileCallback )) {
405397
406398 std::vector<Local<Object> > fileDeltasArray;
407399
@@ -459,7 +451,6 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) {
459451
460452 baton->fileDeltas .clear ();
461453
462- uv_mutex_unlock (&baton->mutex );
463454
464455 Handle<Value> argv[2 ] = {
465456 Local<Value>::New (Null ()),
@@ -472,6 +463,7 @@ void GitDiffList::WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/) {
472463 node::FatalException (try_catch);
473464 }
474465 }
466+ uv_mutex_unlock (&baton->mutex );
475467}
476468void GitDiffList::WalkWorkSendHunk (uv_async_t *handle, int status /* UNUSED*/ ) { }
477469void GitDiffList::WalkWorkSendData (uv_async_t *handle, int status /* UNUSED*/ ) { }
0 commit comments