export diffNotifyCallback
(_diff_so_far unsafe.Pointer, delta_to_add *C.git_diff_delta, matched_pathspec *C.char, handle unsafe.Pointer)
| 605 | |
| 606 | //export diffNotifyCallback |
| 607 | func 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 | |
| 646 | func 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…