MCPcopy Create free account
hub / github.com/libgit2/git2go / diffNotifyCallback

Function diffNotifyCallback

diff.go:607–644  ·  view source on GitHub ↗

export diffNotifyCallback

(_diff_so_far unsafe.Pointer, delta_to_add *C.git_diff_delta, matched_pathspec *C.char, handle unsafe.Pointer)

Source from the content-addressed store, hash-verified

605
606//export diffNotifyCallback
607func diffNotifyCallback(_diff_so_far unsafe.Pointer, delta_to_add *C.git_diff_delta, matched_pathspec *C.char, handle unsafe.Pointer) C.int {
608 diff_so_far := (*C.git_diff)(_diff_so_far)
609
610 payload := pointerHandles.Get(handle)
611 data, ok := payload.(*diffNotifyCallbackData)
612 if !ok {
613 panic("could not retrieve data for handle")
614 }
615
616 if data == nil {
617 return C.int(ErrorCodeOK)
618 }
619
620 // We are not taking ownership of this diff pointer, so no finalizer is set.
621 diff := &Diff{
622 ptr: diff_so_far,
623 repo: data.repository,
624 runFinalizer: false,
625 }
626
627 err := data.callback(diff, diffDeltaFromC(delta_to_add), C.GoString(matched_pathspec))
628
629 // Since the callback could theoretically keep a reference to the diff
630 // (which could be freed by libgit2 if an error occurs later during the
631 // diffing process), this converts a use-after-free (terrible!) into a nil
632 // dereference ("just" pretty bad).
633 diff.ptr = nil
634
635 if err == ErrDeltaSkip {
636 return 1
637 }
638 if err != nil {
639 *data.errorTarget = err
640 return C.int(ErrorCodeUser)
641 }
642
643 return C.int(ErrorCodeOK)
644}
645
646func populateDiffOptions(copts *C.git_diff_options, opts *DiffOptions, repo *Repository, errorTarget *error) *C.git_diff_options {
647 C.git_diff_options_init(copts, C.GIT_DIFF_OPTIONS_VERSION)

Callers

nothing calls this directly

Calls 2

diffDeltaFromCFunction · 0.85
GetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…