diff options
| author | Carlos Martín Nieto <[email protected]> | 2014-12-11 02:42:29 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2014-12-11 02:42:29 +0100 |
| commit | 1198f829b1f1e2dc907445769a2a1ea30f5df571 (patch) | |
| tree | 89933385ba4c47beab8eab88929bf748f68db3b3 /diff.go | |
| parent | 7762e1a3a963d3e00c4709b284d30ff843ea30ff (diff) | |
| parent | db17135a30100c698d3efa1c98ba717201f426ce (diff) | |
Merge pull request #148 from joseferminj/export-patch-from-branches
Export PatchFromBuffers function.
Diffstat (limited to 'diff.go')
| -rw-r--r-- | diff.go | 72 |
1 files changed, 27 insertions, 45 deletions
@@ -459,21 +459,8 @@ func diffNotifyCb(_diff_so_far unsafe.Pointer, delta_to_add *C.git_diff_delta, m return 0 } -func (v *Repository) DiffTreeToTree(oldTree, newTree *Tree, opts *DiffOptions) (*Diff, error) { - var diffPtr *C.git_diff - var oldPtr, newPtr *C.git_tree - - if oldTree != nil { - oldPtr = oldTree.cast_ptr - } - - if newTree != nil { - newPtr = newTree.cast_ptr - } - +func diffOptionsToC(opts *DiffOptions) (copts *C.git_diff_options, notifyData *diffNotifyData) { cpathspec := C.git_strarray{} - var copts *C.git_diff_options - var notifyData *diffNotifyData if opts != nil { notifyData = &diffNotifyData{ Callback: opts.NotifyCallback, @@ -481,7 +468,6 @@ func (v *Repository) DiffTreeToTree(oldTree, newTree *Tree, opts *DiffOptions) ( if opts.Pathspec != nil { cpathspec.count = C.size_t(len(opts.Pathspec)) cpathspec.strings = makeCStringsFromStrings(opts.Pathspec) - defer freeStrarray(&cpathspec) } copts = &C.git_diff_options{ @@ -500,6 +486,30 @@ func (v *Repository) DiffTreeToTree(oldTree, newTree *Tree, opts *DiffOptions) ( copts.notify_payload = unsafe.Pointer(notifyData) } } + return +} + +func freeDiffOptions(copts *C.git_diff_options) { + if copts != nil { + cpathspec := copts.pathspec + freeStrarray(&cpathspec) + } +} + +func (v *Repository) DiffTreeToTree(oldTree, newTree *Tree, opts *DiffOptions) (*Diff, error) { + var diffPtr *C.git_diff + var oldPtr, newPtr *C.git_tree + + if oldTree != nil { + oldPtr = oldTree.cast_ptr + } + + if newTree != nil { + newPtr = newTree.cast_ptr + } + + copts, notifyData := diffOptionsToC(opts) + defer freeDiffOptions(copts) runtime.LockOSThread() defer runtime.UnlockOSThread() @@ -523,35 +533,8 @@ func (v *Repository) DiffTreeToWorkdir(oldTree *Tree, opts *DiffOptions) (*Diff, oldPtr = oldTree.cast_ptr } - cpathspec := C.git_strarray{} - var copts *C.git_diff_options - var notifyData *diffNotifyData - if opts != nil { - notifyData = &diffNotifyData{ - Callback: opts.NotifyCallback, - } - if opts.Pathspec != nil { - cpathspec.count = C.size_t(len(opts.Pathspec)) - cpathspec.strings = makeCStringsFromStrings(opts.Pathspec) - defer freeStrarray(&cpathspec) - } - - copts = &C.git_diff_options{ - version: C.GIT_DIFF_OPTIONS_VERSION, - flags: C.uint32_t(opts.Flags), - ignore_submodules: C.git_submodule_ignore_t(opts.IgnoreSubmodules), - pathspec: cpathspec, - context_lines: C.uint32_t(opts.ContextLines), - interhunk_lines: C.uint32_t(opts.InterhunkLines), - id_abbrev: C.uint16_t(opts.IdAbbrev), - max_size: C.git_off_t(opts.MaxSize), - } - - if opts.NotifyCallback != nil { - C._go_git_setup_diff_notify_callbacks(copts) - copts.notify_payload = unsafe.Pointer(notifyData) - } - } + copts, notifyData := diffOptionsToC(opts) + defer freeDiffOptions(copts) runtime.LockOSThread() defer runtime.UnlockOSThread() @@ -565,5 +548,4 @@ func (v *Repository) DiffTreeToWorkdir(oldTree *Tree, opts *DiffOptions) (*Diff, return notifyData.Diff, nil } return newDiffFromC(diffPtr), nil - } |
