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

Function DiffBlobs

diff.go:836–889  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
836func 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.
892type ApplyHunkCallback func(*DiffHunk) (apply bool, err error)

Callers 1

TestDiffBlobsFunction · 0.85

Calls 6

populateDiffOptionsFunction · 0.85
freeDiffOptionsFunction · 0.85
MakeGitErrorFunction · 0.85
TrackMethod · 0.80
UntrackMethod · 0.80
freeMethod · 0.80

Tested by 1

TestDiffBlobsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…