Skip to content

Commit fb9b327

Browse files
authored
Merge pull request #774 from stanhu/sh-allow-diff-patch-no-gvl
Allow diff_patch to run without the global lock
2 parents ca994bb + 8b60e44 commit fb9b327

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

ext/rugged/rugged_diff.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "rugged.h"
9+
#include <ruby/thread.h>
910

1011
extern VALUE rb_mRugged;
1112
VALUE rb_cRuggedDiff;
@@ -197,6 +198,20 @@ static int diff_print_cb(
197198
return GIT_OK;
198199
}
199200

201+
struct nogvl_diff_patch_args {
202+
git_diff * diff;
203+
git_diff_format_t format;
204+
VALUE rb_str;
205+
};
206+
207+
static void rb_git_diff_patch_nogvl(void * _args)
208+
{
209+
struct nogvl_diff_patch_args * args;
210+
211+
args = (struct nogvl_diff_patch_args *)_args;
212+
git_diff_print(args->diff, args->format, diff_print_cb, (void*) args->rb_str);
213+
}
214+
200215
/*
201216
* call-seq:
202217
* diff.patch -> patch
@@ -209,20 +224,25 @@ static VALUE rb_git_diff_patch(int argc, VALUE *argv, VALUE self)
209224
git_diff *diff;
210225
VALUE rb_str = rb_str_new(NULL, 0);
211226
VALUE rb_opts;
227+
struct nogvl_diff_patch_args args;
228+
git_diff_format_t format = GIT_DIFF_FORMAT_PATCH;
212229

213230
rb_scan_args(argc, argv, "00:", &rb_opts);
214231

215232
Data_Get_Struct(self, git_diff, diff);
216233

217234
if (!NIL_P(rb_opts)) {
218235
if (rb_hash_aref(rb_opts, CSTR2SYM("compact")) == Qtrue)
219-
git_diff_print(diff, GIT_DIFF_FORMAT_NAME_STATUS, diff_print_cb, (void*)rb_str);
236+
format = GIT_DIFF_FORMAT_NAME_STATUS;
220237
else
221-
git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, diff_print_cb, (void*)rb_str);
222-
} else {
223-
git_diff_print(diff, GIT_DIFF_FORMAT_PATCH, diff_print_cb, (void*)rb_str);
238+
format = GIT_DIFF_FORMAT_PATCH;
224239
}
225240

241+
args.diff = diff;
242+
args.format = format;
243+
args.rb_str = rb_str;
244+
rb_thread_call_without_gvl(rb_git_diff_patch_nogvl, &args, RUBY_UBF_PROCESS, NULL);
245+
226246
return rb_str;
227247
}
228248

0 commit comments

Comments
 (0)