@@ -264,8 +264,7 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
264
264
265
265
rugged_remote_init_callbacks_and_payload_from_options (rb_options , & callbacks , & payload );
266
266
267
- if ((error = git_remote_set_callbacks (remote , & callbacks )) ||
268
- (error = git_remote_connect (remote , GIT_DIRECTION_FETCH )) ||
267
+ if ((error = git_remote_connect (remote , GIT_DIRECTION_FETCH , & callbacks )) ||
269
268
(error = git_remote_ls (& heads , & heads_len , remote )))
270
269
goto cleanup ;
271
270
@@ -319,28 +318,6 @@ static VALUE rb_git_remote_url(VALUE self)
319
318
return rb_str_new_utf8 (git_remote_url (remote ));
320
319
}
321
320
322
- /*
323
- * call-seq:
324
- * remote.url = url -> url
325
- *
326
- * Sets the remote's url without persisting it in the config.
327
- * Existing connections will not be updated.
328
- *
329
- * remote.url = 'git://github.com/libgit2/rugged.git' #=> "git://github.com/libgit2/rugged.git"
330
- */
331
- static VALUE rb_git_remote_set_url (VALUE self , VALUE rb_url )
332
- {
333
- git_remote * remote ;
334
-
335
- Check_Type (rb_url , T_STRING );
336
- Data_Get_Struct (self , git_remote , remote );
337
-
338
- rugged_exception_check (
339
- git_remote_set_url (remote , StringValueCStr (rb_url ))
340
- );
341
- return rb_url ;
342
- }
343
-
344
321
/*
345
322
* call-seq:
346
323
* remote.push_url() -> string or nil
@@ -372,13 +349,18 @@ static VALUE rb_git_remote_push_url(VALUE self)
372
349
*/
373
350
static VALUE rb_git_remote_set_push_url (VALUE self , VALUE rb_url )
374
351
{
352
+ VALUE rb_repo = rugged_owner (self );
375
353
git_remote * remote ;
354
+ git_repository * repo ;
355
+
356
+ rugged_check_repo (rb_repo );
357
+ Data_Get_Struct (rb_repo , git_repository , repo );
376
358
377
359
Check_Type (rb_url , T_STRING );
378
360
Data_Get_Struct (self , git_remote , remote );
379
361
380
362
rugged_exception_check (
381
- git_remote_set_pushurl (remote , StringValueCStr (rb_url ))
363
+ git_remote_set_pushurl (repo , git_remote_name ( remote ) , StringValueCStr (rb_url ))
382
364
);
383
365
384
366
return rb_url ;
@@ -427,86 +409,6 @@ static VALUE rb_git_remote_push_refspecs(VALUE self)
427
409
return rb_git_remote_refspecs (self , GIT_DIRECTION_PUSH );
428
410
}
429
411
430
- static VALUE rb_git_remote_add_refspec (VALUE self , VALUE rb_refspec , git_direction direction )
431
- {
432
- git_remote * remote ;
433
- int error = 0 ;
434
-
435
- Data_Get_Struct (self , git_remote , remote );
436
-
437
- Check_Type (rb_refspec , T_STRING );
438
-
439
- if (direction == GIT_DIRECTION_FETCH )
440
- error = git_remote_add_fetch (remote , StringValueCStr (rb_refspec ));
441
- else
442
- error = git_remote_add_push (remote , StringValueCStr (rb_refspec ));
443
-
444
- rugged_exception_check (error );
445
-
446
- return Qnil ;
447
- }
448
-
449
- /*
450
- * call-seq:
451
- * remote.add_fetch(refspec) -> nil
452
- *
453
- * Add a fetch refspec to the remote.
454
- */
455
- static VALUE rb_git_remote_add_fetch (VALUE self , VALUE rb_refspec )
456
- {
457
- return rb_git_remote_add_refspec (self , rb_refspec , GIT_DIRECTION_FETCH );
458
- }
459
-
460
- /*
461
- * call-seq:
462
- * remote.add_push(refspec) -> nil
463
- *
464
- * Add a push refspec to the remote.
465
- */
466
- static VALUE rb_git_remote_add_push (VALUE self , VALUE rb_refspec )
467
- {
468
- return rb_git_remote_add_refspec (self , rb_refspec , GIT_DIRECTION_PUSH );
469
- }
470
-
471
- /*
472
- * call-seq:
473
- * remote.clear_refspecs -> nil
474
- *
475
- * Remove all configured fetch and push refspecs from the remote.
476
- */
477
- static VALUE rb_git_remote_clear_refspecs (VALUE self )
478
- {
479
- git_remote * remote ;
480
-
481
- Data_Get_Struct (self , git_remote , remote );
482
-
483
- git_remote_clear_refspecs (remote );
484
-
485
- return Qnil ;
486
- }
487
-
488
- /*
489
- * call-seq:
490
- * remote.save -> true
491
- *
492
- * Saves the remote data (url, fetchspecs, ...) to the config.
493
- *
494
- * Anonymous, in-memory remotes created through
495
- * +ReferenceCollection#create_anonymous+ can not be saved.
496
- * Doing so will result in an exception being raised.
497
- */
498
- static VALUE rb_git_remote_save (VALUE self )
499
- {
500
- git_remote * remote ;
501
-
502
- Data_Get_Struct (self , git_remote , remote );
503
-
504
- rugged_exception_check (
505
- git_remote_save (remote )
506
- );
507
- return Qtrue ;
508
- }
509
-
510
412
/*
511
413
* call-seq:
512
414
* remote.check_connection(direction, options = {}) -> boolean
@@ -556,21 +458,13 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
556
458
557
459
rugged_remote_init_callbacks_and_payload_from_options (rb_options , & callbacks , & payload );
558
460
559
- if ((error = git_remote_set_callbacks (remote , & callbacks )) < 0 )
560
- goto cleanup ;
561
-
562
- if (git_remote_connect (remote , direction ))
563
- return Qfalse ;
564
- else {
565
- git_remote_disconnect (remote );
566
- return Qtrue ;
567
- }
461
+ error = git_remote_connect (remote , direction , & callbacks );
462
+ git_remote_disconnect (remote );
568
463
569
- cleanup :
570
464
if (payload .exception )
571
465
rb_jump_tag (payload .exception );
572
- rugged_exception_check ( error );
573
- return Qfalse ;
466
+
467
+ return error ? Qfalse : Qtrue ;
574
468
}
575
469
576
470
/*
@@ -622,7 +516,8 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
622
516
git_remote * remote ;
623
517
git_repository * repo ;
624
518
git_strarray refspecs ;
625
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT ;
519
+ git_fetch_options opts = GIT_FETCH_OPTIONS_INIT ;
520
+ const git_transfer_progress * stats ;
626
521
struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
627
522
628
523
char * log_message = NULL ;
@@ -638,31 +533,15 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
638
533
rugged_check_repo (rb_repo );
639
534
Data_Get_Struct (rb_repo , git_repository , repo );
640
535
641
- rugged_remote_init_callbacks_and_payload_from_options (rb_options , & callbacks , & payload );
536
+ rugged_remote_init_callbacks_and_payload_from_options (rb_options , & opts . callbacks , & payload );
642
537
643
538
if (!NIL_P (rb_options )) {
644
539
VALUE rb_val = rb_hash_aref (rb_options , CSTR2SYM ("message" ));
645
540
if (!NIL_P (rb_val ))
646
541
log_message = StringValueCStr (rb_val );
647
542
}
648
543
649
- if ((error = git_remote_set_callbacks (remote , & callbacks )))
650
- goto cleanup ;
651
-
652
- if ((error = git_remote_fetch (remote , & refspecs , log_message )) == GIT_OK ) {
653
- const git_transfer_progress * stats = git_remote_stats (remote );
654
-
655
- rb_result = rb_hash_new ();
656
- rb_hash_aset (rb_result , CSTR2SYM ("total_objects" ), UINT2NUM (stats -> total_objects ));
657
- rb_hash_aset (rb_result , CSTR2SYM ("indexed_objects" ), UINT2NUM (stats -> indexed_objects ));
658
- rb_hash_aset (rb_result , CSTR2SYM ("received_objects" ), UINT2NUM (stats -> received_objects ));
659
- rb_hash_aset (rb_result , CSTR2SYM ("local_objects" ), UINT2NUM (stats -> local_objects ));
660
- rb_hash_aset (rb_result , CSTR2SYM ("total_deltas" ), UINT2NUM (stats -> total_deltas ));
661
- rb_hash_aset (rb_result , CSTR2SYM ("indexed_deltas" ), UINT2NUM (stats -> indexed_deltas ));
662
- rb_hash_aset (rb_result , CSTR2SYM ("received_bytes" ), INT2FIX (stats -> received_bytes ));
663
- }
664
-
665
- cleanup :
544
+ error = git_remote_fetch (remote , & refspecs , & opts , log_message );
666
545
667
546
xfree (refspecs .strings );
668
547
@@ -671,6 +550,17 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
671
550
672
551
rugged_exception_check (error );
673
552
553
+ stats = git_remote_stats (remote );
554
+
555
+ rb_result = rb_hash_new ();
556
+ rb_hash_aset (rb_result , CSTR2SYM ("total_objects" ), UINT2NUM (stats -> total_objects ));
557
+ rb_hash_aset (rb_result , CSTR2SYM ("indexed_objects" ), UINT2NUM (stats -> indexed_objects ));
558
+ rb_hash_aset (rb_result , CSTR2SYM ("received_objects" ), UINT2NUM (stats -> received_objects ));
559
+ rb_hash_aset (rb_result , CSTR2SYM ("local_objects" ), UINT2NUM (stats -> local_objects ));
560
+ rb_hash_aset (rb_result , CSTR2SYM ("total_deltas" ), UINT2NUM (stats -> total_deltas ));
561
+ rb_hash_aset (rb_result , CSTR2SYM ("indexed_deltas" ), UINT2NUM (stats -> indexed_deltas ));
562
+ rb_hash_aset (rb_result , CSTR2SYM ("received_bytes" ), INT2FIX (stats -> received_bytes ));
563
+
674
564
return rb_result ;
675
565
}
676
566
@@ -708,7 +598,6 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
708
598
709
599
git_repository * repo ;
710
600
git_remote * remote ;
711
- git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT ;
712
601
git_strarray refspecs ;
713
602
git_push_options opts = GIT_PUSH_OPTIONS_INIT ;
714
603
@@ -724,14 +613,10 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
724
613
Data_Get_Struct (rb_repo , git_repository , repo );
725
614
Data_Get_Struct (self , git_remote , remote );
726
615
727
- rugged_remote_init_callbacks_and_payload_from_options (rb_options , & callbacks , & payload );
728
-
729
- if ((error = git_remote_set_callbacks (remote , & callbacks )))
730
- goto cleanup ;
616
+ rugged_remote_init_callbacks_and_payload_from_options (rb_options , & opts .callbacks , & payload );
731
617
732
618
error = git_remote_push (remote , & refspecs , & opts );
733
619
734
- cleanup :
735
620
xfree (refspecs .strings );
736
621
737
622
if (payload .exception )
@@ -746,20 +631,14 @@ void Init_rugged_remote(void)
746
631
{
747
632
rb_cRuggedRemote = rb_define_class_under (rb_mRugged , "Remote" , rb_cObject );
748
633
749
-
750
634
rb_define_method (rb_cRuggedRemote , "name" , rb_git_remote_name , 0 );
751
635
rb_define_method (rb_cRuggedRemote , "url" , rb_git_remote_url , 0 );
752
- rb_define_method (rb_cRuggedRemote , "url=" , rb_git_remote_set_url , 1 );
753
636
rb_define_method (rb_cRuggedRemote , "push_url" , rb_git_remote_push_url , 0 );
754
637
rb_define_method (rb_cRuggedRemote , "push_url=" , rb_git_remote_set_push_url , 1 );
755
638
rb_define_method (rb_cRuggedRemote , "fetch_refspecs" , rb_git_remote_fetch_refspecs , 0 );
756
639
rb_define_method (rb_cRuggedRemote , "push_refspecs" , rb_git_remote_push_refspecs , 0 );
757
- rb_define_method (rb_cRuggedRemote , "add_fetch" , rb_git_remote_add_fetch , 1 );
758
- rb_define_method (rb_cRuggedRemote , "add_push" , rb_git_remote_add_push , 1 );
759
640
rb_define_method (rb_cRuggedRemote , "ls" , rb_git_remote_ls , -1 );
760
641
rb_define_method (rb_cRuggedRemote , "check_connection" , rb_git_remote_check_connection , -1 );
761
642
rb_define_method (rb_cRuggedRemote , "fetch" , rb_git_remote_fetch , -1 );
762
643
rb_define_method (rb_cRuggedRemote , "push" , rb_git_remote_push , -1 );
763
- rb_define_method (rb_cRuggedRemote , "clear_refspecs" , rb_git_remote_clear_refspecs , 0 );
764
- rb_define_method (rb_cRuggedRemote , "save" , rb_git_remote_save , 0 );
765
644
}
0 commit comments