@@ -144,6 +144,7 @@ type ProxyOptions struct {
144
144
type Remote struct {
145
145
ptr * C.git_remote
146
146
callbacks RemoteCallbacks
147
+ repo * Repository
147
148
}
148
149
149
150
type CertificateKind uint
@@ -370,6 +371,7 @@ func RemoteIsValidName(name string) bool {
370
371
func (r * Remote ) Free () {
371
372
runtime .SetFinalizer (r , nil )
372
373
C .git_remote_free (r .ptr )
374
+ r .ptr = nil
373
375
}
374
376
375
377
type RemoteCollection struct {
@@ -383,6 +385,7 @@ func (c *RemoteCollection) List() ([]string, error) {
383
385
defer runtime .UnlockOSThread ()
384
386
385
387
ecode := C .git_remote_list (& r , c .repo .ptr )
388
+ runtime .KeepAlive (c .repo )
386
389
if ecode < 0 {
387
390
return nil , MakeGitError (ecode )
388
391
}
@@ -393,7 +396,7 @@ func (c *RemoteCollection) List() ([]string, error) {
393
396
}
394
397
395
398
func (c * RemoteCollection ) Create (name string , url string ) (* Remote , error ) {
396
- remote := & Remote {}
399
+ remote := & Remote {repo : c . repo }
397
400
398
401
cname := C .CString (name )
399
402
defer C .free (unsafe .Pointer (cname ))
@@ -419,14 +422,15 @@ func (c *RemoteCollection) Delete(name string) error {
419
422
defer runtime .UnlockOSThread ()
420
423
421
424
ret := C .git_remote_delete (c .repo .ptr , cname )
425
+ runtime .KeepAlive (c .repo )
422
426
if ret < 0 {
423
427
return MakeGitError (ret )
424
428
}
425
429
return nil
426
430
}
427
431
428
432
func (c * RemoteCollection ) CreateWithFetchspec (name string , url string , fetch string ) (* Remote , error ) {
429
- remote := & Remote {}
433
+ remote := & Remote {repo : c . repo }
430
434
431
435
cname := C .CString (name )
432
436
defer C .free (unsafe .Pointer (cname ))
@@ -447,7 +451,7 @@ func (c *RemoteCollection) CreateWithFetchspec(name string, url string, fetch st
447
451
}
448
452
449
453
func (c * RemoteCollection ) CreateAnonymous (url string ) (* Remote , error ) {
450
- remote := & Remote {}
454
+ remote := & Remote {repo : c . repo }
451
455
452
456
curl := C .CString (url )
453
457
defer C .free (unsafe .Pointer (curl ))
@@ -464,7 +468,7 @@ func (c *RemoteCollection) CreateAnonymous(url string) (*Remote, error) {
464
468
}
465
469
466
470
func (c * RemoteCollection ) Lookup (name string ) (* Remote , error ) {
467
- remote := & Remote {}
471
+ remote := & Remote {repo : c . repo }
468
472
469
473
cname := C .CString (name )
470
474
defer C .free (unsafe .Pointer (cname ))
@@ -481,15 +485,21 @@ func (c *RemoteCollection) Lookup(name string) (*Remote, error) {
481
485
}
482
486
483
487
func (o * Remote ) Name () string {
484
- return C .GoString (C .git_remote_name (o .ptr ))
488
+ s := C .git_remote_name (o .ptr )
489
+ runtime .KeepAlive (o )
490
+ return C .GoString (s )
485
491
}
486
492
487
493
func (o * Remote ) Url () string {
488
- return C .GoString (C .git_remote_url (o .ptr ))
494
+ s := C .git_remote_url (o .ptr )
495
+ runtime .KeepAlive (o )
496
+ return C .GoString (s )
489
497
}
490
498
491
499
func (o * Remote ) PushUrl () string {
492
- return C .GoString (C .git_remote_pushurl (o .ptr ))
500
+ s := C .git_remote_pushurl (o .ptr )
501
+ runtime .KeepAlive (o )
502
+ return C .GoString (s )
493
503
}
494
504
495
505
func (c * RemoteCollection ) Rename (remote , newname string ) ([]string , error ) {
@@ -504,6 +514,7 @@ func (c *RemoteCollection) Rename(remote, newname string) ([]string, error) {
504
514
defer runtime .UnlockOSThread ()
505
515
506
516
ret := C .git_remote_rename (& cproblems , c .repo .ptr , cremote , cnewname )
517
+ runtime .KeepAlive (c .repo )
507
518
if ret < 0 {
508
519
return []string {}, MakeGitError (ret )
509
520
}
@@ -522,6 +533,7 @@ func (c *RemoteCollection) SetUrl(remote, url string) error {
522
533
defer runtime .UnlockOSThread ()
523
534
524
535
ret := C .git_remote_set_url (c .repo .ptr , cremote , curl )
536
+ runtime .KeepAlive (c .repo )
525
537
if ret < 0 {
526
538
return MakeGitError (ret )
527
539
}
@@ -538,6 +550,7 @@ func (c *RemoteCollection) SetPushUrl(remote, url string) error {
538
550
defer runtime .UnlockOSThread ()
539
551
540
552
ret := C .git_remote_set_pushurl (c .repo .ptr , cremote , curl )
553
+ runtime .KeepAlive (c .repo )
541
554
if ret < 0 {
542
555
return MakeGitError (ret )
543
556
}
@@ -554,6 +567,7 @@ func (c *RemoteCollection) AddFetch(remote, refspec string) error {
554
567
defer runtime .UnlockOSThread ()
555
568
556
569
ret := C .git_remote_add_fetch (c .repo .ptr , cremote , crefspec )
570
+ runtime .KeepAlive (c .repo )
557
571
if ret < 0 {
558
572
return MakeGitError (ret )
559
573
}
@@ -605,6 +619,7 @@ func (o *Remote) FetchRefspecs() ([]string, error) {
605
619
defer runtime .UnlockOSThread ()
606
620
607
621
ret := C .git_remote_get_fetch_refspecs (& crefspecs , o .ptr )
622
+ runtime .KeepAlive (o )
608
623
if ret < 0 {
609
624
return nil , MakeGitError (ret )
610
625
}
@@ -624,6 +639,7 @@ func (c *RemoteCollection) AddPush(remote, refspec string) error {
624
639
defer runtime .UnlockOSThread ()
625
640
626
641
ret := C .git_remote_add_push (c .repo .ptr , cremote , crefspec )
642
+ runtime .KeepAlive (c .repo )
627
643
if ret < 0 {
628
644
return MakeGitError (ret )
629
645
}
@@ -641,12 +657,16 @@ func (o *Remote) PushRefspecs() ([]string, error) {
641
657
return nil , MakeGitError (ret )
642
658
}
643
659
defer C .git_strarray_free (& crefspecs )
660
+ runtime .KeepAlive (o )
661
+
644
662
refspecs := makeStringsFromCStrings (crefspecs .strings , int (crefspecs .count ))
645
663
return refspecs , nil
646
664
}
647
665
648
666
func (o * Remote ) RefspecCount () uint {
649
- return uint (C .git_remote_refspec_count (o .ptr ))
667
+ count := C .git_remote_refspec_count (o .ptr )
668
+ runtime .KeepAlive (o )
669
+ return uint (count )
650
670
}
651
671
652
672
func populateFetchOptions (options * C.git_fetch_options , opts * FetchOptions ) {
@@ -706,6 +726,7 @@ func (o *Remote) Fetch(refspecs []string, opts *FetchOptions, msg string) error
706
726
defer runtime .UnlockOSThread ()
707
727
708
728
ret := C .git_remote_fetch (o .ptr , & crefspecs , coptions , cmsg )
729
+ runtime .KeepAlive (o )
709
730
if ret < 0 {
710
731
return MakeGitError (ret )
711
732
}
@@ -734,17 +755,18 @@ func (o *Remote) Connect(direction ConnectDirection, callbacks *RemoteCallbacks,
734
755
var cproxy C.git_proxy_options
735
756
populateProxyOptions (& cproxy , proxyOpts )
736
757
defer freeProxyOptions (& cproxy )
737
-
758
+
738
759
cheaders := C.git_strarray {}
739
760
cheaders .count = C .size_t (len (headers ))
740
761
cheaders .strings = makeCStringsFromStrings (headers )
741
762
defer freeStrarray (& cheaders )
742
763
743
-
744
764
runtime .LockOSThread ()
745
765
defer runtime .UnlockOSThread ()
746
766
747
- if ret := C .git_remote_connect (o .ptr , C .git_direction (direction ), & ccallbacks , & cproxy , & cheaders ); ret != 0 {
767
+ ret := C .git_remote_connect (o .ptr , C .git_direction (direction ), & ccallbacks , & cproxy , & cheaders )
768
+ runtime .KeepAlive (o )
769
+ if ret != 0 {
748
770
return MakeGitError (ret )
749
771
}
750
772
return nil
@@ -755,6 +777,7 @@ func (o *Remote) Disconnect() {
755
777
defer runtime .UnlockOSThread ()
756
778
757
779
C .git_remote_disconnect (o .ptr )
780
+ runtime .KeepAlive (o )
758
781
}
759
782
760
783
func (o * Remote ) Ls (filterRefs ... string ) ([]RemoteHead , error ) {
@@ -765,7 +788,9 @@ func (o *Remote) Ls(filterRefs ...string) ([]RemoteHead, error) {
765
788
runtime .LockOSThread ()
766
789
defer runtime .UnlockOSThread ()
767
790
768
- if ret := C .git_remote_ls (& refs , & length , o .ptr ); ret != 0 {
791
+ ret := C .git_remote_ls (& refs , & length , o .ptr )
792
+ runtime .KeepAlive (o )
793
+ if ret != 0 {
769
794
return nil , MakeGitError (ret )
770
795
}
771
796
@@ -820,6 +845,7 @@ func (o *Remote) Push(refspecs []string, opts *PushOptions) error {
820
845
defer runtime .UnlockOSThread ()
821
846
822
847
ret := C .git_remote_push (o .ptr , & crefspecs , coptions )
848
+ runtime .KeepAlive (o )
823
849
if ret < 0 {
824
850
return MakeGitError (ret )
825
851
}
@@ -838,6 +864,7 @@ func (o *Remote) Prune(callbacks *RemoteCallbacks) error {
838
864
defer runtime .UnlockOSThread ()
839
865
840
866
ret := C .git_remote_prune (o .ptr , & ccallbacks )
867
+ runtime .KeepAlive (o )
841
868
if ret < 0 {
842
869
return MakeGitError (ret )
843
870
}
0 commit comments