* adding a weak bool param for Remote

* create a new remote in the smartTransportCallback incase one is not found
This commit is contained in:
Yashodhan Ghadge 2021-10-15 14:10:24 +05:30
parent 6eae74c128
commit c86c835832
2 changed files with 17 additions and 0 deletions

View File

@ -182,6 +182,9 @@ type Remote struct {
ptr *C.git_remote
callbacks RemoteCallbacks
repo *Repository
// weak indicates that a remote is a weak pointer and should not be
// freed.
weak bool
}
type remotePointerList struct {
@ -602,6 +605,9 @@ func (r *Remote) free() {
// Free releases the resources of the Remote.
func (r *Remote) Free() {
r.repo.Remotes.untrackRemote(r)
if r.weak {
return
}
r.free()
}
@ -1231,3 +1237,12 @@ func freeRemoteCreateOptions(ptr *C.git_remote_create_options) {
C.free(unsafe.Pointer(ptr.name))
C.free(unsafe.Pointer(ptr.fetchspec))
}
// createNewEmptyRemote used to get a new empty object of *Remote
func createNewEmptyRemote() *Remote {
return &Remote{
callbacks: RemoteCallbacks{},
repo: nil,
weak: false,
}
}

View File

@ -307,6 +307,8 @@ func smartTransportCallback(
remote, ok := remotePointers.get(owner)
if !ok {
err := errors.New("remote pointer not found")
remote = createNewEmptyRemote()
remote.weak = true
return setCallbackError(errorMessage, err)
}