@@ -302,13 +302,6 @@ static VALUE do_walk(VALUE _payload)
302
302
return Qnil ;
303
303
}
304
304
305
- static VALUE do_walk_cleanup (VALUE _payload )
306
- {
307
- struct walk_options * w = (struct walk_options * )_payload ;
308
- git_revwalk_free (w -> walk );
309
- return Qnil ;
310
- }
311
-
312
305
/*
313
306
* call-seq:
314
307
* Rugged::Walker.walk(repo, options={}) { |commit| block }
@@ -360,9 +353,16 @@ static VALUE rb_git_walk(int argc, VALUE *argv, VALUE self)
360
353
{
361
354
VALUE rb_repo , rb_options ;
362
355
struct walk_options w ;
356
+ int exception = 0 ;
363
357
364
358
rb_scan_args (argc , argv , "10:" , & rb_repo , & rb_options );
365
359
360
+ if (!rb_block_given_p ()) {
361
+ ID iter_method = ID2SYM (rb_intern ("walk" ));
362
+ return rb_funcall (self , rb_intern ("to_enum" ), 3 ,
363
+ iter_method , rb_repo , rb_options );
364
+ }
365
+
366
366
Data_Get_Struct (rb_repo , git_repository , w .repo );
367
367
rugged_exception_check (git_revwalk_new (& w .walk , w .repo ));
368
368
@@ -373,22 +373,32 @@ static VALUE rb_git_walk(int argc, VALUE *argv, VALUE self)
373
373
w .offset = 0 ;
374
374
w .limit = UINT64_MAX ;
375
375
376
- if (!NIL_P (w .rb_options )) {
377
- rb_ensure (
378
- load_all_options , (VALUE )& w ,
379
- do_walk_cleanup , (VALUE )& w );
380
- }
376
+ if (!NIL_P (w .rb_options ))
377
+ rb_protect (load_all_options , (VALUE )& w , & exception );
378
+
379
+ if (!exception )
380
+ rb_protect (do_walk , (VALUE )& w , & exception );
381
+
382
+ git_revwalk_free (w .walk );
381
383
382
- return rb_ensure (
383
- do_walk , (VALUE )& w ,
384
- do_walk_cleanup , (VALUE )& w );
384
+ if (exception )
385
+ rb_jump_tag (exception );
386
+
387
+ return Qnil ;
385
388
}
386
389
387
390
static VALUE rb_git_walk_with_opts (int argc , VALUE * argv , VALUE self , int oid_only )
388
391
{
389
392
VALUE rb_options ;
390
393
struct walk_options w ;
391
394
395
+ rb_scan_args (argc , argv , "01" , & rb_options );
396
+
397
+ if (!rb_block_given_p ()) {
398
+ ID iter_method = ID2SYM (rb_intern (oid_only ? "each_oid" : "each" ));
399
+ return rb_funcall (self , rb_intern ("to_enum" ), 2 , iter_method , rb_options );
400
+ }
401
+
392
402
Data_Get_Struct (self , git_revwalk , w .walk );
393
403
w .repo = git_revwalk_repository (w .walk );
394
404
@@ -399,13 +409,6 @@ static VALUE rb_git_walk_with_opts(int argc, VALUE *argv, VALUE self, int oid_on
399
409
w .offset = 0 ;
400
410
w .limit = UINT64_MAX ;
401
411
402
- rb_scan_args (argc , argv , "01" , & rb_options );
403
-
404
- if (!rb_block_given_p ()) {
405
- ID iter_method = ID2SYM (rb_intern (oid_only ? "each_oid" : "each" ));
406
- return rb_funcall (self , rb_intern ("to_enum" ), 2 , iter_method , rb_options );
407
- }
408
-
409
412
if (!NIL_P (rb_options ))
410
413
load_walk_limits (& w , rb_options );
411
414
0 commit comments