| 444 | ) |
| 445 | |
| 446 | func (diff *Diff) ToBuf(format DiffFormat) ([]byte, error) { |
| 447 | if diff.ptr == nil { |
| 448 | return nil, ErrInvalid |
| 449 | } |
| 450 | |
| 451 | diffBuf := C.git_buf{} |
| 452 | |
| 453 | runtime.LockOSThread() |
| 454 | defer runtime.UnlockOSThread() |
| 455 | |
| 456 | ecode := C.git_diff_to_buf(&diffBuf, diff.ptr, C.git_diff_format_t(format)) |
| 457 | runtime.KeepAlive(diff) |
| 458 | if ecode < 0 { |
| 459 | return nil, MakeGitError(ecode) |
| 460 | } |
| 461 | defer C.git_buf_dispose(&diffBuf) |
| 462 | |
| 463 | return C.GoBytes(unsafe.Pointer(diffBuf.ptr), C.int(diffBuf.size)), nil |
| 464 | } |
| 465 | |
| 466 | type DiffOptionsFlag int |
| 467 | |