DiffBlobs performs a diff between two arbitrary blobs. You can pass whatever file names you'd like for them to appear as in the diff.
(oldBlob *Blob, oldAsPath string, newBlob *Blob, newAsPath string, opts *DiffOptions, fileCallback DiffForEachFileCallback, detail DiffDetail)
| 834 | // DiffBlobs performs a diff between two arbitrary blobs. You can pass |
| 835 | // whatever file names you'd like for them to appear as in the diff. |
| 836 | func DiffBlobs(oldBlob *Blob, oldAsPath string, newBlob *Blob, newAsPath string, opts *DiffOptions, fileCallback DiffForEachFileCallback, detail DiffDetail) error { |
| 837 | var err error |
| 838 | data := &diffForEachCallbackData{ |
| 839 | fileCallback: fileCallback, |
| 840 | errorTarget: &err, |
| 841 | } |
| 842 | |
| 843 | intHunks := C.int(0) |
| 844 | if detail >= DiffDetailHunks { |
| 845 | intHunks = C.int(1) |
| 846 | } |
| 847 | |
| 848 | intLines := C.int(0) |
| 849 | if detail >= DiffDetailLines { |
| 850 | intLines = C.int(1) |
| 851 | } |
| 852 | |
| 853 | handle := pointerHandles.Track(data) |
| 854 | defer pointerHandles.Untrack(handle) |
| 855 | |
| 856 | var repo *Repository |
| 857 | var oldBlobPtr, newBlobPtr *C.git_blob |
| 858 | if oldBlob != nil { |
| 859 | oldBlobPtr = oldBlob.cast_ptr |
| 860 | repo = oldBlob.repo |
| 861 | } |
| 862 | if newBlob != nil { |
| 863 | newBlobPtr = newBlob.cast_ptr |
| 864 | repo = newBlob.repo |
| 865 | } |
| 866 | |
| 867 | oldBlobPath := C.CString(oldAsPath) |
| 868 | defer C.free(unsafe.Pointer(oldBlobPath)) |
| 869 | newBlobPath := C.CString(newAsPath) |
| 870 | defer C.free(unsafe.Pointer(newBlobPath)) |
| 871 | |
| 872 | copts := populateDiffOptions(&C.git_diff_options{}, opts, repo, &err) |
| 873 | defer freeDiffOptions(copts) |
| 874 | |
| 875 | runtime.LockOSThread() |
| 876 | defer runtime.UnlockOSThread() |
| 877 | |
| 878 | ret := C._go_git_diff_blobs(oldBlobPtr, oldBlobPath, newBlobPtr, newBlobPath, copts, 1, intHunks, intLines, handle) |
| 879 | runtime.KeepAlive(oldBlob) |
| 880 | runtime.KeepAlive(newBlob) |
| 881 | if ret == C.int(ErrorCodeUser) && err != nil { |
| 882 | return err |
| 883 | } |
| 884 | if ret < 0 { |
| 885 | return MakeGitError(ret) |
| 886 | } |
| 887 | |
| 888 | return nil |
| 889 | } |
| 890 | |
| 891 | // ApplyHunkCallback is a callback that will be made per delta (file) when applying a patch. |
| 892 | type ApplyHunkCallback func(*DiffHunk) (apply bool, err error) |
searching dependent graphs…