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

Function MergeFile

merge.go:542–594  ·  view source on GitHub ↗
(ancestor MergeFileInput, ours MergeFileInput, theirs MergeFileInput, options *MergeFileOptions)

Source from the content-addressed store, hash-verified

540}
541
542func MergeFile(ancestor MergeFileInput, ours MergeFileInput, theirs MergeFileInput, options *MergeFileOptions) (*MergeFileResult, error) {
543
544 ancestorPath := C.CString(ancestor.Path)
545 defer C.free(unsafe.Pointer(ancestorPath))
546 var ancestorContents *byte
547 if len(ancestor.Contents) > 0 {
548 ancestorContents = &ancestor.Contents[0]
549 }
550
551 oursPath := C.CString(ours.Path)
552 defer C.free(unsafe.Pointer(oursPath))
553 var oursContents *byte
554 if len(ours.Contents) > 0 {
555 oursContents = &ours.Contents[0]
556 }
557
558 theirsPath := C.CString(theirs.Path)
559 defer C.free(unsafe.Pointer(theirsPath))
560 var theirsContents *byte
561 if len(theirs.Contents) > 0 {
562 theirsContents = &theirs.Contents[0]
563 }
564
565 var copts *C.git_merge_file_options
566 if options != nil {
567 copts = &C.git_merge_file_options{}
568 ecode := C.git_merge_file_options_init(copts, C.GIT_MERGE_FILE_OPTIONS_VERSION)
569 if ecode < 0 {
570 return nil, MakeGitError(ecode)
571 }
572 populateMergeFileOptions(copts, options)
573 defer freeMergeFileOptions(copts)
574 }
575
576 runtime.LockOSThread()
577 defer runtime.UnlockOSThread()
578
579 var result C.git_merge_file_result
580 ecode := C._go_git_merge_file(&result,
581 (*C.char)(unsafe.Pointer(ancestorContents)), C.size_t(len(ancestor.Contents)), ancestorPath, C.uint(ancestor.Mode),
582 (*C.char)(unsafe.Pointer(oursContents)), C.size_t(len(ours.Contents)), oursPath, C.uint(ours.Mode),
583 (*C.char)(unsafe.Pointer(theirsContents)), C.size_t(len(theirs.Contents)), theirsPath, C.uint(theirs.Mode),
584 copts)
585 runtime.KeepAlive(ancestor)
586 runtime.KeepAlive(ours)
587 runtime.KeepAlive(theirs)
588 if ecode < 0 {
589 return nil, MakeGitError(ecode)
590 }
591
592 return newMergeFileResultFromC(&result), nil
593
594}
595
596// TODO: GIT_EXTERN(int) git_merge_file_from_index(git_merge_file_result *out,git_repository *repo,const git_index_entry *ancestor, const git_index_entry *ours, const git_index_entry *theirs, const git_merge_file_options *opts);

Callers 1

TestMergeSameFileFunction · 0.85

Calls 5

MakeGitErrorFunction · 0.85
populateMergeFileOptionsFunction · 0.85
freeMergeFileOptionsFunction · 0.85
newMergeFileResultFromCFunction · 0.85
freeMethod · 0.80

Tested by 1

TestMergeSameFileFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…