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

Method PatchFromBuffers

patch.go:69–99  ·  view source on GitHub ↗
(oldPath, newPath string, oldBuf, newBuf []byte, opts *DiffOptions)

Source from the content-addressed store, hash-verified

67}
68
69func (v *Repository) PatchFromBuffers(oldPath, newPath string, oldBuf, newBuf []byte, opts *DiffOptions) (*Patch, error) {
70 var patchPtr *C.git_patch
71
72 oldPtr := toPointer(oldBuf)
73 newPtr := toPointer(newBuf)
74
75 cOldPath := C.CString(oldPath)
76 defer C.free(unsafe.Pointer(cOldPath))
77
78 cNewPath := C.CString(newPath)
79 defer C.free(unsafe.Pointer(cNewPath))
80
81 var err error
82 copts := populateDiffOptions(&C.git_diff_options{}, opts, v, &err)
83 defer freeDiffOptions(copts)
84
85 runtime.LockOSThread()
86 defer runtime.UnlockOSThread()
87
88 ret := C.git_patch_from_buffers(&patchPtr, oldPtr, C.size_t(len(oldBuf)), cOldPath, newPtr, C.size_t(len(newBuf)), cNewPath, copts)
89 runtime.KeepAlive(oldBuf)
90 runtime.KeepAlive(newBuf)
91 if ret == C.int(ErrorCodeUser) && err != nil {
92 return nil, err
93 }
94 if ret < 0 {
95 return nil, MakeGitError(ret)
96 }
97
98 return newPatchFromC(patchPtr), nil
99}

Callers

nothing calls this directly

Calls 6

toPointerFunction · 0.85
populateDiffOptionsFunction · 0.85
freeDiffOptionsFunction · 0.85
MakeGitErrorFunction · 0.85
newPatchFromCFunction · 0.85
freeMethod · 0.80

Tested by

no test coverage detected